Search in sources :

Example 26 with SimulationSymbolTable

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

the class RunSims method isSmoldynTimeStepOK.

private boolean isSmoldynTimeStepOK(Simulation sim) {
    for (int jobIndex = 0; jobIndex < sim.getScanCount(); jobIndex++) {
        SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, jobIndex);
        double Dmax = 0;
        MathDescription mathDesc = sim.getMathDescription();
        Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
        while (subDomainEnumeration.hasMoreElements()) {
            SubDomain subDomain = subDomainEnumeration.nextElement();
            // }
            for (ParticleProperties particleProperties : subDomain.getParticleProperties()) {
                try {
                    Expression newExp = new Expression(particleProperties.getDiffusion());
                    newExp.bindExpression(simSymbolTable);
                    newExp = simSymbolTable.substituteFunctions(newExp).flatten();
                    try {
                        double diffConstant = newExp.evaluateConstant();
                        Dmax = Math.max(Dmax, diffConstant);
                    } catch (ExpressionException ex) {
                        throw new ExpressionException("diffusion coefficient for variable " + particleProperties.getVariable().getQualifiedName() + " is not a constant. Constants are required for all diffusion coefficients");
                    }
                } catch (Exception ex) {
                }
            }
        }
        double s = sim.getMeshSpecification().getDx(sim.hasCellCenteredMesh());
        double dt = sim.getSolverTaskDescription().getTimeStep().getDefaultTimeStep();
        if (dt >= s * s / (2 * Dmax)) {
            smoldynTimestepVars = new SmoldynTimeStepVars(s, Dmax);
            return false;
        }
    }
    return true;
}
Also used : SubDomain(cbit.vcell.math.SubDomain) MathDescription(cbit.vcell.math.MathDescription) Expression(cbit.vcell.parser.Expression) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) ParticleProperties(cbit.vcell.math.ParticleProperties) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException)

Example 27 with SimulationSymbolTable

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

the class DefaultODESolver method createIdentifiers.

/**
 * This method was created in VisualAge.
 */
private Vector<Variable> createIdentifiers() throws MathException, ExpressionException {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    // create list of possible identifiers (including reserved x,y,z,t)
    Vector<Variable> identifiers = new Vector<Variable>();
    // add reserved variables x,y,z,t
    identifiers.addElement(ReservedVariable.TIME);
    identifiers.addElement(ReservedVariable.X);
    identifiers.addElement(ReservedVariable.Y);
    identifiers.addElement(ReservedVariable.Z);
    // add regular variables
    Variable[] variables = simSymbolTable.getVariables();
    for (int i = 0; i < variables.length; i++) {
        if (variables[i] instanceof VolVariable) {
            identifiers.addElement(variables[i]);
        }
    }
    // Add sensitivity variables (for sensitivity equations)...
    fieldSensVariables = new Vector<SensVariable>();
    if (getSensitivityParameter() != null) {
        for (int i = 0; i < variables.length; i++) {
            if (variables[i] instanceof VolVariable) {
                VolVariable volVariable = (VolVariable) variables[i];
                SensVariable sv = new SensVariable(volVariable, getSensitivityParameter());
                identifiers.addElement(sv);
            }
        }
    }
    // Add pseudoConstants for fast system (if necessary)...
    if (getFastAlgebraicSystem() != null) {
        Enumeration<PseudoConstant> enum1 = fieldFastAlgebraicSystem.getPseudoConstants();
        while (enum1.hasMoreElements()) {
            identifiers.addElement(enum1.nextElement());
        }
    }
    // Assign indices...
    for (int i = 0; i < identifiers.size(); i++) {
        Variable variable = (Variable) identifiers.elementAt(i);
        variable.setIndex(i);
    }
    return (identifiers);
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) VolVariable(cbit.vcell.math.VolVariable) PseudoConstant(cbit.vcell.math.PseudoConstant) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) Vector(java.util.Vector)

Example 28 with SimulationSymbolTable

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

the class DefaultODESolver method getSensitivityParameter.

/**
 * Gets the sensitivityParameter property (cbit.vcell.math.Constant) value.
 * THIS IS ONLY A CONVENIENCE FUNCTION...AND IT WOULD BE GOOD TO GET RID OF IT
 * EVENTUALLY...WHEN YOU HAVE TIME!!!
 * @return The sensitivityParameter property value.
 * @see #setSensitivityParameter
 */
public Constant getSensitivityParameter() {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    Constant origSensParam = simSymbolTable.getSimulation().getSolverTaskDescription().getSensitivityParameter();
    // 
    if (origSensParam != null) {
        return (Constant) simSymbolTable.getVariable(origSensParam.getName());
    } else {
        return null;
    }
}
Also used : Constant(cbit.vcell.math.Constant) PseudoConstant(cbit.vcell.math.PseudoConstant) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable)

