Search in sources :

Example 31 with MathDescription

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

the class XmlHelper method XMLToSim.

public static Simulation XMLToSim(String xmlString) throws XmlParseException {
    Simulation sim = null;
    Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
    try {
        if (xmlString == null || xmlString.length() == 0) {
            throw new XmlParseException("Invalid xml for Simulation: " + xmlString);
        }
        // default parser and no validation
        Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
        Element simElement = root.getChild(XMLTags.SimulationTag, ns);
        Element mdElement = root.getChild(XMLTags.MathDescriptionTag, ns);
        Element geomElement = root.getChild(XMLTags.GeometryTag, ns);
        XmlReader reader = new XmlReader(true, ns);
        Geometry geom = null;
        if (geomElement != null) {
            geom = reader.getGeometry(geomElement);
        }
        MathDescription md = reader.getMathDescription(mdElement, geom);
        sim = reader.getSimulation(simElement, md);
    } catch (Exception pve) {
        pve.printStackTrace();
        throw new XmlParseException("Unable to parse simulation string.", pve);
    }
    sim.refreshDependencies();
    return sim;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) MathDescription(cbit.vcell.math.MathDescription) Element(org.jdom.Element) Namespace(org.jdom.Namespace) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 32 with MathDescription

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

the class XmlHelper method XMLToSimTask.

