Search in sources :

Example 46 with Constant

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

the class XmlReader method getSolverTaskDescription.

/**
 * This method returns a SolverTaskDescription Object from a XML Element.
 * Creation date: (5/22/2001 10:51:23 AM)
 * @return cbit.vcell.solver.SolverTaskDescription
 * @param param org.jdom.Element
 * @param simulation cbit.vcell.solver.Simulation
 */
private SolverTaskDescription getSolverTaskDescription(Element param, Simulation simulation) throws XmlParseException {
    // *** create new SolverTaskDescription ***
    SolverTaskDescription solverTaskDesc = new SolverTaskDescription(simulation);
    // Added July 22nd, 2007, used as condition for stochSimOptions or stochHybridOprtions
    SolverDescription sd = null;
    // Retrieve attributes
    String taskType = param.getAttributeValue(XMLTags.TaskTypeTag);
    int keepEvery = -1;
    int keepAtMost = -1;
    if (param.getAttributeValue(XMLTags.KeepEveryTag) != null) {
        keepEvery = Integer.parseInt(param.getAttributeValue(XMLTags.KeepEveryTag));
        keepAtMost = Integer.parseInt(param.getAttributeValue(XMLTags.KeepAtMostTag));
    }
    boolean useSymJacob = new Boolean(param.getAttributeValue(XMLTags.UseSymbolicJacobianAttrTag)).booleanValue();
    String solverName = param.getAttributeValue(XMLTags.SolverNameTag);
    // get sentivity parameter
    Element sensparamElement = param.getChild(XMLTags.ConstantTag, vcNamespace);
    Constant sensitivityparam = null;
    if (sensparamElement != null) {
        sensitivityparam = getConstant(sensparamElement);
    }
    // set Attributes
    try {
        // set solver
        sd = SolverDescription.fromDatabaseName(solverName);
        if (sd == null) {
            System.err.println("====================================== couldn't find solver description name ==========================================");
        }
        solverTaskDesc.setSolverDescription(sd);
        if (taskType.equalsIgnoreCase(XMLTags.UnsteadyTag)) {
            solverTaskDesc.setTaskType(SolverTaskDescription.TASK_UNSTEADY);
        } else if (taskType.equalsIgnoreCase(XMLTags.SteadyTag)) {
            solverTaskDesc.setTaskType(SolverTaskDescription.TASK_STEADY);
        } else {
            throw new XmlParseException("Unexpected task type: " + taskType);
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("A PropertyVetoException was fired when setting the taskType: " + taskType, e);
    }
    int numProcessors = parseIntWithDefault(param, XMLTags.NUM_PROCESSORS, 1);
    try {
        solverTaskDesc.setNumProcessors(numProcessors);
        solverTaskDesc.setUseSymbolicJacobian(useSymJacob);
        // get TimeBound
        solverTaskDesc.setTimeBounds(getTimeBounds(param.getChild(XMLTags.TimeBoundTag, vcNamespace)));
        // get TimeStep
        solverTaskDesc.setTimeStep(getTimeStep(param.getChild(XMLTags.TimeStepTag, vcNamespace)));
        // get ErrorTolerance
        solverTaskDesc.setErrorTolerance(getErrorTolerance(param.getChild(XMLTags.ErrorToleranceTag, vcNamespace)));
        // get StochSimOptions
        if (simulation != null && simulation.getMathDescription() != null) {
            if (simulation.getMathDescription().isNonSpatialStoch() && param.getChild(XMLTags.StochSimOptionsTag, vcNamespace) != null) {
                // Amended July 22nd, 2007 to read either stochSimOptions or stochHybridOptions
                solverTaskDesc.setStochOpt(getStochSimOptions(param.getChild(XMLTags.StochSimOptionsTag, vcNamespace)));
                if (sd != null && !sd.equals(SolverDescription.StochGibson)) {
                    solverTaskDesc.setStochHybridOpt(getStochHybridOptions(param.getChild(XMLTags.StochSimOptionsTag, vcNamespace)));
                }
            }
        }
        // get OutputOptions
        if (keepEvery != -1) {
            solverTaskDesc.setOutputTimeSpec(new DefaultOutputTimeSpec(keepEvery, keepAtMost));
        }
        OutputTimeSpec ots = getOutputTimeSpec(param.getChild(XMLTags.OutputOptionsTag, vcNamespace));
        if (ots != null) {
            solverTaskDesc.setOutputTimeSpec(getOutputTimeSpec(param.getChild(XMLTags.OutputOptionsTag, vcNamespace)));
        }
        // set SensitivityParameter
        solverTaskDesc.setSensitivityParameter(sensitivityparam);
        // set StopAtSpatiallyUniform
        Element stopSpatiallyElement = param.getChild(XMLTags.StopAtSpatiallyUniform, vcNamespace);
        if (stopSpatiallyElement != null) {
            Element errTolElement = stopSpatiallyElement.getChild(XMLTags.ErrorToleranceTag, vcNamespace);
            if (errTolElement != null) {
                solverTaskDesc.setStopAtSpatiallyUniformErrorTolerance(getErrorTolerance(errTolElement));
            }
        }
        String runParameterScanSeriallyAttributeValue = param.getAttributeValue(XMLTags.RunParameterScanSerially);
        if (runParameterScanSeriallyAttributeValue != null) {
            solverTaskDesc.setSerialParameterScan(new Boolean(runParameterScanSeriallyAttributeValue).booleanValue());
        }
        Element nfsimSimulationOptionsElement = param.getChild(XMLTags.NFSimSimulationOptions, vcNamespace);
        if (nfsimSimulationOptionsElement != null) {
            NFsimSimulationOptions nfsimSimulationOptions = getNFSimSimulationOptions(nfsimSimulationOptionsElement);
            solverTaskDesc.setNFSimSimulationOptions(nfsimSimulationOptions);
        }
        Element smoldySimulationOptionsElement = param.getChild(XMLTags.SmoldynSimulationOptions, vcNamespace);
        if (smoldySimulationOptionsElement != null) {
            SmoldynSimulationOptions smoldynSimulationOptions = getSmoldySimulationOptions(smoldySimulationOptionsElement);
            solverTaskDesc.setSmoldynSimulationOptions(smoldynSimulationOptions);
        }
        Element sundialsPdeSolverOptionsElement = param.getChild(XMLTags.SundialsSolverOptions, vcNamespace);
        if (sundialsPdeSolverOptionsElement != null) {
            SundialsPdeSolverOptions sundialsPdeSolverOptions = getSundialsPdeSolverOptions(sundialsPdeSolverOptionsElement);
            solverTaskDesc.setSundialsPdeSolverOptions(sundialsPdeSolverOptions);
        }
        Element chomboElement = param.getChild(XMLTags.ChomboSolverSpec, vcNamespace);
        if (chomboElement != null) {
            ChomboSolverSpec chombo = getChomboSolverSpec(solverTaskDesc, chomboElement, simulation.getMathDescription().getGeometry().getDimension());
            solverTaskDesc.setChomboSolverSpec(chombo);
        }
        Element mbElement = param.getChild(XMLTags.MovingBoundarySolverOptionsTag, vcNamespace);
        if (mbElement != null) {
            MovingBoundarySolverOptions mb = getMovingBoundarySolverOptions(solverTaskDesc, mbElement);
            solverTaskDesc.setMovingBoundarySolverOptions(mb);
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException(e);
    }
    return solverTaskDesc;
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) SolverDescription(cbit.vcell.solver.SolverDescription) MovingBoundarySolverOptions(cbit.vcell.solvers.mb.MovingBoundarySolverOptions) SundialsPdeSolverOptions(cbit.vcell.solver.SundialsPdeSolverOptions) MacroscopicRateConstant(cbit.vcell.math.MacroscopicRateConstant) Constant(cbit.vcell.math.Constant) Element(org.jdom.Element) ChomboSolverSpec(org.vcell.chombo.ChomboSolverSpec) PropertyVetoException(java.beans.PropertyVetoException) SmoldynSimulationOptions(cbit.vcell.solver.SmoldynSimulationOptions) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 47 with Constant

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

the class XmlReader method getConstant.

/**
 * This method returns a Constant object from a XML element.
 * Creation date: (5/16/2001 1:50:07 PM)
 * @return cbit.vcell.math.Constant
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private Constant getConstant(Element param) throws XmlParseException {
    // retrieve values
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    Expression exp = unMangleExpression(param.getText());
    // -- create new constant object ---
    Constant newconstant = new Constant(name, exp);
    transcribeComments(param, newconstant);
    return newconstant;
}
Also used : Expression(cbit.vcell.parser.Expression) MacroscopicRateConstant(cbit.vcell.math.MacroscopicRateConstant) Constant(cbit.vcell.math.Constant)

Example 48 with Constant

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

the class XmlReader method addResevedSymbols.

/**
 * This method returns a Kinetics object from a XML Element based on the value of the kinetics type attribute.
 * Creation date: (3/19/2001 4:42:04 PM)
 * @return cbit.vcell.model.Kinetics
 * @param param org.jdom.Element
 */
private void addResevedSymbols(VariableHash varHash, Model model) throws XmlParseException {
    // 
    try {
        // add reserved symbols
        varHash.addVariable(new Constant(model.getPI_CONSTANT().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getFARADAY_CONSTANT().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getFARADAY_CONSTANT_NMOLE().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getGAS_CONSTANT().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getKMILLIVOLTS().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getN_PMOLE().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getKMOLE().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getTEMPERATURE().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getK_GHK().getName(), new Expression(0.0)));
        varHash.addVariable(new Constant(model.getTIME().getName(), new Expression(0.0)));
    } catch (MathException e) {
        e.printStackTrace(System.out);
        throw new XmlParseException("error reordering parameters according to dependencies", e);
    }
}
Also used : Expression(cbit.vcell.parser.Expression) MacroscopicRateConstant(cbit.vcell.math.MacroscopicRateConstant) Constant(cbit.vcell.math.Constant) MathException(cbit.vcell.math.MathException)

Example 49 with Constant

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

the class SimulationRepresentation method getParameters.

private static ParameterRepresentation[] getParameters(BioModel bioModel, SimulationRep simulationRep) {
    SimulationContext simContext = null;
    for (SimulationContext sc : bioModel.getSimulationContexts()) {
        if (sc.getMathDescription().getKey().equals(simulationRep.getMathKey())) {
            simContext = sc;
            break;
        }
    }
    if (simContext == null) {
        return null;
    }
    // initialize to old mathDescription in case error generating math
    MathDescription mathDesc = simContext.getMathDescription();
    MathMapping mathMapping = simContext.createNewMathMapping();
    MathSymbolMapping mathSymbolMapping = null;
    try {
        mathDesc = mathMapping.getMathDescription();
        mathSymbolMapping = mathMapping.getMathSymbolMapping();
    } catch (Exception e1) {
        System.err.println(e1.getMessage());
    }
    ArrayList<ParameterRepresentation> parameterReps = new ArrayList<ParameterRepresentation>();
    Enumeration<Constant> enumMath = mathDesc.getConstants();
    while (enumMath.hasMoreElements()) {
        Constant constant = enumMath.nextElement();
        if (constant.getExpression().isNumeric()) {
            SymbolTableEntry biologicalSymbolTableEntry = null;
            if (mathSymbolMapping != null) {
                SymbolTableEntry[] stes = mathSymbolMapping.getBiologicalSymbol(constant);
                if (stes != null && stes.length >= 1) {
                    biologicalSymbolTableEntry = stes[0];
                }
            }
            if (biologicalSymbolTableEntry instanceof ReservedSymbol) {
                continue;
            }
            try {
                parameterReps.add(new ParameterRepresentation(constant.getName(), constant.getExpression().evaluateConstant(), biologicalSymbolTableEntry));
            } catch (ExpressionException e) {
                // can't happen, because constant expression is numeric
                e.printStackTrace();
            }
        }
    }
    return parameterReps.toArray(new ParameterRepresentation[0]);
}
Also used : MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ArrayList(java.util.ArrayList) SimulationContext(cbit.vcell.mapping.SimulationContext) MathSymbolMapping(cbit.vcell.mapping.MathSymbolMapping) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MatrixException(cbit.vcell.matrix.MatrixException) MathException(cbit.vcell.math.MathException) ModelException(cbit.vcell.model.ModelException) ExpressionException(cbit.vcell.parser.ExpressionException) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) MathMapping(cbit.vcell.mapping.MathMapping)

Example 50 with Constant

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

the class ConstantArraySpec method createListSpec.

/**
 * Insert the method's description here.
 * Creation date: (9/23/2005 1:33:00 PM)
 * @return cbit.vcell.solver.ConstantArraySpec
 */
public static ConstantArraySpec createListSpec(String name, String[] values) throws cbit.vcell.parser.ExpressionException {
    if (values.length < 2)
        throw new RuntimeException("List must contain at least two values");
    ConstantArraySpec spec = new ConstantArraySpec();
    spec.type = TYPE_LIST;
    spec.name = name;
    spec.constants = new Constant[values.length];
    spec.numValues = values.length;
    for (int i = 0; i < values.length; i++) {
        spec.constants[i] = new Constant(name, new cbit.vcell.parser.Expression(values[i]));
    }
    return spec;
}
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