Example 29 with SimulationSymbolTable

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

the class DefaultODESolver method createStateVariables.

/**
 * This method was created in VisualAge.
 */
private Vector<StateVariable> createStateVariables() throws MathException, ExpressionException {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    Simulation sim = simSymbolTable.getSimulation();
    Vector<StateVariable> stateVariables = new Vector<StateVariable>();
    // get Ode's from MathDescription and create ODEStateVariables
    Enumeration<Equation> enum1 = getSubDomain().getEquations();
    while (enum1.hasMoreElements()) {
        Equation equation = enum1.nextElement();
        if (equation instanceof OdeEquation) {
            stateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    MathDescription mathDescription = sim.getMathDescription();
    if (rateSensitivity == null) {
        rateSensitivity = new RateSensitivity(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    if (jacobian == null) {
        jacobian = new Jacobian(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    // get Jacobian and RateSensitivities from MathDescription and create SensStateVariables
    for (int v = 0; v < fieldSensVariables.size(); v++) {
        stateVariables.addElement(new SensStateVariable(fieldSensVariables.elementAt(v), rateSensitivity, jacobian, fieldSensVariables, simSymbolTable));
    }
    if (stateVariables.size() == 0) {
        throw new MathException("there are no equations defined");
    }
    return (stateVariables);
}
Also used : MathDescription(cbit.vcell.math.MathDescription) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) Simulation(cbit.vcell.solver.Simulation) OdeEquation(cbit.vcell.math.OdeEquation) MathException(cbit.vcell.math.MathException) Vector(java.util.Vector)

Example 30 with SimulationSymbolTable

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

the class SundialsSolver method createFunctionList.

public Vector<AnnotatedFunction> createFunctionList() {
    // 
    // add appropriate Function columns to result set
    // 
    Vector<AnnotatedFunction> funcList = super.createFunctionList();
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    if (getSensitivityParameter() != null) {
        try {
            AnnotatedFunction saf = new AnnotatedFunction(getSensitivityParameter().getName(), new Expression(getSensitivityParameter().getConstantValue()), getSensitivityParameter().getDomain(), "", VariableType.NONSPATIAL, FunctionCategory.PREDEFINED);
            if (!funcList.contains(saf)) {
                funcList.add(saf);
            }
            Variable[] variables = simSymbolTable.getVariables();
            StateVariable[] stateVars = createStateVariables();
            for (int i = 0; i < variables.length; i++) {
                if (variables[i] instanceof Function && SimulationSymbolTable.isFunctionSaved((Function) variables[i])) {
                    Function depSensFunction = (Function) variables[i];
                    Expression depSensFnExpr = new Expression(depSensFunction.getExpression());
                    depSensFnExpr = simSymbolTable.substituteFunctions(depSensFnExpr);
                    depSensFnExpr = getFunctionSensitivity(depSensFnExpr, getSensitivityParameter(), stateVars);
                    // depSensFnExpr = depSensFnExpr.flatten(); 	// already bound and flattened in getFunctionSensitivity, no need here.....
                    String depSensFnName = new String("sens_" + depSensFunction.getName() + "_wrt_" + getSensitivityParameter().getName());
                    if (depSensFunction != null) {
                        AnnotatedFunction af = new AnnotatedFunction(depSensFnName, depSensFnExpr.flatten(), variables[i].getDomain(), "", VariableType.NONSPATIAL, FunctionCategory.PREDEFINED);
                        funcList.add(af);
                    }
                }
            }
        } catch (MathException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Error adding function to resultSet: " + e.getMessage());
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Error adding function to resultSet: " + e.getMessage());
        }
    }
    return funcList;
}
Also used : Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) ExpressionException(cbit.vcell.parser.ExpressionException) Function(cbit.vcell.math.Function) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Aggregations

SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)32 Expression (cbit.vcell.parser.Expression)20 Simulation (cbit.vcell.solver.Simulation)14 MathException (cbit.vcell.math.MathException)13 Variable (cbit.vcell.math.Variable)13 ExpressionException (cbit.vcell.parser.ExpressionException)12 VolVariable (cbit.vcell.math.VolVariable)11 MathDescription (cbit.vcell.math.MathDescription)10 Equation (cbit.vcell.math.Equation)8 SubDomain (cbit.vcell.math.SubDomain)8 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)7 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)6 Function (cbit.vcell.math.Function)6 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)6 OdeEquation (cbit.vcell.math.OdeEquation)6 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)6 Vector (java.util.Vector)6 ReservedVariable (cbit.vcell.math.ReservedVariable)5 Constant (cbit.vcell.math.Constant)4 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)4