Search in sources :

Example 21 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class DefaultODESolver method initialize.

/**
 * This method was created by a SmartGuide.
 * @exception SolverException The exception description.
 */
protected void initialize() throws SolverException {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    Simulation sim = simSymbolTable.getSimulation();
    try {
        // create a fast system if necessary
        fieldFastAlgebraicSystem = null;
        if (getSubDomain().getFastSystem() != null) {
            fieldFastAlgebraicSystem = new FastAlgebraicSystem(new FastSystemAnalyzer(getSubDomain().getFastSystem(), simSymbolTable));
        }
        // refreshIdentifiers();
        fieldIdentifiers = createIdentifiers();
        fieldSensVariables = createSensitivityVariables();
        // refreshStateVariables();
        fieldStateVariables = createStateVariables();
        // 
        // allocate ValueVectors object
        fieldValueVectors = new ValueVectors(getValueVectorCount(), fieldIdentifiers.size());
        // initialize indexes of variables
        fieldVariableIndexes = new int[getStateVariableCount()];
        for (int i = 0; i < getStateVariableCount(); i++) {
            fieldVariableIndexes[i] = getStateVariable(i).getVariable().getIndex();
        }
        // initialize constants
        double[] initialValues = getValueVector(0);
        for (int i = 0; i < fieldIdentifiers.size(); i++) {
            if (fieldIdentifiers.elementAt(i) instanceof Constant) {
                Constant constant = (Constant) fieldIdentifiers.elementAt(i);
                constant.bind(simSymbolTable);
                if (constant.isConstant()) {
                    // constant.getValue();
                    initialValues[constant.getIndex()] = constant.getExpression().evaluateConstant();
                } else {
                    throw new SolverException("cannot evaluate constant '" + constant.getName() + "' = " + constant.getExpression());
                }
            }
        }
        // initialize variables
        for (int i = 0; i < getStateVariableCount(); i++) {
            initialValues[getVariableIndex(i)] = getStateVariable(i).evaluateIC(initialValues);
        }
        fieldODESolverResultSet = createODESolverResultSet();
        // reset - in the ** default ** solvers we don't pick up from where we left off, we can override that behaviour in integrate() if ever necessary
        fieldCurrentTime = sim.getSolverTaskDescription().getTimeBounds().getStartingTime();
    } catch (ExpressionException expressionException) {
        expressionException.printStackTrace(System.out);
        throw new SolverException(expressionException.getMessage());
    } catch (MathException mathException) {
        mathException.printStackTrace(System.out);
        throw new SolverException(mathException.getMessage());
    }
}
Also used : FastSystemAnalyzer(cbit.vcell.mapping.FastSystemAnalyzer) Simulation(cbit.vcell.solver.Simulation) Constant(cbit.vcell.math.Constant) PseudoConstant(cbit.vcell.math.PseudoConstant) MathException(cbit.vcell.math.MathException) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 22 with SolverException

use of cbit.vcell.solver.SolverException 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 23 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class SundialsSolver method writeLogFile.

private void writeLogFile() throws SolverException {
    String logFile = getBaseName() + LOGFILE_EXTENSION;
    String ideDataFileName = new File(getBaseName() + IDA_DATA_EXTENSION).getName();
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(logFile);
        pw.println(IDA_DATA_IDENTIFIER);
        pw.println(IDA_DATA_FORMAT_ID);
        pw.println(ideDataFileName);
        OutputTimeSpec outputTimeSpec = simTask.getSimulation().getSolverTaskDescription().getOutputTimeSpec();
        if (outputTimeSpec.isDefault()) {
            pw.println(KEEP_MOST + " " + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepAtMost());
        }
        pw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new SolverException(e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) FileNotFoundException(java.io.FileNotFoundException) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) PrintWriter(java.io.PrintWriter)

Example 24 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class SolverFactory method createSolver.

