Search in sources :

Example 41 with VolVariable

use of cbit.vcell.math.VolVariable 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 42 with VolVariable

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

the class Jacobian method show.

/**
 * This method was created by a SmartGuide.
 */
public void show() throws MathException, ExpressionException {
    refresh();
    for (int rateIndex = 0; rateIndex < numVariables; rateIndex++) {
        for (int varIndex = 0; varIndex < numVariables; varIndex++) {
            Expression rateExp = rates[rateIndex];
            VolVariable var = vars[varIndex];
            Expression J = getJexp(rateIndex, varIndex);
            System.out.println("Jacobian of " + vars[rateIndex].getName() + "' wrt " + vars[varIndex].getName() + " is " + J);
        }
    }
}
Also used : Expression(cbit.vcell.parser.Expression) VolVariable(cbit.vcell.math.VolVariable)

Example 43 with VolVariable

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

the class OdeFileWriter method createSymbolTable.

/**
 * OdeFileCoder constructor comment.
 * @throws Exception
 */
private void createSymbolTable() throws Exception {
    // 
    // Create symbol table for binding sensitivity variable expressions. (Cannot bind to simulation,
    // since it does not have the sensitivity variables corresponding to the volume variables).
    // 
    varsSymbolTable = new VariableSymbolTable();
    // SymbolTableEntry.index doesn't matter ... just code generating binding by var names not index.
    varsSymbolTable.addVar(ReservedVariable.TIME);
    int count = 0;
    Variable[] variables = simTask.getSimulationJob().getSimulationSymbolTable().getVariables();
    for (int i = 0; i < variables.length; i++) {
        if (variables[i] instanceof VolVariable) {
            VolVariable vVar = (VolVariable) variables[i];
            vVar.setIndex(count);
            varsSymbolTable.addVar(vVar);
            count++;
        } else if (variables[i] instanceof Function) {
            Function func = (Function) variables[i];
            func.setIndex(count);
            varsSymbolTable.addVar(func);
            count++;
        } else if (variables[i] instanceof Constant) {
            Constant constant = (Constant) variables[i];
            constant.setIndex(count);
            varsSymbolTable.addVar(constant);
            count++;
        } else if (variables[i] instanceof ParameterVariable) {
            ParameterVariable param = (ParameterVariable) variables[i];
            param.setIndex(count);
            varsSymbolTable.addVar(param);
            count++;
        }
    }
    // Get the vector of sensVariables, needed for creating SensStateVariables
    Vector<SensStateVariable> sensVars = new Vector<SensStateVariable>();
    for (int i = 0; i < getStateVariableCount(); i++) {
        if (simTask.getSimulation().getSolverTaskDescription().getSensitivityParameter() != null) {
            if (getStateVariable(i) instanceof SensStateVariable) {
                sensVars.addElement((SensStateVariable) getStateVariable(i));
            }
        }
    }
    for (int j = count; j < (count + sensVars.size()); j++) {
        SensVariable sVar = (SensVariable) (sensVars.elementAt(j - count).getVariable());
        sVar.setIndex(j);
        varsSymbolTable.addVar(sVar);
    }
}
Also used : Function(cbit.vcell.math.Function) ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) VolVariable(cbit.vcell.math.VolVariable) Constant(cbit.vcell.math.Constant) VariableSymbolTable(cbit.vcell.parser.VariableSymbolTable) ParameterVariable(cbit.vcell.math.ParameterVariable) Vector(java.util.Vector)

Example 44 with VolVariable

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

the class SensStateVariable method init.

/**
 * This method was created in VisualAge.
 * @param rateSensitivity cbit.vcell.math.RateSensitivity
 * @param jacobian cbit.vcell.math.Jacobian
 */
private void init(RateSensitivity rateSensitivity, Jacobian jacobian, SymbolTable symbolTable, Vector<SensVariable> sensVarArray) throws MathException, ExpressionException {
    // 
    // order sensVars according to the jacobian (rate index)
    // 
    sensVars = (Vector<SensVariable>) sensVarArray.clone();
    for (int i = 0; i < sensVarArray.size(); i++) {
        SensVariable sensVar = sensVarArray.elementAt(i);
        int index = jacobian.getRateIndex(sensVar.getVolVariable());
        sensVars.setElementAt(sensVar, index);
    }
    // 
    // given the system
    // 
    // 
    // d Ci
    // ------- = Fi(C1..Cn,P1..Pm)
    // d t
    // 
    // where:  C's are variables and P's are parameters
    // 
    // jacobian.show();
    VolVariable var = ((SensVariable) variable).getVolVariable();
    Constant parameter = ((SensVariable) variable).getParameter();
    // 
    // get list of jacobian expressions for this var (Ci)
    // 
    // d Fi
    // ------   for all j
    // d Cj
    // 
    optimizedJacobianExps = new Expression[jacobian.getNumRates()];
    int currIndex = jacobian.getRateIndex(var);
    for (int i = 0; i < optimizedJacobianExps.length; i++) {
        Expression exp = jacobian.getJexp(currIndex, i);
        exp.bindExpression(symbolTable);
        optimizedJacobianExps[i] = exp.flatten();
    }
    // 
    // get rate sensitivity for this variable (Ci) and the parameter under investigation (Pj)
    // 
    // d Fi
    // ------
    // d Pj
    // 
    // 
    Expression exp = rateSensitivity.getCPexp(var, parameter.getName());
    exp.bindExpression(symbolTable);
    optimizedRateSensExp = exp.flatten();
}
Also used : VolVariable(cbit.vcell.math.VolVariable) Expression(cbit.vcell.parser.Expression) Constant(cbit.vcell.math.Constant)

