Search in sources :

Example 36 with Simulation

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

the class MathTestingUtilities method getConstructedResultSet.

/**
 * Insert the method's description here.
 * Creation date: (1/17/2003 3:47:43 PM)
 * @return cbit.vcell.solver.ode.ODESolverResultSet
 * @param sim cbit.vcell.solver.Simulation
 */
public static ODESolverResultSet getConstructedResultSet(MathDescription mathDesc, double[] time) throws Exception {
    if (mathDesc.getGeometry().getDimension() != 0) {
        throw new RuntimeException("can only handle non-spatial simulations.");
    }
    Simulation sim = new Simulation(mathDesc);
    SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, 0);
    ODESolverResultSet resultSet = new ODESolverResultSet();
    resultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
    for (int i = 0; i < time.length; i++) {
        resultSet.addRow(new double[] { time[i] });
    }
    java.util.Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
    String errorString = "Variable(s) : ";
    while (subDomainEnum.hasMoreElements()) {
        SubDomain subDomain = subDomainEnum.nextElement();
        java.util.Enumeration<Equation> enumEquations = subDomain.getEquations();
        while (enumEquations.hasMoreElements()) {
            Equation equation = enumEquations.nextElement();
            Expression constructedSolution = equation.getExactSolution();
            if (constructedSolution != null) {
                constructedSolution = new Expression(constructedSolution);
                constructedSolution.bindExpression(simSymbolTable);
                constructedSolution = simSymbolTable.substituteFunctions(constructedSolution);
                constructedSolution = constructedSolution.flatten();
                resultSet.addFunctionColumn(new FunctionColumnDescription(constructedSolution, equation.getVariable().getName(), null, equation.getVariable().getName(), false));
            } else {
                errorString = errorString + equation.getVariable().getName() + ", ";
            }
        }
    }
    if (!errorString.equals("Variable(s) : ")) {
        throw new RuntimeException(errorString + " don't have a constructed solution");
    }
    return resultSet;
}
Also used : SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) OdeEquation(cbit.vcell.math.OdeEquation) PdeEquation(cbit.vcell.math.PdeEquation) Equation(cbit.vcell.math.Equation) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Example 37 with Simulation

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

the class MathTestingUtilities method getExactResultSet.

/**
 * Insert the method's description here.
 * Creation date: (1/17/2003 3:47:43 PM)
 * @return cbit.vcell.solver.ode.ODESolverResultSet
 * @param sim cbit.vcell.solver.Simulation
 */
public static ODESolverResultSet getExactResultSet(MathDescription mathDesc, double[] time, Constant sensitivityParam) throws Exception {
    if (mathDesc.getGeometry().getDimension() != 0) {
        throw new RuntimeException("can only handle non-spatial simulations.");
    }
    Simulation sim = new Simulation(mathDesc);
    SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, 0);
    ODESolverResultSet resultSet = new ODESolverResultSet();
    resultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
    for (int i = 0; i < time.length; i++) {
        resultSet.addRow(new double[] { time[i] });
    }
    java.util.Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
    while (subDomainEnum.hasMoreElements()) {
        SubDomain subDomain = subDomainEnum.nextElement();
        java.util.Enumeration<Equation> enumEquations = subDomain.getEquations();
        while (enumEquations.hasMoreElements()) {
            Equation equation = enumEquations.nextElement();
            Expression exactSolution = equation.getExactSolution();
            if (exactSolution != null) {
                exactSolution = new Expression(exactSolution);
                exactSolution.bindExpression(simSymbolTable);
                exactSolution = simSymbolTable.substituteFunctions(exactSolution);
                exactSolution.bindExpression(simSymbolTable);
                exactSolution = exactSolution.flatten();
                resultSet.addFunctionColumn(new FunctionColumnDescription(exactSolution, equation.getVariable().getName(), null, equation.getVariable().getName(), false));
                if (sensitivityParam != null) {
                    exactSolution = equation.getExactSolution();
                    Expression exactSensitivity = new Expression(exactSolution);
                    exactSensitivity.bindExpression(simSymbolTable);
                    exactSensitivity = simSymbolTable.substituteFunctions(exactSensitivity);
                    exactSensitivity.bindExpression(simSymbolTable);
                    exactSensitivity = exactSensitivity.differentiate(sensitivityParam.getName());
                    exactSensitivity = exactSensitivity.flatten();
                    VolVariable volVar = (VolVariable) equation.getVariable();
                    String sensName = SensVariable.getSensName(volVar, sensitivityParam);
                    resultSet.addFunctionColumn(new FunctionColumnDescription(exactSensitivity, sensName, null, sensName, false));
                }
            } else {
                throw new RuntimeException("variable " + equation.getVariable().getName() + " doesn't have an exact solution");
            }
        }
    }
    return resultSet;
}
Also used : VolVariable(cbit.vcell.math.VolVariable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) OdeEquation(cbit.vcell.math.OdeEquation) PdeEquation(cbit.vcell.math.PdeEquation) Equation(cbit.vcell.math.Equation) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Example 38 with Simulation

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

