Search in sources :

Example 1 with MathExecutable

use of cbit.vcell.solvers.MathExecutable in project vcell by virtualcell.

the class SmoldynSolver method initialize.

/**
 *  This method takes the place of the old runUnsteady()...
 */
protected void initialize() throws SolverException {
    if (lg.isTraceEnabled())
        lg.trace("SmoldynSolver.initialize()");
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
    writeFunctionsFile();
    // write subdomains file
    try {
        SubdomainInfo.write(new File(getBaseName() + SimDataConstants.SUBDOMAINS_FILE_SUFFIX), simTask.getSimulation().getMathDescription());
    } catch (IOException e1) {
        e1.printStackTrace();
        throw new SolverException(e1.getMessage());
    } catch (MathException e1) {
        e1.printStackTrace();
        throw new SolverException(e1.getMessage());
    }
    String inputFilename = getInputFilename();
    if (lg.isTraceEnabled())
        lg.trace("SmoldynSolver.initialize() baseName = " + getBaseName());
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INPUT_FILE);
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(inputFilename);
        if (SystemUtils.IS_OS_WINDOWS) {
            // 
            // the windows executable is compiled under cygwin (or mingw) and expect Unix style line termination characters.
            // so SmoldynInput file is written with platform default Java convention (different on windows) to a String.
            // Then the string is translated to Unix style before written to the file.
            // smoldyn is particularly sensitive to this issue, other compiled solvers are more tolerant.
            // 
            StringWriter stringWriter = new StringWriter();
            PrintWriter pw2 = new PrintWriter(stringWriter);
            SmoldynFileWriter stFileWriter = new SmoldynFileWriter(pw2, false, getBaseName(), simTask, bMessaging);
            stFileWriter.write();
            String fileContents = stringWriter.getBuffer().toString();
            fileContents = fileContents.replace("\r\n", "\n");
            pw.write(fileContents);
        } else {
            // 
            // for linux or macos, no translation is necessary.
            // 
            SmoldynFileWriter stFileWriter = new SmoldynFileWriter(pw, false, getBaseName(), simTask, bMessaging);
            stFileWriter.write();
        }
    } catch (Exception e) {
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not generate input file: " + e.getMessage())));
        e.printStackTrace(System.out);
        throw new SolverException(e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
    // get executable path+name.
    setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
// setMathExecutable(new cbit.vcell.solvers.MathExecutable(executableName + " gibson " + getBaseName() + ".stochInput" + " " + getBaseName() + ".stoch"));
}
Also used : StringWriter(java.io.StringWriter) MathException(cbit.vcell.math.MathException) IOException(java.io.IOException) SolverException(cbit.vcell.solver.SolverException) MathExecutable(cbit.vcell.solvers.MathExecutable) File(java.io.File) SolverStatus(cbit.vcell.solver.server.SolverStatus) IOException(java.io.IOException) SolverException(cbit.vcell.solver.SolverException) MathException(cbit.vcell.math.MathException) PrintWriter(java.io.PrintWriter)

Example 2 with MathExecutable

use of cbit.vcell.solvers.MathExecutable in project vcell by virtualcell.

the class CVodeSolverStandalone method initialize.

/**
 *  This method takes the place of the old runUnsteady()...
 */
protected void initialize() throws SolverException {
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
    super.initialize();
    String inputFilename = getInputFilename();
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INPUT_FILE);
    PrintWriter pw = null;
    try {
        pw = new java.io.PrintWriter(inputFilename);
        CVodeFileWriter cvodeFileWriter = new CVodeFileWriter(pw, simTask, bMessaging);
        cvodeFileWriter.write();
    } catch (Exception e) {
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("CVODE solver could not generate input file: " + e.getMessage())));
        e.printStackTrace(System.out);
        throw new SolverException("CVODE solver could not generate input file: " + e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
    setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
}
Also used : PrintWriter(java.io.PrintWriter) SolverException(cbit.vcell.solver.SolverException) MathExecutable(cbit.vcell.solvers.MathExecutable) SolverStatus(cbit.vcell.solver.server.SolverStatus) IOException(java.io.IOException) SolverException(cbit.vcell.solver.SolverException) PrintWriter(java.io.PrintWriter)

Example 3 with MathExecutable

use of cbit.vcell.solvers.MathExecutable in project vcell by virtualcell.

the class IDASolverStandalone method initialize.

/**
 *  This method takes the place of the old runUnsteady()...
 */
