Search in sources :

Example 26 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class SimulationWarning method analyzeDiffusion.

/**
 * make sure diffusion expressions are constants, store for later use
 * @throws ExpressionException
 */
private static Map<MembraneSubDomain, List<DiffusionValue>> analyzeDiffusion(Simulation simulation, double timeStep, IssueContext issueContext, List<Issue> issueList) throws ExpressionException {
    Map<MembraneSubDomain, List<DiffusionValue>> diffusionValuesMap = new IdentityHashMap<>();
    diffusionValuesMap.clear();
    MutableDouble value = new MutableDouble();
    MathDescription cm = simulation.getMathDescription();
    Objects.requireNonNull(cm);
    MathDescription localMath = new MathDescription(cm);
    SimulationSymbolTable symTable = new SimulationSymbolTable(simulation, 0);
    Map<MembraneSubDomain, List<DiffusionValue>> dvMap = new HashMap<>();
    double maxDiffValue = Double.MIN_VALUE;
    List<DiffusionValue> diffusionList = new ArrayList<>();
    for (SubDomain sd : localMath.getSubDomainCollection()) {
        final boolean isMembrane = sd instanceof MembraneSubDomain;
        diffusionList.clear();
        for (ParticleProperties pp : sd.getParticleProperties()) {
            String name = pp.getVariable().getName();
            Expression diffExp = pp.getDiffusion();
            Expression flattened = MathUtilities.substituteFunctions(diffExp, symTable).flatten();
            if (isConstant(flattened, value)) {
                if (isMembrane) {
                    DiffusionValue dv = new DiffusionValue(name, value.doubleValue());
                    maxDiffValue = Math.max(maxDiffValue, dv.value);
                    diffusionList.add(dv);
                }
            } else {
                String s = "Smoldyn only supports constant diffusion, " + name + " is variable";
                Issue i = new Issue(simulation, issueContext, IssueCategory.SMOLYDN_DIFFUSION, s, s, Severity.ERROR);
                issueList.add(i);
            }
        }
        if (isMembrane && !diffusionList.isEmpty()) {
            dvMap.put((MembraneSubDomain) sd, diffusionList);
        }
    }
    diffusionValuesMap.putAll(dvMap);
    MeshSpecification ms = simulation.getMeshSpecification();
    Geometry g = ms.getGeometry();
    int dim = g.getDimension();
    double minDelta = Double.MAX_VALUE;
    switch(dim) {
        case 3:
            minDelta = Math.min(minDelta, ms.getDz(true));
        // fall-through
        case 2:
            minDelta = Math.min(minDelta, ms.getDy(true));
        // fall-through
        case 1:
            minDelta = Math.min(minDelta, ms.getDx(true));
            break;
        default:
            throw new RuntimeException("Invalid dimension " + dim + " for smoldyn solver");
    }
    double minArea = minDelta * minDelta / 2;
    double limit = PRECHECK_LIMIT_ADJUST * minArea / maxDiffValue;
    boolean warn = (timeStep > limit);
    if (lg.isDebugEnabled()) {
        lg.debug("Min delta " + minDelta + ", min area " + minArea + " time limit " + limit + " timeStep " + timeStep + " -> warn = " + warn);
    }
    if (warn) {
        String s = "Time step " + timeStep + " may be too large, performing further analysis ...";
        Issue i = new Issue(simulation, issueContext, IssueCategory.SMOLYDN_DIFFUSION, s, s, Severity.WARNING);
        issueList.add(i);
    }
    lg.debug("end of diffusion analysis");
    return diffusionValuesMap;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Issue(org.vcell.util.Issue) MathDescription(cbit.vcell.math.MathDescription) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Geometry(cbit.vcell.geometry.Geometry) Expression(cbit.vcell.parser.Expression) ArrayList(java.util.ArrayList) List(java.util.List) ParticleProperties(cbit.vcell.math.ParticleProperties)

Example 27 with Geometry

use of cbit.vcell.geometry.Geometry 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 28 with Geometry

use of cbit.vcell.geometry.Geometry 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 29 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class MeshSpecification method setGeometry.

/**
 * Sets the geometry property (cbit.vcell.geometry.Geometry) value.
 * @param geometry The new value for the property.
 * @see #getGeometry
 */
public void setGeometry(Geometry geometry) {
    Geometry oldGeometry = fieldGeometry;
    fieldGeometry = geometry;
    firePropertyChange("geometry", oldGeometry, fieldGeometry);
    if (oldGeometry == null || fieldGeometry.getDimension() != oldGeometry.getDimension()) {
        resetSamplingSize();
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry)

Example 30 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class OptimizationService method updateMath.

private static void updateMath(SimulationContext simulationContext, final NetworkGenerationRequirements networkGenerationRequirements) throws Exception {
    Geometry geometry = simulationContext.getGeometry();
    if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
        geometry.getGeometrySurfaceDescription().updateAll();
    }
    simulationContext.checkValidity();
    MathMapping mathMapping = simulationContext.createNewMathMapping(callback, networkGenerationRequirements);
    MathDescription mathDesc = mathMapping.getMathDescription(callback);
    callback.setProgressFraction(1.0f / 3.0f * 2.0f);
    if (mathDesc != null) {
        simulationContext.setMathDescription(mathDesc);
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) MathDescription(cbit.vcell.math.MathDescription) MathMapping(cbit.vcell.mapping.MathMapping)

Aggregations

Geometry (cbit.vcell.geometry.Geometry)121 MathDescription (cbit.vcell.math.MathDescription)32 SimulationContext (cbit.vcell.mapping.SimulationContext)31 Simulation (cbit.vcell.solver.Simulation)29 PropertyVetoException (java.beans.PropertyVetoException)24 BioModel (cbit.vcell.biomodel.BioModel)23 DataAccessException (org.vcell.util.DataAccessException)23 VCImage (cbit.image.VCImage)22 SubVolume (cbit.vcell.geometry.SubVolume)21 MathModel (cbit.vcell.mathmodel.MathModel)21 Expression (cbit.vcell.parser.Expression)19 ISize (org.vcell.util.ISize)19 Hashtable (java.util.Hashtable)18 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)17 UserCancelException (org.vcell.util.UserCancelException)17 KeyValue (org.vcell.util.document.KeyValue)17 ImageException (cbit.image.ImageException)16 Extent (org.vcell.util.Extent)16 SurfaceClass (cbit.vcell.geometry.SurfaceClass)15 ExpressionException (cbit.vcell.parser.ExpressionException)15