public static Solver createSolver(File userDir, File parallelDir, SimulationTask simTask, boolean bMessaging) throws SolverException {
    SolverDescription solverDescription = simTask.getSimulationJob().getSimulation().getSolverTaskDescription().getSolverDescription();
    File simTaskFile = new File(userDir, simTask.getSimulationJobID() + "_" + simTask.getTaskID() + ".simtask.xml");
    if (userDir.exists() && !simTaskFile.exists()) {
        try {
            String simTaskXmlText = XmlHelper.simTaskToXML(simTask);
            XmlUtil.writeXMLStringToFile(simTaskXmlText, simTaskFile.toString(), true);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            throw new SolverException("unable to write SimulationTask file");
        }
    }
    if (solverDescription == null) {
        throw new IllegalArgumentException("SolverDescription cannot be null");
    }
    Maker maker = FACTORY.get(solverDescription);
    if (maker != null) {
        Solver s = maker.make(simTask, userDir, parallelDir, bMessaging);
        return s;
    }
    throw new SolverException("Unknown solver: " + solverDescription);
}
Also used : NFSimSolver(org.vcell.solver.nfsim.NFSimSolver) RungeKuttaFehlbergSolver(cbit.vcell.solver.ode.RungeKuttaFehlbergSolver) MovingBoundarySolver(cbit.vcell.solvers.MovingBoundarySolver) HybridSolver(cbit.vcell.solver.stoch.HybridSolver) AdamsMoultonFiveSolver(cbit.vcell.solver.ode.AdamsMoultonFiveSolver) GibsonSolver(cbit.vcell.solver.stoch.GibsonSolver) CombinedSundialsSolver(cbit.vcell.solvers.CombinedSundialsSolver) RungeKuttaTwoSolver(cbit.vcell.solver.ode.RungeKuttaTwoSolver) RungeKuttaFourSolver(cbit.vcell.solver.ode.RungeKuttaFourSolver) ComsolSolver(org.vcell.solver.comsol.ComsolSolver) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) ForwardEulerSolver(cbit.vcell.solver.ode.ForwardEulerSolver) SolverDescription(cbit.vcell.solver.SolverDescription) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) SolverException(cbit.vcell.solver.SolverException)

Example 25 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class RungeKuttaFehlbergSolver method step.

/**
 * Integrate over time step using the forward Euler method (1st order explicit)
 * results must be stored in NumVectors-1 = vector(4);
 *  t is the current time
 *  h is the time step
 */
protected void step(double t, double h) throws SolverException {
    try {
        double[] oldValues = getValueVector(0);
        double[] newValues = getValueVector(1);
        // 
        // update time
        oldValues[getTimeIndex()] = t;
        // 
        for (int i = 0; i < 6; i++) {
            newValues[getTimeIndex()] = t + a[i] * h;
            for (int j = 0; j < getStateVariableCount(); j++) {
                int J = getVariableIndex(j);
                newValues[J] = oldValues[J];
                for (int m = 0; m < i; m++) {
                    newValues[J] += b[i][m] * k[m][J];
                }
            }
            for (int j = 0; j < getStateVariableCount(); j++) {
                k[i][getVariableIndex(j)] = h * evaluate(newValues, j);
            }
        }
        for (int i = 0; i < getStateVariableCount(); i++) {
            int I = getVariableIndex(i);
            newValues[I] = oldValues[I];
            for (int j = 0; j < 6; j++) {
                newValues[I] += c[j] * k[j][I];
            }
        }
    } catch (ExpressionException expressionException) {
        throw new SolverException(expressionException.getMessage());
    }
}
Also used : SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

SolverException (cbit.vcell.solver.SolverException)53 ExpressionException (cbit.vcell.parser.ExpressionException)28 IOException (java.io.IOException)23 MathException (cbit.vcell.math.MathException)20 PrintWriter (java.io.PrintWriter)16 File (java.io.File)15 Element (org.jdom.Element)13 SolverStatus (cbit.vcell.solver.server.SolverStatus)10 DataAccessException (org.vcell.util.DataAccessException)9 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)8 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)8 Variable (cbit.vcell.math.Variable)8 FileNotFoundException (java.io.FileNotFoundException)8 ISize (org.vcell.util.ISize)8 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)7 ImageException (cbit.image.ImageException)6 GeometryException (cbit.vcell.geometry.GeometryException)6 Expression (cbit.vcell.parser.Expression)5 SubVolume (cbit.vcell.geometry.SubVolume)4 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)4