Search in sources :

Example 56 with MathException

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

the class XmlReader method getMembraneSubDomain.

/**
 * This method returns a MembraneSubDomain object from a XML Element.
 * Creation date: (5/18/2001 4:23:30 PM)
 * @return cbit.vcell.math.MembraneSubDomain
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
@SuppressWarnings("unchecked")
private MembraneSubDomain getMembraneSubDomain(Element param, MathDescription mathDesc) throws XmlParseException {
    // no need to do anything with the 'Name' attribute : constructor of MembraneSubDomain creates name from inside/outside compartmentSubDomains.
    // String msdName = unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
    // if ( msdName != null) {
    // }
    // get compartmentSubDomain references
    // inside
    String name = unMangle(param.getAttributeValue(XMLTags.InsideCompartmentTag));
    CompartmentSubDomain insideRef = (CompartmentSubDomain) mathDesc.getCompartmentSubDomain(name);
    if (insideRef == null) {
        throw new XmlParseException("The reference to the inside CompartmentSubDomain " + name + ", could not be resolved!");
    }
    // outside
    name = unMangle(param.getAttributeValue(XMLTags.OutsideCompartmentTag));
    CompartmentSubDomain outsideRef = (CompartmentSubDomain) mathDesc.getCompartmentSubDomain(name);
    if (outsideRef == null) {
        throw new XmlParseException("The reference to the outside CompartmentSubDomain " + name + ", could not be resolved!");
    }
    // *** create new Membrane SubDomain ***
    SubVolume insideSubVolume = mathDesc.getGeometry().getGeometrySpec().getSubVolume(insideRef.getName());
    SubVolume outsideSubVolume = mathDesc.getGeometry().getGeometrySpec().getSubVolume(outsideRef.getName());
    SurfaceClass surfaceClass = mathDesc.getGeometry().getGeometrySurfaceDescription().getSurfaceClass(insideSubVolume, outsideSubVolume);
    MembraneSubDomain subDomain = new MembraneSubDomain(insideRef, outsideRef, surfaceClass.getName());
    transcribeComments(param, subDomain);
    // Process BoundaryConditions
    Iterator<Element> iterator = param.getChildren(XMLTags.BoundaryTypeTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempelement = (Element) iterator.next();
        // create BoundaryConditionType
        String temp = tempelement.getAttributeValue(XMLTags.BoundaryTypeAttrTag);
        BoundaryConditionType bType = new BoundaryConditionType(temp);
        // Process Xm
        if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueXm)) {
            subDomain.setBoundaryConditionXm(bType);
        } else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueXp)) {
            // Process Xp
            subDomain.setBoundaryConditionXp(bType);
        } else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueYm)) {
            // Process Ym
            subDomain.setBoundaryConditionYm(bType);
        } else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueYp)) {
            // Process Yp
            subDomain.setBoundaryConditionYp(bType);
        } else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueZm)) {
            // Process Zm
            subDomain.setBoundaryConditionZm(bType);
        } else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueZp)) {
            // Process Zp
            subDomain.setBoundaryConditionZp(bType);
        } else {
            // If not indentified throw an exception!!
            throw new XmlParseException("Unknown BoundaryConditionType: " + tempelement.getAttributeValue(XMLTags.BoundaryAttrTag));
        }
    }
    // Add OdeEquations
    iterator = param.getChildren(XMLTags.OdeEquationTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempElement = (Element) iterator.next();
        OdeEquation odeEquation = getOdeEquation(tempElement, mathDesc);
        try {
            subDomain.addEquation(odeEquation);
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding an OdeEquation to a MembraneSubDomain!", e);
        }
    }
    // process PdeEquations
    iterator = param.getChildren(XMLTags.PdeEquationTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempElement = (Element) iterator.next();
        try {
            subDomain.addEquation(getPdeEquation(tempElement, mathDesc));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding an PdeEquation to the MembraneSubDomain " + name, e);
        }
    }
    // Add JumpConditions
    iterator = param.getChildren(XMLTags.JumpConditionTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempElement = (Element) iterator.next();
        try {
            subDomain.addJumpCondition(getJumpCondition(tempElement, mathDesc));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding a JumpCondition to a MembraneSubDomain!", e);
        }
    }
    // Add the FastSystem (if any)
    Element tempElement = param.getChild(XMLTags.FastSystemTag, vcNamespace);
    if (tempElement != null) {
        subDomain.setFastSystem(getFastSystem(tempElement, mathDesc));
    }
    // add MembraneRegionEquation
    iterator = param.getChildren(XMLTags.MembraneRegionEquationTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempElement = (Element) iterator.next();
        try {
            subDomain.addEquation(getMembraneRegionEquation(tempElement, mathDesc));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding a MembraneRegionEquation to a MEmbraneSubDomain!", e);
        }
    }
    iterator = param.getChildren(XMLTags.ParticleJumpProcessTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempelement = (Element) iterator.next();
        try {
            subDomain.addParticleJumpProcess(getParticleJumpProcess(tempelement, mathDesc));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding a jump process to the MembraneSubDomain " + name, e);
        }
    }
    iterator = param.getChildren(XMLTags.ParticlePropertiesTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempelement = (Element) iterator.next();
        try {
            subDomain.addParticleProperties(getParticleProperties(tempelement, mathDesc));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding a jump process to the MembraneSubDomain " + name, e);
        }
    }
    // process ComputeNormal "equations"
    iterator = param.getChildren(XMLTags.ComputeNormalTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempelement = (Element) iterator.next();
        try {
            subDomain.addEquation(getComputeNormal(tempelement, mathDesc));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("A MathException was fired when adding an ComputeNormal 'equation' to the MembraneSubDomain " + name, e);
        }
    }
    Element velElem = param.getChild(XMLTags.VelocityTag, vcNamespace);
    setMembraneSubdomainVelocity(velElem, XMLTags.XAttrTag, subDomain::setVelocityX);
    setMembraneSubdomainVelocity(velElem, XMLTags.YAttrTag, subDomain::setVelocityY);
    return subDomain;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) OdeEquation(cbit.vcell.math.OdeEquation) SurfaceClass(cbit.vcell.geometry.SurfaceClass) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) MathException(cbit.vcell.math.MathException) Element(org.jdom.Element) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType)

Example 57 with MathException

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

the class XmlReader method getPdeEquation.

/**
 * This method returns a PdeEquation from a XML element.
 * Creation date: (4/26/2001 12:11:14 PM)
 * @return cbit.vcell.math.PdeEquation
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private PdeEquation getPdeEquation(Element param, MathDescription mathDesc) throws XmlParseException {
    // Retrieve the variable reference
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    boolean bSteady = false;
    String bSteadyAttr = param.getAttributeValue(XMLTags.SteadyTag);
    if (bSteadyAttr != null && bSteadyAttr.equals("1")) {
        bSteady = true;
    }
    Variable varref = mathDesc.getVariable(name);
    if (varref == null) {
        throw new XmlParseException("The variable " + name + " for a PdeEquation, could not be resolved!");
    }
    PdeEquation pdeEquation = null;
    try {
        // Retrieve the initial expression
        String temp = param.getChildText(XMLTags.InitialTag, vcNamespace);
        Expression initialExp = null;
        if (temp != null && temp.length() > 0) {
            initialExp = unMangleExpression(temp);
        }
        // Retrieve the Rate Expression
        temp = param.getChildText(XMLTags.RateTag, vcNamespace);
        Expression rateExp = null;
        if (temp != null && temp.length() > 0) {
            rateExp = unMangleExpression(temp);
        }
        // Retrieve the diffusion rate expression
        temp = param.getChildText(XMLTags.DiffusionTag, vcNamespace);
        Expression difExp = null;
        if (temp != null && temp.length() > 0) {
            difExp = unMangleExpression(temp);
        }
        // *** Create new PdeEquation object ****
        pdeEquation = new PdeEquation(varref, bSteady, initialExp, rateExp, difExp);
        // ***** *****
        // add specific solutions expressions
        String solType = param.getAttributeValue(XMLTags.SolutionTypeTag);
        if (solType.equalsIgnoreCase(XMLTags.ExactTypeTag)) {
            String solutionExp = param.getChildText(XMLTags.SolutionExpressionTag, vcNamespace);
            if (solutionExp != null && solutionExp.length() > 0) {
                Expression expression = unMangleExpression(solutionExp);
                pdeEquation.setExactSolution(expression);
            }
        }
        // Retrieve Boudaries (if any)
        Element tempelement = param.getChild(XMLTags.BoundariesTag, vcNamespace);
        if (tempelement != null) {
            Expression newexp = null;
            // Xm
            temp = tempelement.getAttributeValue(XMLTags.BoundaryAttrValueXm);
            if (temp != null) {
                newexp = unMangleExpression(temp);
                pdeEquation.setBoundaryXm(newexp);
            }
            // Xp
            temp = tempelement.getAttributeValue(XMLTags.BoundaryAttrValueXp);
            if (temp != null) {
                newexp = unMangleExpression(temp);
                pdeEquation.setBoundaryXp(newexp);
            }
            // Ym
            temp = tempelement.getAttributeValue(XMLTags.BoundaryAttrValueYm);
            if (temp != null) {
                newexp = unMangleExpression(temp);
                pdeEquation.setBoundaryYm(newexp);
            }
            // Yp
            temp = tempelement.getAttributeValue(XMLTags.BoundaryAttrValueYp);
            if (temp != null) {
                newexp = unMangleExpression(temp);
                pdeEquation.setBoundaryYp(newexp);
            }
            // Zm
            temp = tempelement.getAttributeValue(XMLTags.BoundaryAttrValueZm);
            if (temp != null) {
                newexp = unMangleExpression(temp);
                pdeEquation.setBoundaryZm(newexp);
            }
            // Zp
            temp = tempelement.getAttributeValue(XMLTags.BoundaryAttrValueZp);
            if (temp != null) {
                newexp = unMangleExpression(temp);
                pdeEquation.setBoundaryZp(newexp);
            }
        }
        // process BoundaryConditionValues
        {
            Iterator<Element> iterator = param.getChildren(XMLTags.BoundaryConditionValueTag, vcNamespace).iterator();
            if (iterator != null) {
                while (iterator.hasNext()) {
                    tempelement = (Element) iterator.next();
                    try {
                        pdeEquation.addBoundaryConditionValue(getBoundaryConditionValue(tempelement, pdeEquation));
                    } catch (MathException e) {
                        e.printStackTrace();
                        throw new XmlParseException("A MathException was fired when adding a BoundaryConditionValue to the compartmentSubDomain " + name, e);
                    }
                }
            }
        }
        {
            // add Velocity
            Element velocityE = param.getChild(XMLTags.VelocityTag, vcNamespace);
            if (velocityE != null) {
                String tempStr = null;
                boolean dummyVel = true;
                tempStr = velocityE.getAttributeValue(XMLTags.XAttrTag);
                if (tempStr != null) {
                    // all velocity dimensions are optional.
                    pdeEquation.setVelocityX(unMangleExpression(tempStr));
                    if (dummyVel) {
                        dummyVel = false;
                    }
                }
                tempStr = velocityE.getAttributeValue(XMLTags.YAttrTag);
                if (tempStr != null) {
                    pdeEquation.setVelocityY(unMangleExpression(tempStr));
                    if (dummyVel) {
                        dummyVel = false;
                    }
                }
                tempStr = velocityE.getAttributeValue(XMLTags.ZAttrTag);
                if (tempStr != null) {
                    pdeEquation.setVelocityZ(unMangleExpression(tempStr));
                    if (dummyVel) {
                        dummyVel = false;
                    }
                }
                if (dummyVel) {
                    throw new XmlParseException("Void Velocity element found under PDE for: " + name);
                }
            }
        }
        {
            // add Grad
            Element gradElement = param.getChild(XMLTags.GradientTag, vcNamespace);
            if (gradElement != null) {
                String tempStr = null;
                tempStr = gradElement.getAttributeValue(XMLTags.XAttrTag);
                if (tempStr != null) {
                    // all grad dimensions are optional.
                    pdeEquation.setGradientX(unMangleExpression(tempStr));
                }
                tempStr = gradElement.getAttributeValue(XMLTags.YAttrTag);
                if (tempStr != null) {
                    pdeEquation.setGradientY(unMangleExpression(tempStr));
                }
                tempStr = gradElement.getAttributeValue(XMLTags.ZAttrTag);
                if (tempStr != null) {
                    pdeEquation.setGradientZ(unMangleExpression(tempStr));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new XmlParseException(e);
    }
    return pdeEquation;
}
Also used : PdeEquation(cbit.vcell.math.PdeEquation) FilamentVariable(cbit.vcell.math.FilamentVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) StochVolVariable(cbit.vcell.math.StochVolVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) PointVariable(cbit.vcell.math.PointVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) Element(org.jdom.Element) Iterator(java.util.Iterator) GeometryException(cbit.vcell.geometry.GeometryException) MathFormatException(cbit.vcell.math.MathFormatException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) DataConversionException(org.jdom.DataConversionException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Example 58 with MathException

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

the class CartesianMesh method readFromFiles.

// private void writeContourElements(OutputStream out)
// {
// int i;
// //
// // write out contour elements (if present)
// //
// if (getNumContourElements()>0){
// out.println("    ContourElements {\n");
// out.println("           %d\n",(int)getNumContourElements());
// //
// // index volumeIndex begin.x begin.y begin.z  end.x, end.y end.z neighbor(prev) neighbor(next)
// //
// for (i=0;i<getNumContourElements();i++){
// ContourElement *cEl = getContourElement(i);
// int neighborPrev = -1;
// int neighborNext = -1;
// if (cEl->getBorder() == CONTOUR_BEGIN){
// neighborPrev = -1;
// neighborNext = i+1;
// }else if (cEl->getBorder() == CONTOUR_END){
// neighborPrev = i-1;
// neighborNext = -1;
// }else if (cEl->getBorder() == CONTOUR_INTERIOR){
// neighborPrev = i-1;
// neighborNext = i+1;
// }else{
// throw new Exception("Error writing contour mesh, contour element(%ld) has an illegal ContourBorder type = %d\n",i,cEl->getBorder());
// }
// out.println("           %ld %ld %lg %lg %lg %lg %lg %lg %ld %ld\n",cEl->getElementIndex(),cEl->getVolumeIndex(),
// cEl->getBegin().x,cEl->getBegin().y,cEl->getBegin().z,
// cEl->getEnd().x,  cEl->getEnd().y,  cEl->getEnd().z,
// neighborPrev, neighborNext);
// }
// out.println("    }\n");  // end ContourElements
// }
// }
public static CartesianMesh readFromFiles(File meshFile, File meshmetricsFile, File subdomainFile) throws IOException, MathException {
    // 
    // read meshFile and parse into 'mesh' object
    // 
    BufferedReader meshReader = null;
    BufferedReader meshMetricsReader = null;
    try {
        meshReader = new BufferedReader(new FileReader(meshFile));
        CommentStringTokenizer meshST = new CommentStringTokenizer(meshReader);
        CommentStringTokenizer membraneMeshMetricsST = null;
        if (meshmetricsFile != null) {
            meshMetricsReader = new BufferedReader(new FileReader(meshmetricsFile));
            membraneMeshMetricsST = new CommentStringTokenizer(meshMetricsReader);
        }
        CartesianMesh mesh = new CartesianMesh();
        MembraneMeshMetrics membraneMeshMetrics = null;
        if (membraneMeshMetricsST != null) {
            membraneMeshMetrics = mesh.readMembraneMeshMetrics(membraneMeshMetricsST);
        }
        if (subdomainFile != null) {
            mesh.subdomainInfo = SubdomainInfo.read(subdomainFile);
        }
        mesh.read(meshST, membraneMeshMetrics);
        return mesh;
    } finally {
        if (meshReader != null) {
            try {
                meshReader.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (meshMetricsReader != null) {
            try {
                meshMetricsReader.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer) FileReader(java.io.FileReader) IOException(java.io.IOException) MathFormatException(cbit.vcell.math.MathFormatException) MathException(cbit.vcell.math.MathException)

Example 59 with MathException

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

the class FiniteVolumeFileWriter method writeMembrane_jumpConditions.

/**
 *JUMP_CONDITION_BEGIN r
 *INFLUX 0.0;
 *OUTFLUX 0.0;
 *JUMP_CONDITION_END
 * @throws ExpressionException
 * @throws MathException
 */