protected void initialize() throws SolverException {
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
    super.initialize();
    String inputFilename = getInputFilename();
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INPUT_FILE);
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(inputFilename);
        IDAFileWriter idaFileWriter = new IDAFileWriter(pw, simTask, bMessaging);
        idaFileWriter.write();
    } catch (Exception e) {
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not generate input file: " + e.getMessage())));
        e.printStackTrace(System.out);
        throw new SolverException("IDA solver could not generate input file: " + e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
    setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
}
Also used : SolverException(cbit.vcell.solver.SolverException) MathExecutable(cbit.vcell.solvers.MathExecutable) SolverStatus(cbit.vcell.solver.server.SolverStatus) IOException(java.io.IOException) SolverException(cbit.vcell.solver.SolverException) PrintWriter(java.io.PrintWriter)

Example 4 with MathExecutable

use of cbit.vcell.solvers.MathExecutable in project vcell by virtualcell.

the class GibsonSolver method initialize.

/**
 *  This method takes the place of the old runUnsteady()...
 */
protected void initialize() throws SolverException {
    if (lg.isTraceEnabled())
        lg.trace("StochSolver.initialize()");
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
    writeFunctionsFile();
    writeLogFile();
    String inputFilename = getInputFilename();
    if (lg.isTraceEnabled())
        lg.trace("StochSolver.initialize() baseName = " + getBaseName());
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INPUT_FILE);
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(inputFilename);
        StochFileWriter stFileWriter = new StochFileWriter(pw, simTask, bMessaging);
        stFileWriter.write();
    } catch (Exception e) {
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not generate input file: " + e.getMessage())));
        e.printStackTrace(System.out);
        throw new SolverException("solver input file exception: " + e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
    // get executable path+name.
    setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
// setMathExecutable(new cbit.vcell.solvers.MathExecutable(executableName + " gibson " + getBaseName() + ".stochInput" + " " + getBaseName() + ".stoch"));
}
Also used : SolverException(cbit.vcell.solver.SolverException) MathExecutable(cbit.vcell.solvers.MathExecutable) SolverStatus(cbit.vcell.solver.server.SolverStatus) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) FileNotFoundException(java.io.FileNotFoundException) SolverException(cbit.vcell.solver.SolverException) MathException(cbit.vcell.math.MathException) PrintWriter(java.io.PrintWriter)

Example 5 with MathExecutable

use of cbit.vcell.solvers.MathExecutable in project vcell by virtualcell.

the class HybridSolver method initialize.

/**
 *  This method takes the place of the old runUnsteady()...
 */
protected void initialize() throws SolverException {
    if (lg.isTraceEnabled())
        lg.trace("HybridSolver.initialize()");
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
    writeFunctionsFile();
    writeLogFile();
    // 
    // file used by precompiled solver.
    String inputFilename = getInputFilename();
    // 
    if (lg.isTraceEnabled())
        lg.trace("HybridSolver.initialize() baseName = " + getBaseName());
    // 
    NetCDFWriter ncWriter = new NetCDFWriter(simTask, inputFilename, bMessaging);
    try {
        ncWriter.initialize();
    } catch (Exception e) {
        setSolverStatus(new cbit.vcell.solver.server.SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not initialize StochFileWriter...")));
        e.printStackTrace(System.out);
        throw new SolverException("autocode init exception: " + e.getMessage());
    }
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INPUT_FILE);
    // 
    try {
        ncWriter.writeHybridInputFile();
    } catch (Exception e) {
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not generate input file: " + e.getMessage())));
        e.printStackTrace(System.err);
        throw new SolverException("solver input file exception: " + e.getMessage());
    }
    // 
    // 
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
    // get executable path+name.
    // Hybrid solver's usage: ProgramName <NetCDF Filename> <epsilon> <lambda> <MSR_Tolerance> <SDE_Tolerance> <SDE_dt> [-R <Random Seed>] [-OV]
    setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
}
Also used : SolverException(cbit.vcell.solver.SolverException) MathExecutable(cbit.vcell.solvers.MathExecutable) SolverStatus(cbit.vcell.solver.server.SolverStatus) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) FileNotFoundException(java.io.FileNotFoundException) MathException(cbit.vcell.math.MathException)

Aggregations

MathExecutable (cbit.vcell.solvers.MathExecutable)7 IOException (java.io.IOException)7 SolverException (cbit.vcell.solver.SolverException)6 SolverStatus (cbit.vcell.solver.server.SolverStatus)6 PrintWriter (java.io.PrintWriter)6 MathException (cbit.vcell.math.MathException)3 ExpressionException (cbit.vcell.parser.ExpressionException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ExecutableException (org.vcell.util.exe.ExecutableException)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1