Search in sources :

Example 46 with Variable

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

the class Jacobian 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 variableList = new Vector();
    enum1 = mathDesc.getVariables();
    while (enum1.hasMoreElements()) {
        Variable var = (Variable) enum1.nextElement();
        if (var instanceof VolVariable) {
            variableList.addElement(var);
        }
    }
    if (equationList.size() != variableList.size()) {
        throw new MathException("there are " + equationList.size() + " equations and " + variableList.size() + " variables");
    }
    numVariables = variableList.size();
    rates = new Expression[numVariables];
    vars = new VolVariable[numVariables];
    for (int i = 0; i < numVariables; i++) {
        OdeEquation odeEqu = (OdeEquation) equationList.elementAt(i);
        rates[i] = odeEqu.getRateExpression();
        vars[i] = (VolVariable) odeEqu.getVariable();
    }
}
Also used : Enumeration(java.util.Enumeration) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) OdeEquation(cbit.vcell.math.OdeEquation) VolVariable(cbit.vcell.math.VolVariable) MathException(cbit.vcell.math.MathException) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) Vector(java.util.Vector)

Example 47 with Variable

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

the class SundialsSolver method getODESolverResultSet.

/**
 * This method was created in VisualAge.
 * @return double[]
 * @param vectorIndex int
 */
public ODESolverResultSet getODESolverResultSet() {
    // 
    // read .ida file
    // 
    ODESolverResultSet odeSolverResultSet = getStateVariableResultSet();
    if (odeSolverResultSet == null) {
        return null;
    }
    // 
    // add appropriate Function columns to result set
    // 
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    Function[] functions = simSymbolTable.getFunctions();
    for (int i = 0; i < functions.length; i++) {
        if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
            Expression exp1 = new Expression(functions[i].getExpression());
            try {
                exp1 = simSymbolTable.substituteFunctions(exp1);
            } catch (MathException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
            }
            try {
                FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
                odeSolverResultSet.addFunctionColumn(cd);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
            }
        }
    }
    if (getSensitivityParameter() != null) {
        try {
            if (odeSolverResultSet.findColumn(getSensitivityParameter().getName()) == -1) {
                FunctionColumnDescription fcd = new FunctionColumnDescription(new Expression(getSensitivityParameter().getConstantValue()), getSensitivityParameter().getName(), null, getSensitivityParameter().getName(), false);
                odeSolverResultSet.addFunctionColumn(fcd);
            }
            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) {
                        FunctionColumnDescription cd = new FunctionColumnDescription(depSensFnExpr.flatten(), depSensFnName, getSensitivityParameter().getName(), depSensFnName, false);
                        odeSolverResultSet.addFunctionColumn(cd);
                    }
                }
            }
        } 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 odeSolverResultSet;
}
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) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Example 48 with Variable

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

the class SundialsSolver method createStateVariables.