private void writeMembrane_jumpConditions(MembraneSubDomain msd) throws ExpressionException, MathException {
    Enumeration<JumpCondition> enum1 = msd.getJumpConditions();
    // equations for boundaryValues for inner compartment subdomain
    CompartmentSubDomain innerCompSubDomain = msd.getInsideCompartment();
    Enumeration<Equation> innercompSubDomEqnsEnum = innerCompSubDomain.getEquations();
    while (innercompSubDomEqnsEnum.hasMoreElements()) {
        Equation eqn = innercompSubDomEqnsEnum.nextElement();
        if (eqn instanceof PdeEquation) {
            PdeEquation pdeEqn = (PdeEquation) eqn;
            BoundaryConditionValue boundaryValue = pdeEqn.getBoundaryConditionValue(msd.getName());
            if (boundaryValue != null) {
                // check if the type of BoundaryConditionSpec for this membraneSubDomain (msd) in the (inner) compartmentSubDomain is Flux; if not, it cannot be handled.
                BoundaryConditionSpec bcs = innerCompSubDomain.getBoundaryConditionSpec(msd.getName());
                if (bcs == null) {
                    throw new MathException("No Boundary type specified for '" + msd.getName() + "' in '" + innerCompSubDomain.getName() + "'.");
                }
                if (bcs != null && !bcs.getBoundaryConditionType().compareEqual(BoundaryConditionType.getNEUMANN()) && !bChomboSolver) {
                    throw new MathException("Boundary type '" + bcs.getBoundaryConditionType().boundaryTypeStringValue() + "' for compartmentSubDomain '" + innerCompSubDomain.getName() + "' not handled by the chosen solver. Expecting boundary condition of type 'Flux'.");
                }
                if (pdeEqn.getVariable().getDomain() == null || pdeEqn.getVariable().getDomain().getName().equals(msd.getInsideCompartment().getName())) {
                    printWriter.println("JUMP_CONDITION_BEGIN " + pdeEqn.getVariable().getName());
                    Expression flux = subsituteExpression(boundaryValue.getBoundaryConditionExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
                    String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
                    printWriter.println(bcs.getBoundaryConditionType().boundaryTypeStringValue().toUpperCase() + " " + msd.getInsideCompartment().getName() + " " + infix + ";");
                    printWriter.println("JUMP_CONDITION_END");
                    printWriter.println();
                }
            }
        }
    }
    // equations for boundaryValues for outer compartment subdomain
    CompartmentSubDomain outerCompSubDomain = msd.getOutsideCompartment();
    Enumeration<Equation> outerCompSubDomEqnsEnum = outerCompSubDomain.getEquations();
    while (outerCompSubDomEqnsEnum.hasMoreElements()) {
        Equation eqn = outerCompSubDomEqnsEnum.nextElement();
        if (eqn instanceof PdeEquation) {
            PdeEquation pdeEqn = (PdeEquation) eqn;
            BoundaryConditionValue boundaryValue = pdeEqn.getBoundaryConditionValue(msd.getName());
            if (boundaryValue != null) {
                // check if the type of BoundaryConditionSpec for this membraneSubDomain (msd) in the (inner) compartmentSubDomain is Flux; if not, it cannot be handled.
                BoundaryConditionSpec bcs = outerCompSubDomain.getBoundaryConditionSpec(msd.getName());
                if (bcs != null && !bcs.getBoundaryConditionType().compareEqual(BoundaryConditionType.getNEUMANN()) && !bChomboSolver) {
                    throw new MathException("Boundary type '" + bcs.getBoundaryConditionType().boundaryTypeStringValue() + "' for compartmentSubDomain '" + outerCompSubDomain.getName() + "' not handled by the chosen solver. Expecting boundary condition of type 'Flux'.");
                }
                if (pdeEqn.getVariable().getDomain() == null || pdeEqn.getVariable().getDomain().getName().equals(msd.getOutsideCompartment().getName())) {
                    printWriter.println("JUMP_CONDITION_BEGIN " + pdeEqn.getVariable().getName());
                    Expression flux = subsituteExpression(boundaryValue.getBoundaryConditionExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
                    String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
                    printWriter.println(bcs.getBoundaryConditionType().boundaryTypeStringValue().toUpperCase() + " " + msd.getOutsideCompartment().getName() + " " + infix + ";");
                    printWriter.println("JUMP_CONDITION_END");
                    printWriter.println();
                }
            }
        }
    }
    while (enum1.hasMoreElements()) {
        JumpCondition jc = enum1.nextElement();
        printWriter.println("JUMP_CONDITION_BEGIN " + jc.getVariable().getName());
        // influx
        if (jc.getVariable().getDomain() == null || jc.getVariable().getDomain().getName().equals(msd.getInsideCompartment().getName())) {
            Expression flux = subsituteExpression(jc.getInFluxExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
            String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
            printWriter.println(BoundaryConditionType.NEUMANN_STRING.toUpperCase() + " " + msd.getInsideCompartment().getName() + " " + infix + ";");
        }
        if (jc.getVariable().getDomain() == null || jc.getVariable().getDomain().getName().equals(msd.getOutsideCompartment().getName())) {
            // outflux
            Expression flux = subsituteExpression(jc.getOutFluxExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
            String infix = replaceVolumeVariable(simTask, msd, flux);
            printWriter.println(BoundaryConditionType.NEUMANN_STRING.toUpperCase() + " " + msd.getOutsideCompartment().getName() + " " + infix + ";");
        }
        printWriter.println("JUMP_CONDITION_END");
        printWriter.println();
    }
}
Also used : JumpCondition(cbit.vcell.math.JumpCondition) PdeEquation(cbit.vcell.math.PdeEquation) BoundaryConditionValue(cbit.vcell.math.PdeEquation.BoundaryConditionValue) Expression(cbit.vcell.parser.Expression) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) MathException(cbit.vcell.math.MathException) MeasureEquation(cbit.vcell.math.MeasureEquation) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) BoundaryConditionSpec(cbit.vcell.math.SubDomain.BoundaryConditionSpec)

Example 60 with MathException

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

the class FiniteVolumeFileWriter method writeVariables.

/**
 *# Variables : type name unit time_dependent_flag advection_flag solve_whole_mesh_flag solve_regions
 *VARIABLE_BEGIN
 *VOLUME_ODE rB uM
 *VOLUME_PDE rf uM false false
 *VOLUME_PDE r uM false false
 *VOLUME_ODE rfB uM
 *VARIABLE_END
 * @throws MathException
 * @throws ExpressionException
 * @throws IOException
 */
private void writeVariables() throws MathException, ExpressionException, IOException {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    printWriter.println("# Variables : type name domain time_dependent_flag advection_flag grad_flag solve_whole_mesh_flag solve_regions");
    printWriter.println(FVInputFileKeyword.VARIABLE_BEGIN);
    MathDescription mathDesc = simSymbolTable.getSimulation().getMathDescription();
    Variable[] vars = simSymbolTable.getVariables();
    ArrayList<RandomVariable> rvList = new ArrayList<RandomVariable>();
    for (int i = 0; i < vars.length; i++) {
        String varName = vars[i].getName();
        String domainName = vars[i].getDomain() == null ? null : vars[i].getDomain().getName();
        if (vars[i] instanceof VolumeRandomVariable || vars[i] instanceof MembraneRandomVariable) {
            rvList.add((RandomVariable) vars[i]);
        } else if (vars[i] instanceof VolVariable) {
            if (bChomboSolver && domainName == null) {
                throw new MathException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " requires that every variable is defined in a single domain");
            }
            VolVariable volVar = (VolVariable) vars[i];
            if (mathDesc.isPDE(volVar)) {
                boolean hasTimeVaryingDiffusionOrAdvection = simSymbolTable.hasTimeVaryingDiffusionOrAdvection(volVar);
                final boolean hasVelocity = mathDesc.hasVelocity(volVar);
                final boolean hasGradient = mathDesc.hasGradient(volVar);
                if (mathDesc.isPdeSteady(volVar)) {
                    printWriter.print("VOLUME_PDE_STEADY ");
                } else {
                    printWriter.print("VOLUME_PDE ");
                }
                printWriter.print(varName + " " + domainName + " " + hasTimeVaryingDiffusionOrAdvection + " " + hasVelocity + " " + hasGradient);
            } else {
                printWriter.print("VOLUME_ODE " + varName + " " + domainName);
            }
            if (domainName == null) {
                Vector<SubDomain> listOfSubDomains = new Vector<SubDomain>();
                int totalNumCompartments = 0;
                Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
                while (subDomainEnum.hasMoreElements()) {
                    SubDomain subDomain = subDomainEnum.nextElement();
                    if (subDomain instanceof CompartmentSubDomain) {
                        CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) subDomain;
                        totalNumCompartments++;
                        Equation varEquation = subDomain.getEquation(vars[i]);
                        if (varEquation != null) {
                            if (!(varEquation instanceof PdeEquation) || !((PdeEquation) varEquation).isDummy(simSymbolTable, compartmentSubDomain)) {
                                listOfSubDomains.add(compartmentSubDomain);
                            }
                        }
                    }
                }
                if ((totalNumCompartments == listOfSubDomains.size()) || (listOfSubDomains.size() == 0 && simTask.getSimulation().getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE))) {
                    printWriter.print(" true");
                } else {
                    printWriter.print(" false");
                    for (int j = 0; j < listOfSubDomains.size(); j++) {
                        CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) listOfSubDomains.elementAt(j);
                        printWriter.print(" " + compartmentSubDomain.getName());
                    }
                }
                printWriter.println();
            } else {
                printWriter.println(" false " + domainName);
            }
        } else if (vars[i] instanceof VolumeParticleVariable) {
            printWriter.println(FVInputFileKeyword.VOLUME_PARTICLE + " " + varName + " " + domainName);
        } else if (vars[i] instanceof MembraneParticleVariable) {
            printWriter.println(FVInputFileKeyword.MEMBRANE_PARTICLE + " " + varName + " " + domainName);
        } else if (vars[i] instanceof VolumeRegionVariable) {
            printWriter.println("VOLUME_REGION " + varName + " " + domainName);
        } else if (vars[i] instanceof MemVariable) {
            if (bChomboSolver && domainName == null) {
                throw new MathException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " requires that every variable is defined in a single domain");
            }
            MemVariable memVar = (MemVariable) vars[i];
            if (mathDesc.isPDE(memVar)) {
                printWriter.println("MEMBRANE_PDE " + varName + " " + domainName + " " + simSymbolTable.hasTimeVaryingDiffusionOrAdvection(memVar));
            } else {
                printWriter.println("MEMBRANE_ODE " + varName + " " + domainName);
            }
        } else if (vars[i] instanceof MembraneRegionVariable) {
            printWriter.println("MEMBRANE_REGION " + varName + " " + domainName);
        } else if (vars[i] instanceof FilamentVariable) {
            throw new RuntimeException("Filament application not supported yet");
        }
    }
    int numRandomVariables = rvList.size();
    if (numRandomVariables > 0) {
        ISize samplingSize = simTask.getSimulation().getMeshSpecification().getSamplingSize();
        String[] varNameArr = new String[numRandomVariables];
        VariableType[] varTypeArr = new VariableType[numRandomVariables];
        double[][] dataArr = new double[numRandomVariables][];
        for (int i = 0; i < numRandomVariables; i++) {
            RandomVariable rv = rvList.get(i);
            varNameArr[i] = rv.getName();
            int numRandomNumbers = 0;
            if (rv instanceof VolumeRandomVariable) {
                printWriter.print("VOLUME_RANDOM");
                varTypeArr[i] = VariableType.VOLUME;
                numRandomNumbers = samplingSize.getXYZ();
            } else if (rv instanceof MembraneRandomVariable) {
                printWriter.print("MEMBRANE_RANDOM");
                varTypeArr[i] = VariableType.MEMBRANE;
                numRandomNumbers = resampledGeometry.getGeometrySurfaceDescription().getSurfaceCollection().getTotalPolygonCount();
            } else {
                throw new RuntimeException("Unknown RandomVariable type");
            }
            printWriter.println(" " + varNameArr[i]);
            dataArr[i] = generateRandomNumbers(rv, numRandomNumbers);
        }
        File rvFile = new File(workingDirectory, simTask.getSimulationJobID() + RANDOM_VARIABLE_FILE_EXTENSION);
        DataSet.writeNew(rvFile, varNameArr, varTypeArr, samplingSize, dataArr);
    }
    printWriter.println(FVInputFileKeyword.VARIABLE_END);
    printWriter.println();
}
Also used : FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) MemVariable(cbit.vcell.math.MemVariable) Variable(cbit.vcell.math.Variable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) MathDescription(cbit.vcell.math.MathDescription) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) Vector(java.util.Vector) Enumeration(java.util.Enumeration) VariableType(cbit.vcell.math.VariableType) VolVariable(cbit.vcell.math.VolVariable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) MeasureEquation(cbit.vcell.math.MeasureEquation) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) MathException(cbit.vcell.math.MathException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) File(java.io.File)

Aggregations

MathException (cbit.vcell.math.MathException)78 ExpressionException (cbit.vcell.parser.ExpressionException)46 Expression (cbit.vcell.parser.Expression)38 Variable (cbit.vcell.math.Variable)33 VolVariable (cbit.vcell.math.VolVariable)26 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)18 MemVariable (cbit.vcell.math.MemVariable)18 PropertyVetoException (java.beans.PropertyVetoException)18 DataAccessException (org.vcell.util.DataAccessException)16 MathDescription (cbit.vcell.math.MathDescription)15 Vector (java.util.Vector)15 Element (org.jdom.Element)15 IOException (java.io.IOException)14 Function (cbit.vcell.math.Function)13 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)13 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)12 ParticleVariable (cbit.vcell.math.ParticleVariable)12 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)12 ArrayList (java.util.ArrayList)12 MappingException (cbit.vcell.mapping.MappingException)11