Search in sources :

Example 61 with Constant

use of cbit.vcell.math.Constant in project vcell by virtualcell.

the class SimulationSymbolTable method applyOverrides.

public void applyOverrides(MathDescription newMath) throws ExpressionException, MappingException, MathException {
    // 
    // replace original constants with "Simulation" constants
    // 
    Variable[] newVarArray = (Variable[]) BeanUtils.getArray(newMath.getVariables(), Variable.class);
    for (int i = 0; i < newVarArray.length; i++) {
        if (newVarArray[i] instanceof Constant) {
            Constant origConstant = (Constant) newVarArray[i];
            Constant simConstant = getLocalConstant(origConstant);
            newVarArray[i] = new Constant(origConstant.getName(), new Expression(simConstant.getExpression()));
        }
    }
    newMath.setAllVariables(newVarArray);
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) PointVariable(cbit.vcell.math.PointVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) Expression(cbit.vcell.parser.Expression) Constant(cbit.vcell.math.Constant)

Example 62 with Constant

use of cbit.vcell.math.Constant in project vcell by virtualcell.

the class SolverTaskDescription method readVCML.

// private void setSmoldynDefaultTimeStep() throws PropertyVetoException {
// if (fieldSimulation != null) {
// SmoldynTimeStepVars smoldynTimeStepVars = RunSims.computeMaxSmoldynTimeStep(fieldSimulation);
// double maxDt = smoldynTimeStepVars.getMaxDt();
// setTimeStep(new TimeStep(maxDt, maxDt, maxDt));
// }
// }
/**
 * Insert the method's description here.
 * Creation date: (10/24/00 3:45:12 PM)
 * @return java.lang.String
 */