/*
	This method was created in Visual Age
*/
private StateVariable[] createStateVariables() throws MathException, ExpressionException {
    Vector<StateVariable> stateVariables = new Vector<StateVariable>();
    // get Ode's from MathDescription and create ODEStateVariables
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    MathDescription mathDescription = simSymbolTable.getSimulation().getMathDescription();
    Enumeration<Equation> enum1 = ((SubDomain) mathDescription.getSubDomains().nextElement()).getEquations();
    while (enum1.hasMoreElements()) {
        Equation equation = (Equation) enum1.nextElement();
        if (equation instanceof OdeEquation) {
            stateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    // Get sensitivity variables
    Variable[] variables = simSymbolTable.getVariables();
    Vector<SensVariable> sensVariables = 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());
                sensVariables.addElement(sv);
            }
        }
    }
    if (rateSensitivity == null) {
        rateSensitivity = new RateSensitivity(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    if (jacobian == null) {
        jacobian = new Jacobian(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    for (int v = 0; v < sensVariables.size(); v++) {
        stateVariables.addElement(new SensStateVariable((SensVariable) sensVariables.elementAt(v), rateSensitivity, jacobian, sensVariables, simSymbolTable));
    }
    if (stateVariables.size() == 0) {
        throw new MathException("there are no equations defined");
    }
    StateVariable[] stateVars = (StateVariable[]) BeanUtils.getArray(stateVariables, StateVariable.class);
    return (stateVars);
}
Also used : Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MathDescription(cbit.vcell.math.MathDescription) VolVariable(cbit.vcell.math.VolVariable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) SubDomain(cbit.vcell.math.SubDomain) OdeEquation(cbit.vcell.math.OdeEquation) MathException(cbit.vcell.math.MathException) Vector(java.util.Vector)

Example 49 with Variable

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

the class OdeFileWriter method createStateVariables.

private void createStateVariables() throws Exception {
    Simulation simulation = simTask.getSimulation();
    MathDescription mathDescription = simulation.getMathDescription();
    SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
    // get Ode's from MathDescription and create ODEStateVariables
    Enumeration<Equation> enum1 = mathDescription.getSubDomains().nextElement().getEquations();
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    while (enum1.hasMoreElements()) {
        Equation equation = enum1.nextElement();
        if (equation instanceof OdeEquation) {
            fieldStateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    // Get sensitivity variables
    Variable[] variables = simSymbolTable.getVariables();
    Vector<SensVariable> sensVariables = new Vector<SensVariable>();
    Constant sensitivityParameter = solverTaskDescription.getSensitivityParameter();
    if (sensitivityParameter != null) {
        Constant origSensParam = sensitivityParameter;
        Constant overriddenSensParam = (Constant) simSymbolTable.getVariable(origSensParam.getName());
        for (int i = 0; i < variables.length; i++) {
            if (variables[i] instanceof VolVariable) {
                VolVariable volVariable = (VolVariable) variables[i];
                SensVariable sv = new SensVariable(volVariable, overriddenSensParam);
                sensVariables.addElement(sv);
            }
        }
    }
    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 < sensVariables.size(); v++) {
        fieldStateVariables.addElement(new SensStateVariable(sensVariables.elementAt(v), rateSensitivity, jacobian, sensVariables, simSymbolTable));
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MathDescription(cbit.vcell.math.MathDescription) VolVariable(cbit.vcell.math.VolVariable) Constant(cbit.vcell.math.Constant) 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) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) Vector(java.util.Vector)

Example 50 with Variable

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

the class MovingBoundaryFileWriter method flattenExpression.

private Expression flattenExpression(Expression ex, VariableDomain varDomain) throws ExpressionException, MathException {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    Variable normalX = new Variable("normalX", null) {

        public boolean compareEqual(Matchable object, boolean bIgnoreMissingDomains) {
            return false;
        }

        public String getVCML() throws MathException {
            return null;
        }
    };
    Variable normalY = new Variable("normalY", null) {

        public boolean compareEqual(Matchable object, boolean bIgnoreMissingDomains) {
            return false;
        }

        public String getVCML() throws MathException {
            return null;
        }
    };
    SymbolTable augmentedSymbolTable = new SymbolTable() {

        @Override
        public SymbolTableEntry getEntry(String identifierString) {
            if (identifierString.equals(normalX.getName())) {
                return normalX;
            }
            if (identifierString.equals(normalY.getName())) {
                return normalY;
            }
            return simSymbolTable.getEntry(identifierString);
        }

        @Override
        public void getEntries(Map<String, SymbolTableEntry> entryMap) {
            simSymbolTable.getEntries(entryMap);
            entryMap.put(normalX.getName(), normalX);
            entryMap.put(normalY.getName(), normalY);
        }
    };
    ex = new Expression(ex);
    ex.bindExpression(augmentedSymbolTable);
    Expression flattended = MathUtilities.substituteFunctions(ex, augmentedSymbolTable).flatten();
    Expression substituted = SolverUtilities.substituteSizeAndNormalFunctions(flattended, varDomain).flatten();
    return substituted;
// return simSymbolTable.substituteFunctions(ex).flatten().infix();
}
Also used : PointVariable(cbit.vcell.math.PointVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) Expression(cbit.vcell.parser.Expression) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) SymbolTable(cbit.vcell.parser.SymbolTable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) Map(java.util.Map) Matchable(org.vcell.util.Matchable)

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