Example 45 with VolVariable

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

the class ModelOptimizationSpec method removeUncoupledParameters.

public void removeUncoupledParameters() {
    try {
        localIssueList.clear();
        MathMapping mathMapping = getSimulationContext().createNewMathMapping();
        MathDescription mathDesc = mathMapping.getMathDescription();
        MathSystemHash mathSystemHash = fromMath(mathDesc);
        Graph graph = mathSystemHash.getDependencyGraph(mathSystemHash.getSymbols());
        Tree[] spanningTrees = graph.getSpanningForest();
        // 
        for (int i = 0; i < spanningTrees.length; i++) {
            Node[] treeNodes = spanningTrees[i].getNodes();
            boolean bHasStateVariables = false;
            for (int j = 0; j < treeNodes.length; j++) {
                Node node = treeNodes[j];
                Variable var = mathDesc.getVariable(node.getName());
                if (var instanceof VolVariable || var instanceof MemVariable || var instanceof FilamentVariable || var instanceof VolumeRegionVariable || var instanceof MembraneRegionVariable || var instanceof FilamentRegionVariable) {
                    bHasStateVariables = true;
                    break;
                }
            }
            if (!bHasStateVariables) {
                spanningTrees = (Tree[]) BeanUtils.removeElement(spanningTrees, spanningTrees[i]);
                i--;
            }
        }
        // 
        // remove parameters not mapped to a surviving tree (not coupled to any state variables
        // 
        ArrayList<ParameterMappingSpec> paramMappingSpecsList = new ArrayList<ParameterMappingSpec>();
        paramMappingSpecsList.addAll(Arrays.asList(fieldParameterMappingSpecs));
        for (int i = 0; i < paramMappingSpecsList.size(); i++) {
            Parameter parameter = paramMappingSpecsList.get(i).getModelParameter();
            String mathName = mathMapping.getMathSymbolMapping().getVariable(parameter).getName();
            boolean bFoundInTree = false;
            for (int j = 0; j < spanningTrees.length; j++) {
                Node node = spanningTrees[j].getNode(mathName);
                if (node != null) {
                    bFoundInTree = true;
                }
            }
            if (!bFoundInTree) {
                paramMappingSpecsList.remove(i);
                i--;
            }
        }
        ParameterMappingSpec[] parameterMappingSpecs = new ParameterMappingSpec[paramMappingSpecsList.size()];
        paramMappingSpecsList.toArray(parameterMappingSpecs);
        setParameterMappingSpecs(parameterMappingSpecs);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        localIssueList.add(new Issue(this, localIssueContext, IssueCategory.ParameterEstimationGeneralWarning, e.getMessage(), Issue.SEVERITY_WARNING));
    // throw new RuntimeException(e.getMessage());
    }
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) Issue(org.vcell.util.Issue) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) MathDescription(cbit.vcell.math.MathDescription) Node(cbit.util.graph.Node) ArrayList(java.util.ArrayList) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) Tree(cbit.util.graph.Tree) VolVariable(cbit.vcell.math.VolVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) PropertyVetoException(java.beans.PropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) Graph(cbit.util.graph.Graph) FilamentVariable(cbit.vcell.math.FilamentVariable) MathMapping(cbit.vcell.mapping.MathMapping) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Aggregations

VolVariable (cbit.vcell.math.VolVariable)46 Variable (cbit.vcell.math.Variable)29 Expression (cbit.vcell.parser.Expression)25 MemVariable (cbit.vcell.math.MemVariable)24 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)19 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)17 ReservedVariable (cbit.vcell.math.ReservedVariable)16 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)15 Constant (cbit.vcell.math.Constant)14 FilamentVariable (cbit.vcell.math.FilamentVariable)13 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)13 Vector (java.util.Vector)13 Function (cbit.vcell.math.Function)12 MathDescription (cbit.vcell.math.MathDescription)11 SubDomain (cbit.vcell.math.SubDomain)11 Equation (cbit.vcell.math.Equation)10 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)10 MathException (cbit.vcell.math.MathException)10 OdeEquation (cbit.vcell.math.OdeEquation)10 Domain (cbit.vcell.math.Variable.Domain)10