public void readVCML(CommentStringTokenizer tokens) throws DataAccessException {
    // 
    // read format as follows: (OUT OF DATE)
    // 
    // SolverTaskDescription {
    // TaskType Unsteady
    // MaxTime 1
    // SolverDescription "Runga-Kutta Fehlberg"
    // UseSymbolicJacobian false
    // TimeBounds {
    // StartingTime	0.0
    // EndingTime		0.0
    // }
    // TimeStep {
    // DefaultTimeStep		0.0
    // MinimumTimeStep		0.0
    // MaximumTimeStep		0.0
    // }
    // ErrorTolerance {
    // AbsoluteErrorTolerance 1e-8
    // RelativeErrorTolerance 1e-4
    // }
    // StochSimOptions {
    // UseCustomSeed	false
    // CustomSeed	0
    // NumOfTrials	1
    // if Hybrid, we have following four more
    // Epsilon 100
    // Lambda 10
    // MSRTolerance 0.01
    // SDETolerance 1e-4
    // }
    // 
    // or
    // 
    // StochSimOptions {
    // UseCustomSeed	false
    // CustomSeed	0
    // NumOfTrials	1
    // }
    // StochHybridOptions {
    // Epsilon 100
    // Lambda 10
    // MSRTolerance 0.01
    // SDETolerance 1e-4
    // }
    // StopAtSpatiallyUniform {
    // AbsoluteErrorTolerance	1e-8
    // RelativeErrorTolerance 1e-4
    // }
    // KeepEvery 1
    // KeepAtMost	1000
    // OR
    // OutputOptions {
    // KeepEvery 1
    // KeepAtMost 1000
    // }
    // OR
    // OutputOptions {
    // OutputTimeStep 0.5
    // }
    // OR
    // OutputOptions {
    // OutputTimes 0.1,0.3,0.4,... (comma separated list, no spaces or linefeeds between numbers in list)
    // }
    // 
    // SensitivityParameter {
    // Constant k1 39.0;
    // }
    // RunParameterScanSerially false
    // }
    // 
    // 
    int keepEvery = -1;
    int keepAtMost = -1;
    SolverDescription sd = null;
    try {
        String token = tokens.nextToken();
        if (token.equalsIgnoreCase(VCML.SolverTaskDescription)) {
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
        }
        while (tokens.hasMoreTokens()) {
            token = tokens.nextToken();
            lg.debug(token);
            if (token.equalsIgnoreCase(VCML.EndBlock)) {
                lg.debug("end block");
                break;
            }
            if (token.equalsIgnoreCase(VCML.TaskType)) {
                token = tokens.nextToken();
                if (token.equals(VCML.TaskType_Unsteady)) {
                    setTaskType(TASK_UNSTEADY);
                } else if (token.equals(VCML.TaskType_Steady)) {
                    setTaskType(TASK_STEADY);
                } else {
                    throw new DataAccessException("unexpected " + VCML.TaskType + " = " + token);
                }
                continue;
            }
            if (token.equalsIgnoreCase(VCML.SolverDescription)) {
                token = tokens.nextToken();
                // 
                try {
                    sd = SolverDescription.fromDatabaseName(token);
                    setSolverDescription(sd);
                } catch (java.beans.PropertyVetoException e) {
                    e.printStackTrace(System.out);
                }
                continue;
            }
            if (token.equalsIgnoreCase(VCML.UseSymbolicJacobian)) {
                token = tokens.nextToken();
                setUseSymbolicJacobian((new Boolean(token)).booleanValue());
                continue;
            }
            // code allows us to read the old format.
            if (token.equalsIgnoreCase(VCML.MaxTime)) {
                token = tokens.nextToken();
                // double dummyMaxTime = Double.parseDouble(token);
                continue;
            }
            if (token.equalsIgnoreCase(VCML.TimeBounds)) {
                getTimeBounds().readVCML(tokens);
                continue;
            }
            if (token.equalsIgnoreCase(VCML.TimeStep)) {
                getTimeStep().readVCML(tokens);
                continue;
            }
            if (token.equalsIgnoreCase(VCML.ErrorTolerance)) {
                getErrorTolerance().readVCML(tokens);
                continue;
            }
            if (token.equalsIgnoreCase(VCML.NFSimSimulationOptions)) {
                getNFSimSimulationOptions().readVCML(tokens);
                continue;
            }
            if (token.equalsIgnoreCase(VCML.StochSimOptions)) {
                boolean useCustomSeed = false;
                int customSeed = -1;
                long numOfTrials = 1;
                Double epsilon = null;
                Double lambda = null;
                Double MSRTolerance = null;
                Double SDETolerance = null;
                token = tokens.nextToken();
                if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                    throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
                }
                while (tokens.hasMoreTokens()) {
                    token = tokens.nextToken();
                    if (token.equalsIgnoreCase(VCML.EndBlock)) {
                        break;
                    }
                    if (token.equalsIgnoreCase(VCML.UseCustomSeed)) {
                        token = tokens.nextToken();
                        useCustomSeed = Boolean.parseBoolean(token);
                        continue;
                    }
                    if (token.equalsIgnoreCase(VCML.CustomSeed)) {
                        token = tokens.nextToken();
                        int val1 = Integer.parseInt(token);
                        if (val1 < 0) {
                            throw new DataAccessException("unexpected token " + token + ", seed is required to be an unsigned interger. ");
                        } else {
                            customSeed = val1;
                        }
                        continue;
                    }
                    if (token.equalsIgnoreCase(VCML.NumOfTrials)) {
                        token = tokens.nextToken();
                        int val2 = Integer.parseInt(token);
                        if (val2 < 1) {
                            throw new DataAccessException("unexpected token " + token + ", num of trials is requied to be at least 1. ");
                        } else {
                            numOfTrials = val2;
                        }
                        continue;
                    }
                    // 
                    if (token.equalsIgnoreCase(VCML.Epsilon)) {
                        token = tokens.nextToken();
                        double val3 = Double.parseDouble(token);
                        if (val3 < 1)
                            throw new DataAccessException("unexpected token " + token + ", Minimum number of molecue is requied to be greater than or equal to 1. ");
                        else
                            epsilon = val3;
                        continue;
                    }
                    if (token.equalsIgnoreCase(VCML.Lambda)) {
                        token = tokens.nextToken();
                        double val4 = Double.parseDouble(token);
                        if (val4 <= 0)
                            throw new DataAccessException("unexpected token " + token + ", num of trials is requied to be greater than 0. ");
                        else
                            lambda = val4;
                        continue;
                    }
                    if (token.equalsIgnoreCase(VCML.MSRTolerance)) {
                        token = tokens.nextToken();
                        double val5 = Double.parseDouble(token);
                        if (val5 <= 0)
                            throw new DataAccessException("unexpected token " + token + ", Maximum allowed effect of slow reactions is requied to be greater than 0. ");
                        else
                            MSRTolerance = val5;
                        continue;
                    }
                    if (token.equalsIgnoreCase(VCML.SDETolerance)) {
                        token = tokens.nextToken();
                        double val6 = Double.parseDouble(token);
                        if (val6 <= 0)
                            throw new DataAccessException("unexpected token " + token + ", SDE allowed value of drift and diffusion errors is requied to be greater than 0. ");
                        else
                            SDETolerance = val6;
                        continue;
                    }
                    throw new DataAccessException("unexpected identifier " + token);
                }
                if (getSimulation() != null && getSimulation().getMathDescription() != null) {
                    if (getSimulation().getMathDescription().isNonSpatialStoch()) {
                        setStochOpt(new NonspatialStochSimOptions(useCustomSeed, customSeed, numOfTrials));
                        if (epsilon != null && lambda != null && MSRTolerance != null && SDETolerance != null) {
                            setStochHybridOpt(new NonspatialStochHybridOptions(epsilon, lambda, MSRTolerance, SDETolerance));
                        }
                    } else {
                        setStochOpt(null);
                    }
                }
                continue;
            }
            if (token.equalsIgnoreCase(VCML.StochHybridOptions)) {
                Double epsilon = null;
                Double lambda = null;
                Double MSRTolerance = null;
                Double SDETolerance = null;
                token = tokens.nextToken();
                if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                    throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
                }
                while (tokens.hasMoreTokens()) {
                    token = tokens.nextToken();
                    if (token.equalsIgnoreCase(VCML.EndBlock)) {
                        break;
                    }
                    if (token.equalsIgnoreCase(VCML.Epsilon)) {
                        token = tokens.nextToken();
                        double val3 = Double.parseDouble(token);
                        if (val3 < 1)
                            throw new DataAccessException("unexpected token " + token + ", Minimum number of molecue is requied to be greater than or equal to 1. ");
                        else
                            epsilon = val3;
                        continue;
                    }
                    if (token.equalsIgnoreCase(VCML.Lambda)) {
                        token = tokens.nextToken();
                        double val4 = Double.parseDouble(token);
                        if (val4 <= 0)
                            throw new DataAccessException("unexpected token " + token + ", num of trials is requied to be greater than 0. ");
                        else
                            lambda = val4;
                        continue;
                    }
                    if (token.equalsIgnoreCase(VCML.MSRTolerance)) {
                        token = tokens.nextToken();
                        double val5 = Double.parseDouble(token);
                        if (val5 <= 0)
                            throw new DataAccessException("unexpected token " + token + ", Maximum allowed effect of slow reactions is requied to be greater than 0. ");
                        else
                            MSRTolerance = val5;
                        continue;
                    }
                    if (token.equalsIgnoreCase(VCML.SDETolerance)) {
                        token = tokens.nextToken();
                        double val6 = Double.parseDouble(token);
                        if (val6 <= 0)
                            throw new DataAccessException("unexpected token " + token + ", SDE allowed value of drift and diffusion errors is requied to be greater than 0. ");
                        else
                            SDETolerance = val6;
                        continue;
                    }
                    throw new DataAccessException("unexpected identifier " + token);
                }
                if (getSimulation() != null && getSimulation().getMathDescription() != null) {
                    if (getSimulation().getMathDescription().isNonSpatialStoch()) {
                        if (epsilon != null && lambda != null && MSRTolerance != null && SDETolerance != null) {
                            setStochHybridOpt(new NonspatialStochHybridOptions(epsilon, lambda, MSRTolerance, SDETolerance));
                        }
                    }
                }
                continue;
            }
            if (token.equalsIgnoreCase(VCML.OutputOptions)) {
                fieldOutputTimeSpec = OutputTimeSpec.readVCML(tokens);
                continue;
            }
            if (token.equalsIgnoreCase(VCML.KeepEvery)) {
                token = tokens.nextToken();
                keepEvery = Integer.parseInt(token);
                continue;
            }
            if (token.equalsIgnoreCase(VCML.KeepAtMost)) {
                token = tokens.nextToken();
                keepAtMost = Integer.parseInt(token);
                continue;
            }
            if (token.equalsIgnoreCase(VCML.SensitivityParameter)) {
                token = tokens.nextToken();
                if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                    throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
                }
                token = tokens.nextToken();
                if (!token.equalsIgnoreCase(VCML.Constant)) {
                    throw new DataAccessException("unexpected token " + token + " expecting " + VCML.Constant);
                }
                String name = tokens.nextToken();
                Expression exp = MathFunctionDefinitions.fixFunctionSyntax(tokens);
                Constant constant = new Constant(name, exp);
                setSensitivityParameter(constant);
                token = tokens.nextToken();
                if (!token.equalsIgnoreCase(VCML.EndBlock)) {
                    throw new DataAccessException("unexpected token " + token + " expecting " + VCML.EndBlock);
                }
                continue;
            }
            if (token.equalsIgnoreCase(VCML.StopAtSpatiallyUniform)) {
                token = tokens.nextToken();
                stopAtSpatiallyUniformErrorTolerance = ErrorTolerance.getDefaultSpatiallyUniformErrorTolerance();
                stopAtSpatiallyUniformErrorTolerance.readVCML(tokens);
            } else if (token.equalsIgnoreCase(VCML.RunParameterScanSerially)) {
                token = tokens.nextToken();
                setSerialParameterScan((new Boolean(token)).booleanValue());
            } else if (token.equalsIgnoreCase(VCML.SmoldynSimulationOptions)) {
                setSmoldynSimulationOptions(new SmoldynSimulationOptions(tokens));
            } else if (token.equalsIgnoreCase(VCML.SundialsSolverOptions)) {
                setSundialsPdeSolverOptions(new SundialsPdeSolverOptions(tokens));
            } else if (token.equalsIgnoreCase(VCML.ChomboSolverSpec)) {
                chomboSolverSpec = new ChomboSolverSpec(tokens);
            } else if (token.equalsIgnoreCase(VCML.NUM_PROCESSORS)) {
                token = tokens.nextToken();
                numProcessors = Integer.parseInt(token);
            } else if (token.equalsIgnoreCase(VCML.MovingBoundarySolverOptions)) {
                movingBoundarySolverOptions = new MovingBoundarySolverOptions(tokens);
            } else {
                throw new DataAccessException("unexpected identifier " + token);
            }
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("line #" + (tokens.lineIndex() + 1) + " Exception: " + e.getMessage());
    }
    if (keepEvery != -1) {
        fieldOutputTimeSpec = new DefaultOutputTimeSpec(keepEvery, keepAtMost);
    }
}
Also used : MovingBoundarySolverOptions(cbit.vcell.solvers.mb.MovingBoundarySolverOptions) Constant(cbit.vcell.math.Constant) ChomboSolverSpec(org.vcell.chombo.ChomboSolverSpec) PropertyVetoException(java.beans.PropertyVetoException) Expression(cbit.vcell.parser.Expression) DataAccessException(org.vcell.util.DataAccessException)

