Search in sources :

Example 96 with Variable

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

the class SimulationSymbolTable method getVariables.

/**
 * Insert the method's description here.
 * Creation date: (5/25/01 11:34:08 AM)
 * @return cbit.vcell.math.Variable[]
 */
public Variable[] getVariables() {
    Vector<Variable> varList = new Vector<Variable>();
    // 
    // get all variables from MathDescription, but replace MathOverrides
    // 
    Enumeration<Variable> enum1 = simulation.getMathDescription().getVariables();
    while (enum1.hasMoreElements()) {
        Variable mathDescriptionVar = enum1.nextElement();
        // 
        if (mathDescriptionVar instanceof Constant) {
            try {
                Constant overriddenConstant = getLocalConstant((Constant) mathDescriptionVar);
                varList.addElement(overriddenConstant);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("local Constant " + mathDescriptionVar.getName() + " not found for Simulation");
            }
        // 
        // replace all Functions with local Functions that are bound to this Simulation
        // 
        } else if (mathDescriptionVar instanceof Function) {
            try {
                Function overriddenFunction = getLocalFunction((Function) mathDescriptionVar);
                varList.addElement(overriddenFunction);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("local Function " + mathDescriptionVar.getName() + " not found for Simulation");
            }
        // 
        // pass all other Variables through
        // 
        } else {
            varList.addElement(mathDescriptionVar);
        }
    }
    Variable[] variables = (Variable[]) BeanUtils.getArray(varList, Variable.class);
    return variables;
}
Also used : Function(cbit.vcell.math.Function) 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) Constant(cbit.vcell.math.Constant) Vector(java.util.Vector) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 97 with Variable

use of cbit.vcell.math.Variable 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 98 with Variable

use of cbit.vcell.math.Variable 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 99 with Variable

use of cbit.vcell.math.Variable 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 100 with Variable

use of cbit.vcell.math.Variable 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

Variable (cbit.vcell.math.Variable)108 Expression (cbit.vcell.parser.Expression)69 VolVariable (cbit.vcell.math.VolVariable)63 MemVariable (cbit.vcell.math.MemVariable)48 ReservedVariable (cbit.vcell.math.ReservedVariable)43 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)38 MathException (cbit.vcell.math.MathException)37 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)36 FilamentVariable (cbit.vcell.math.FilamentVariable)35 InsideVariable (cbit.vcell.math.InsideVariable)34 OutsideVariable (cbit.vcell.math.OutsideVariable)34 ExpressionException (cbit.vcell.parser.ExpressionException)34 Function (cbit.vcell.math.Function)32 MathDescription (cbit.vcell.math.MathDescription)32 Constant (cbit.vcell.math.Constant)31 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)29 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)25 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)24 ParticleVariable (cbit.vcell.math.ParticleVariable)24 Vector (java.util.Vector)23