public static SimulationTask XMLToSimTask(String xmlString) throws XmlParseException, ExpressionException {
    Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
    try {
        if (xmlString == null || xmlString.length() == 0) {
            throw new XmlParseException("Invalid xml for Simulation: " + xmlString);
        }
        // default parser and no validation
        Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
        if (!root.getName().equals(SimulationTask_tag)) {
            throw new RuntimeException("expecting top level element to be " + SimulationTask_tag);
        }
        int taskId = Integer.parseInt(root.getAttributeValue(TaskId_attr));
        int jobIndex = Integer.parseInt(root.getAttributeValue(JobIndex_attr));
        String computeResource = root.getChildTextTrim(ComputeResource_tag, ns);
        List<?> children = root.getChildren(FieldFunctionIdentifierSpec_tag, ns);
        ArrayList<FieldDataIdentifierSpec> fdisArrayList = new ArrayList<FieldDataIdentifierSpec>();
        for (Object child : children) {
            if (child instanceof Element) {
                String fdisText = ((Element) child).getTextTrim();
                FieldDataIdentifierSpec fdis = FieldDataIdentifierSpec.fromCSVString(fdisText);
                fdisArrayList.add(fdis);
            }
        }
        FieldDataIdentifierSpec[] fdisArray = fdisArrayList.toArray(new FieldDataIdentifierSpec[0]);
        Element simElement = root.getChild(XMLTags.SimulationTag, ns);
        Element mdElement = root.getChild(XMLTags.MathDescriptionTag, ns);
        Element geomElement = root.getChild(XMLTags.GeometryTag, ns);
        XmlReader reader = new XmlReader(true, ns);
        Geometry geom = null;
        if (geomElement != null) {
            geom = reader.getGeometry(geomElement);
        }
        MathDescription md = reader.getMathDescription(mdElement, geom);
        Simulation sim = reader.getSimulation(simElement, md);
        sim.refreshDependencies();
        SimulationJob simJob = new SimulationJob(sim, jobIndex, fdisArray);
        SimulationTask simTask = new SimulationTask(simJob, taskId, computeResource);
        return simTask;
    } catch (Exception pve) {
        pve.printStackTrace();
        throw new XmlParseException("Unable to parse simulation string.", pve);
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) MathDescription(cbit.vcell.math.MathDescription) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Namespace(org.jdom.Namespace) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 33 with MathDescription

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

the class OutputFunctionContext method getAutoCompleteSymbolFilter.

public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter() {
    AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {

        public boolean accept(SymbolTableEntry ste) {
            MathDescription math = getSimulationOwner().getMathDescription();
            Variable var = math.getVariable(ste.getName());
            return (!(var instanceof InsideVariable || var instanceof OutsideVariable));
        }

        public boolean acceptFunction(String funcName) {
            return true;
        }
    };
    return stef;
}
Also used : AutoCompleteSymbolFilter(cbit.vcell.parser.AutoCompleteSymbolFilter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) OutsideVariable(cbit.vcell.math.OutsideVariable) InsideVariable(cbit.vcell.math.InsideVariable)

Example 34 with MathDescription

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

the class OutputFunctionContext method getEntries.

// public abstract void validateNamingConflicts(String symbolDescription, Class<?> newSymbolClass, String newSymbolName, PropertyChangeEvent e)  throws PropertyVetoException ;
public void getEntries(Map<String, SymbolTableEntry> entryMap) {
    // add all valid entries (variables) from mathdescription
    MathDescription mathDescription = simulationOwner.getMathDescription();
    if (mathDescription != null) {
        Enumeration<Variable> varEnum = mathDescription.getVariables();
        while (varEnum.hasMoreElements()) {
            Variable var = varEnum.nextElement();
            if (!(var instanceof PseudoConstant) && !(var instanceof Constant)) {
                entryMap.put(var.getName(), var);
            }
        }
        for (DataGenerator dataGenerator : mathDescription.getPostProcessingBlock().getDataGeneratorList()) {
            entryMap.put(dataGenerator.getName(), dataGenerator);
        }
    }
    entryMap.put(ReservedVariable.TIME.getName(), ReservedVariable.TIME);
    int dimension = mathDescription.getGeometry().getDimension();
    if (dimension > 0) {
        entryMap.put(ReservedVariable.X.getName(), ReservedVariable.X);
        if (dimension > 1) {
            entryMap.put(ReservedVariable.Y.getName(), ReservedVariable.Y);
            if (dimension > 2) {
                entryMap.put(ReservedVariable.Z.getName(), ReservedVariable.Z);
            }
        }
    }
    // then add list of output functions.
    for (SymbolTableEntry ste : outputFunctionsList) {
        entryMap.put(ste.getName(), ste);
    }
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) PseudoConstant(cbit.vcell.math.PseudoConstant) PseudoConstant(cbit.vcell.math.PseudoConstant) DataGenerator(cbit.vcell.math.DataGenerator)

Example 35 with MathDescription

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

the class OutputFunctionContext method computeFunctionTypeWRTExpression.

// check if the new expression is valid for outputFunction of functionType
public VariableType computeFunctionTypeWRTExpression(AnnotatedFunction outputFunction, Expression exp) throws ExpressionException, InconsistentDomainException {
    MathDescription mathDescription = getSimulationOwner().getMathDescription();
    boolean bSpatial = getSimulationOwner().getGeometry().getDimension() > 0;
    if (!bSpatial) {
        return VariableType.NONSPATIAL;
    }
    Expression newexp = new Expression(exp);
    // making sure that output function is not direct function of constant.
    newexp.bindExpression(this);
    // here use math description as symbol table because we allow
    // new expression itself to be function of constant.
    newexp = MathUtilities.substituteFunctions(newexp, this).flatten();
    String[] symbols = newexp.getSymbols();
    VariableType functionType = outputFunction.getFunctionType();
    String funcName = outputFunction.getName();
    Domain funcDomain = outputFunction.getDomain();
    VariableType[] varTypes = null;
    if (symbols != null && symbols.length > 0) {
        // making sure that new expression is defined in the same domain
        varTypes = new VariableType[symbols.length];
        for (int i = 0; i < symbols.length; i++) {
            if (ReservedMathSymbolEntries.getReservedVariableEntry(symbols[i]) != null) {
                varTypes[i] = functionType;
            } else {
                Variable var = mathDescription.getVariable(symbols[i]);
                if (var == null) {
                    var = mathDescription.getPostProcessingBlock().getDataGenerator(symbols[i]);
                }
                varTypes[i] = VariableType.getVariableType(var);
                if (funcDomain != null) {
                    if (var.getDomain() == null) {
                        // OK
                        continue;
                    }
                    GeometryClass funcGeoClass = simulationOwner.getGeometry().getGeometryClass(funcDomain.getName());
                    GeometryClass varGeoClass = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
                    if (varGeoClass instanceof SubVolume && funcGeoClass instanceof SurfaceClass) {
                        // seems ok if membrane refereces volume
                        if (!((SurfaceClass) funcGeoClass).isAdjacentTo((SubVolume) varGeoClass)) {
                            // but has to be adjacent
                            String errMsg = "'" + funcName + "' defined on Membrane '" + funcDomain.getName() + "' directly or indirectly references " + " variable '" + symbols[i] + "' defined on Volume '" + var.getDomain().getName() + " which is not adjacent to Membrane '" + funcDomain.getName() + "'.";
                            throw new ExpressionException(errMsg);
                        }
                    } else if (!var.getDomain().compareEqual(funcDomain)) {
                        String errMsg = "'" + funcName + "' defined on '" + funcDomain.getName() + "' directly or indirectly references " + " variable '" + symbols[i] + "' defined on '" + var.getDomain().getName() + ".";
                        throw new ExpressionException(errMsg);
                    }
                }
            }
        }
    }
    // if there are no variables (like built in function, vcRegionArea), check with flattened expression to find out the variable type of the new expression
    VariableDomain functionVariableDomain = functionType.getVariableDomain();
    Function flattenedFunction = new Function(funcName, newexp, funcDomain);
    flattenedFunction.bind(this);
    VariableType newVarType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, getSimulationOwner().getMathDescription(), symbols, varTypes, bSpatial);
    if (!newVarType.getVariableDomain().equals(functionVariableDomain)) {
        String errMsg = "The expression for '" + funcName + "' includes at least one " + newVarType.getVariableDomain().getName() + " variable. Please make sure that only " + functionVariableDomain.getName() + " variables are " + "referenced in " + functionVariableDomain.getName() + " output functions.";
        throw new ExpressionException(errMsg);
    }
    return newVarType;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) VariableType(cbit.vcell.math.VariableType) MathDescription(cbit.vcell.math.MathDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ExpressionException(cbit.vcell.parser.ExpressionException) Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) SubVolume(cbit.vcell.geometry.SubVolume) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) Domain(cbit.vcell.math.Variable.Domain)

Aggregations

MathDescription (cbit.vcell.math.MathDescription)120 Simulation (cbit.vcell.solver.Simulation)48 Geometry (cbit.vcell.geometry.Geometry)32 SimulationContext (cbit.vcell.mapping.SimulationContext)32 Variable (cbit.vcell.math.Variable)32 Expression (cbit.vcell.parser.Expression)30 ExpressionException (cbit.vcell.parser.ExpressionException)27 PropertyVetoException (java.beans.PropertyVetoException)25 BioModel (cbit.vcell.biomodel.BioModel)24 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)22 Constant (cbit.vcell.math.Constant)22 MathException (cbit.vcell.math.MathException)21 MathModel (cbit.vcell.mathmodel.MathModel)21 KeyValue (org.vcell.util.document.KeyValue)20 SubDomain (cbit.vcell.math.SubDomain)19 ArrayList (java.util.ArrayList)18 SubVolume (cbit.vcell.geometry.SubVolume)17 Model (cbit.vcell.model.Model)17 DataAccessException (org.vcell.util.DataAccessException)17 Function (cbit.vcell.math.Function)15