Example 63 with Constant

use of cbit.vcell.math.Constant 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 64 with Constant

use of cbit.vcell.math.Constant in project vcell by virtualcell.

the class RateSensitivity method parseMathDesc.

/**
 * This method was created by a SmartGuide.
 * @exception java.lang.Exception The exception description.
 */
private void parseMathDesc() throws MathException {
    Vector equationList = new Vector();
    Enumeration enum1 = subDomain.getEquations();
    while (enum1.hasMoreElements()) {
        Equation equ = (Equation) enum1.nextElement();
        if (equ instanceof OdeEquation) {
            equationList.addElement(equ);
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    Vector constantList = new Vector();
    enum1 = mathDesc.getVariables();
    while (enum1.hasMoreElements()) {
        Variable var = (Variable) enum1.nextElement();
        if (var instanceof Constant) {
            constantList.addElement(var);
        }
    }
    numConstants = constantList.size();
    numRates = equationList.size();
    rates = new Expression[numRates];
    vars = new Variable[numRates];
    consts = new Constant[numConstants];
    for (int i = 0; i < numRates; i++) {
        OdeEquation odeEqu = (OdeEquation) equationList.elementAt(i);
        rates[i] = odeEqu.getRateExpression();
        vars[i] = odeEqu.getVariable();
    }
    for (int i = 0; i < numConstants; i++) {
        consts[i] = (Constant) constantList.elementAt(i);
    }
}
Also used : Enumeration(java.util.Enumeration) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) OdeEquation(cbit.vcell.math.OdeEquation) MathException(cbit.vcell.math.MathException) Constant(cbit.vcell.math.Constant) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) Vector(java.util.Vector)