the class AbstractCompiledSolver method getProgress.

/**
 * Insert the method's description here.
 * Creation date: (6/28/01 2:48:52 PM)
 * @return double
 */
public double getProgress() {
    Simulation simulation = simTask.getSimulationJob().getSimulation();
    TimeBounds timeBounds = simulation.getSolverTaskDescription().getTimeBounds();
    double startTime = timeBounds.getStartingTime();
    double endTime = timeBounds.getEndingTime();
    return (currentTime - startTime) / (endTime - startTime);
}
Also used : TimeBounds(cbit.vcell.solver.TimeBounds) Simulation(cbit.vcell.solver.Simulation)

Example 39 with Simulation

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

the class FVSolverStandalone method getChomboCommands.

private Collection<ExecutableCommand> getChomboCommands() {
    assert (isChombo);
    ArrayList<ExecutableCommand> commands = new ArrayList<ExecutableCommand>(2);
    String inputFilename = getInputFilename();
    String executableName = null;
    Simulation simulation = getSimulationJob().getSimulation();
    SolverTaskDescription sTaskDesc = simulation.getSolverTaskDescription();
    final boolean isParallel = sTaskDesc.isParallel();
    int dimension = simulation.getMeshSpecification().getGeometry().getDimension();
    switch(dimension) {
        case 2:
            try {
                executableName = SolverUtilities.getExes(SolverDescription.Chombo)[0].getAbsolutePath();
            } catch (IOException e) {
                throw new RuntimeException("failed to get executable for 2D solver " + SolverDescription.Chombo.getDisplayLabel() + ": " + e.getMessage(), e);
            }
            break;
        case 3:
            try {
                executableName = SolverUtilities.getExes(SolverDescription.Chombo)[1].getAbsolutePath();
            } catch (IOException e) {
                throw new RuntimeException("failed to get executable for 3D solver " + SolverDescription.Chombo.getDisplayLabel() + ": " + e.getMessage(), e);
            }
            break;
        default:
            throw new IllegalArgumentException("VCell Chombo solver does not support " + dimension + "problems");
    }
    if (isParallel) {
        String parallelName = executableName + "parallel";
        ExecutableCommand solve = new ExecutableCommand(new ExecutableCommand.LibraryPath(ResourceUtil.getLocalSolversDirectory().getAbsolutePath()), true, true, parallelName, inputFilename);
        commands.add(solve);
        ChomboSolverSpec css = sTaskDesc.getChomboSolverSpec();
        Objects.requireNonNull(css);
        if (css.isSaveVCellOutput()) {
            ExecutableCommand convertChomboData = new ExecutableCommand(new ExecutableCommand.LibraryPath(ResourceUtil.getLocalSolversDirectory().getAbsolutePath()), true, false, executableName, "-ccd", inputFilename);
            commands.add(convertChomboData);
        }
    } else {
        ExecutableCommand ec = new ExecutableCommand(new ExecutableCommand.LibraryPath(ResourceUtil.getLocalSolversDirectory().getAbsolutePath()), true, false, executableName, inputFilename);
        commands.add(ec);
        primaryCommand = ec;
    }
    return commands;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ChomboSolverSpec(org.vcell.chombo.ChomboSolverSpec) Simulation(cbit.vcell.solver.Simulation) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription)