Example 65 with Constant

use of cbit.vcell.math.Constant in project vcell by virtualcell.

the class RateSensitivity method show.

/**
 * This method was created by a SmartGuide.
 */
public void show() throws MathException, ExpressionException {
    refresh();
    for (int rateIndex = 0; rateIndex < numRates; rateIndex++) {
        for (int constantIndex = 0; constantIndex < numConstants; constantIndex++) {
            Expression rateExp = rates[rateIndex];
            Constant constant = consts[constantIndex];
            /* Expression sens = CPexp[rateIndex+constantIndex*numRates];
			if (sens == null){
				continue;
			}*/
            Expression sens = getCPexp(rateIndex, constantIndex);
            System.out.println("RateSensitivity of " + vars[rateIndex].getName() + "' wrt " + consts[constantIndex].getName() + " is " + sens);
        }
    }
}
Also used : Expression(cbit.vcell.parser.Expression) Constant(cbit.vcell.math.Constant)

Aggregations

Constant (cbit.vcell.math.Constant)69 Expression (cbit.vcell.parser.Expression)43 Variable (cbit.vcell.math.Variable)31 Function (cbit.vcell.math.Function)24 MathDescription (cbit.vcell.math.MathDescription)22 VolVariable (cbit.vcell.math.VolVariable)21 ExpressionException (cbit.vcell.parser.ExpressionException)21 MathException (cbit.vcell.math.MathException)15 Vector (java.util.Vector)15 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)14 MemVariable (cbit.vcell.math.MemVariable)14 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)13 SubDomain (cbit.vcell.math.SubDomain)13 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)12 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)12 ReservedVariable (cbit.vcell.math.ReservedVariable)11 FilamentVariable (cbit.vcell.math.FilamentVariable)10 InsideVariable (cbit.vcell.math.InsideVariable)10 OutsideVariable (cbit.vcell.math.OutsideVariable)10 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)9