Example 40 with Simulation

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

the class FiniteVolumeFileWriter method write.

/**
 * Insert the method's description here.
 * Creation date: (5/9/2005 2:52:48 PM)
 * @throws MathException
 * @throws ExpressionException
 * @throws DataAccessException
 * @throws IOException
 */
public void write(String[] parameterNames) throws Exception {
    Variable[] originalVars = null;
    Simulation simulation = simTask.getSimulation();
    MathDescription mathDesc = simulation.getMathDescription();
    if (bChomboSolver) {
        writeJMSParamters();
        writeSimulationParamters();
        writeModelDescription();
        writeChomboSpec();
        writeVariables();
        writePostProcessingBlock();
        writeCompartments();
        writeMembranes();
    } else {
        if (simTask.getSimulation().isSerialParameterScan()) {
            originalVars = (Variable[]) BeanUtils.getArray(mathDesc.getVariables(), Variable.class);
            Variable[] allVars = (Variable[]) BeanUtils.getArray(mathDesc.getVariables(), Variable.class);
            MathOverrides mathOverrides = simulation.getMathOverrides();
            String[] scanParameters = mathOverrides.getOverridenConstantNames();
            for (int i = 0; i < scanParameters.length; i++) {
                String scanParameter = scanParameters[i];
                Variable mathVariable = mathDesc.getVariable(scanParameter);
                // 
                if (mathVariable instanceof Constant) {
                    Constant origConstant = (Constant) mathVariable;
                    for (int j = 0; j < allVars.length; j++) {
                        if (allVars[j].equals(origConstant)) {
                            allVars[j] = new ParameterVariable(origConstant.getName());
                            break;
                        }
                    }
                }
            }
            mathDesc.setAllVariables(allVars);
        }
        writeJMSParamters();
        writeSimulationParamters();
        writeModelDescription();
        writeMeshFile();
        writeVariables();
        if (mathDesc.isSpatialHybrid()) {
            writeSmoldyn();
        }
        writeParameters(parameterNames);
        writeSerialParameterScans();
        writeFieldData();
        writePostProcessingBlock();
        writeCompartments();
        writeMembranes();
        if (originalVars != null) {
            mathDesc.setAllVariables(originalVars);
        }
    }
}
Also used : MathOverrides(cbit.vcell.solver.MathOverrides) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) MemVariable(cbit.vcell.math.MemVariable) Variable(cbit.vcell.math.Variable) Simulation(cbit.vcell.solver.Simulation) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) PseudoConstant(cbit.vcell.math.PseudoConstant) ParameterVariable(cbit.vcell.math.ParameterVariable)

Aggregations

Simulation (cbit.vcell.solver.Simulation)195 SimulationContext (cbit.vcell.mapping.SimulationContext)57 BioModel (cbit.vcell.biomodel.BioModel)53 MathDescription (cbit.vcell.math.MathDescription)48 KeyValue (org.vcell.util.document.KeyValue)33 Geometry (cbit.vcell.geometry.Geometry)29 MathModel (cbit.vcell.mathmodel.MathModel)27 Expression (cbit.vcell.parser.Expression)26 DataAccessException (org.vcell.util.DataAccessException)26 File (java.io.File)25 ExpressionException (cbit.vcell.parser.ExpressionException)24 IOException (java.io.IOException)24 SimulationJob (cbit.vcell.solver.SimulationJob)23 ArrayList (java.util.ArrayList)23 PropertyVetoException (java.beans.PropertyVetoException)20 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)18 XMLSource (cbit.vcell.xml.XMLSource)18 SimulationTask (cbit.vcell.messaging.server.SimulationTask)17 TimeBounds (cbit.vcell.solver.TimeBounds)16 BigString (org.vcell.util.BigString)16