Search in sources :

Example 76 with Variable

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

the class XmlReader method getOdeEquation.

/**
 * This method returns an OdeEquation from a XML Element.
 * Creation date: (5/17/2001 3:52:40 PM)
 * @return cbit.vcell.math.OdeEquation
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private OdeEquation getOdeEquation(Element param, MathDescription mathDesc) throws XmlParseException {
    // get attributes
    String varname = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    // find reference in the dictionnary
    // try as a VolVariable
    Variable varref = mathDesc.getVariable(varname);
    // Make sure that the reference is not empty!!!
    if (varref == null) {
        throw new XmlParseException("The reference to the variable " + varname + " in a OdeEquation could not be resolved!");
    }
    // get Initial condition
    String temp = param.getChildText(XMLTags.InitialTag, vcNamespace);
    Expression initialexp = null;
    if (temp != null && temp.length() > 0) {
        initialexp = unMangleExpression(temp);
    }
    // Get Rate condition
    temp = param.getChildText(XMLTags.RateTag, vcNamespace);
    Expression rateexp = null;
    if (temp != null && temp.length() > 0) {
        rateexp = unMangleExpression((temp));
    }
    // --- Create the OdeEquation object ---
    OdeEquation odeEquation = new OdeEquation(varref, initialexp, rateexp);
    // 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);
            odeEquation.setExactSolution(expression);
        }
    }
    return odeEquation;
}
Also used : 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) OdeEquation(cbit.vcell.math.OdeEquation) Expression(cbit.vcell.parser.Expression)

Example 77 with Variable

use of cbit.vcell.math.Variable 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 78 with Variable

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

the class MathTestingUtilities method substituteWithExactSolution.

/**
 * Insert the method's description here.
 * Creation date: (1/24/2003 10:18:14 AM)
 * @return cbit.vcell.parser.Expression
 * @param origExp cbit.vcell.parser.Expression
 * @param subDomain cbit.vcell.math.SubDomain
 */
private static Expression substituteWithExactSolution(Expression origExp, CompartmentSubDomain subDomain, MathDescription exactMathDesc) throws ExpressionException {
    Expression substitutedExp = new Expression(origExp);
    substitutedExp.bindExpression(exactMathDesc);
    substitutedExp = MathUtilities.substituteFunctions(substitutedExp, exactMathDesc);
    substitutedExp.bindExpression(null);
    substitutedExp = substitutedExp.flatten();
    substitutedExp.bindExpression(exactMathDesc);
    String[] symbols = substitutedExp.getSymbols();
    for (int i = 0; i < symbols.length; i++) {
        Variable var = (Variable) substitutedExp.getSymbolBinding(symbols[i]);
        if (var instanceof VolVariable) {
            String exactVarName = var.getName() + "_" + subDomain.getName() + "_exact";
            substitutedExp.substituteInPlace(new Expression(var.getName()), new Expression(exactVarName));
        } else if (var instanceof VolumeRegionVariable || var instanceof MemVariable || var instanceof MembraneRegionVariable || var instanceof FilamentVariable || var instanceof FilamentRegionVariable) {
            throw new RuntimeException("variable substitution not yet implemented for Variable type " + var.getClass().getName() + "(" + var.getName() + ")");
        }
    }
    substitutedExp.bindExpression(null);
    return substitutedExp;
}
Also used : VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) SensVariable(cbit.vcell.solver.ode.SensVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) MemVariable(cbit.vcell.math.MemVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) Expression(cbit.vcell.parser.Expression) VolVariable(cbit.vcell.math.VolVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) FilamentVariable(cbit.vcell.math.FilamentVariable)

Example 79 with Variable

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

the class MathTestingUtilities method comparePDEResults.

/**
 * Insert the method's description here.
 * Creation date: (8/20/2003 12:58:10 PM)
 */
public static SimulationComparisonSummary comparePDEResults(SimulationSymbolTable testSimSymbolTable, PDEDataManager testDataManager, SimulationSymbolTable refSimSymbolTable, PDEDataManager refDataManager, String[] varsToCompare, double absErrorThreshold, double relErrorThreshold, VCDocument refDocument, DataInfoProvider refDataInfoProvider, VCDocument testDocument, DataInfoProvider testDataInfoProvider) throws DataAccessException, ExpressionException {
    java.util.Hashtable<String, DataErrorSummary> tempVarHash = new java.util.Hashtable<String, DataErrorSummary>();
    boolean bTimesEqual = true;
    double[] testTimeArray = testDataManager.getDataSetTimes();
    double[] refTimeArray = refDataManager.getDataSetTimes();
    if (testTimeArray.length != refTimeArray.length) {
        bTimesEqual = false;
    // throw new RuntimeException("Data times for reference and test simulations don't match, cannot compare the two simulations!");
    } else {
        for (int i = 0; i < testTimeArray.length; i++) {
            if (testTimeArray[i] != refTimeArray[i]) {
                bTimesEqual = false;
            }
        }
    }
    // if (!checkSimVars(testSim, refSim)) {
    // //String errorS = "TestVars - ";
    // Variable[] testVars = testSim.getVariables();
    // //for(int i =0;i<vars.length;i+= 1){
    // //errorS+= vars[i].getName()+" ";
    // //}
    // //errorS+=" <<>> RefVars - ";
    // Variable[] refVars = refSim.getVariables();
    // //for(int i =0;i<vars.length;i+= 1){
    // //errorS+= vars[i].getName()+" ";
    // //}
    // throw new RuntimeException(
    // "VarNotMatch testLength="+(testVars != null?testVars.length+"":"null")+" refLength="+(refVars != null?refVars.length+"":"null"));
    // }
    CartesianMesh testMesh = testDataManager.getMesh();
    MathDescription testMathDesc = testSimSymbolTable.getSimulation().getMathDescription();
    // Variable[] refVars = refSim.getVariables();
    MathDescription refMathDesc = refSimSymbolTable.getSimulation().getMathDescription();
    CartesianMesh refMesh = refDataManager.getMesh();
    int[] membraneIndexMapping = null;
    // Get volumeSubdomains from mathDesc/mesh and store in lookupTable for testSimulation
    int testNumVol = testMesh.getSizeX() * testMesh.getSizeY() * testMesh.getSizeZ();
    CompartmentSubDomain[] testVolSubDomainLookup = new CompartmentSubDomain[testNumVol];
    for (int i = 0; i < testNumVol; i++) {
        int subVolumeIndex = testMesh.getSubVolumeFromVolumeIndex(i);
        SubVolume subVolume = testMathDesc.getGeometry().getGeometrySpec().getSubVolume(subVolumeIndex);
        CompartmentSubDomain compSubDomain = testMathDesc.getCompartmentSubDomain(subVolume.getName());
        testVolSubDomainLookup[i] = compSubDomain;
    }
    // Get membraneSubdomains from mathDesc/mesh and store in lookupTable for testSimulation
    int testNumMem = testMesh.getMembraneElements().length;
    MembraneSubDomain[] testMemSubDomainLookup = new MembraneSubDomain[testNumMem];
    for (int i = 0; i < testNumMem; i++) {
        int insideVolIndex = testMesh.getMembraneElements()[i].getInsideVolumeIndex();
        int outsideVolIndex = testMesh.getMembraneElements()[i].getOutsideVolumeIndex();
        MembraneSubDomain memSubDomain = testMathDesc.getMembraneSubDomain(testVolSubDomainLookup[insideVolIndex], testVolSubDomainLookup[outsideVolIndex]);
        testMemSubDomainLookup[i] = memSubDomain;
    }
    // Get volumeSubdomains from mathDesc/mesh and store in lookupTable for refSimulation
    int refNumVol = refMesh.getSizeX() * refMesh.getSizeY() * refMesh.getSizeZ();
    CompartmentSubDomain[] refVolSubDomainLookup = new CompartmentSubDomain[refNumVol];
    for (int i = 0; i < refNumVol; i++) {
        int subVolumeIndex = refMesh.getSubVolumeFromVolumeIndex(i);
        SubVolume subVolume = refMathDesc.getGeometry().getGeometrySpec().getSubVolume(subVolumeIndex);
        CompartmentSubDomain compSubDomain = refMathDesc.getCompartmentSubDomain(subVolume.getName());
        refVolSubDomainLookup[i] = compSubDomain;
    }
    // Get membraneSubdomains from mathDesc/mesh and store in lookupTable for refSimulation
    int refNumMem = refMesh.getMembraneElements().length;
    MembraneSubDomain[] refMemSubDomainLookup = new MembraneSubDomain[refNumMem];
    for (int i = 0; i < refNumMem; i++) {
        int insideVolIndex = refMesh.getMembraneElements()[i].getInsideVolumeIndex();
        int outsideVolIndex = refMesh.getMembraneElements()[i].getOutsideVolumeIndex();
        MembraneSubDomain memSubDomain = refMathDesc.getMembraneSubDomain(refVolSubDomainLookup[insideVolIndex], refVolSubDomainLookup[outsideVolIndex]);
        refMemSubDomainLookup[i] = memSubDomain;
    }
    SimulationComparisonSummary simComparisonSummary = new SimulationComparisonSummary();
    String hashKey = new String("");
    DataErrorSummary tempVar = null;
    DataIdentifier[] refDataIDs = refDataManager.getDataIdentifiers();
    // for each var, do the following :
    for (int i = 0; i < varsToCompare.length; i++) {
        DataIdentifier refDataID = null;
        for (int j = 0; j < refDataIDs.length; j++) {
            if (refDataIDs[j].getName().equals(varsToCompare[i])) {
                refDataID = refDataIDs[j];
                break;
            }
        }
        // 
        // Find REFERENCE variable
        // 
        Variable refVar = getSimVar(refSimSymbolTable, varsToCompare[i]);
        if (refVar == null) {
            // Should only happen if TEST sims were generated 'post-domains' and REFERENCE sims were generated 'pre-domains'
            if (refDataID != null) {
                throw new RuntimeException("Unexpected reference condition: '" + varsToCompare[i] + "' not found in symboltable but was found in dataidentifiers");
            }
            if (testDocument instanceof BioModel) {
                // Only BioModels need to be checked
                // Look in TEST for a speciescontext with matching species name
                System.out.println("ReferenceVariable: using alternate method to find '" + varsToCompare[i] + "'");
                BioModel refBioModel = (BioModel) refDocument;
                BioModel testBioModel = (BioModel) testDocument;
                SpeciesContext testSpeciesContext = testBioModel.getModel().getSpeciesContext(varsToCompare[i]);
                if (testSpeciesContext != null) {
                    refVar = refSimSymbolTable.getVariable(testSpeciesContext.getSpecies().getCommonName());
                    for (int j = 0; j < refDataIDs.length; j++) {
                        if (refDataIDs[j].getName().equals(testSpeciesContext.getSpecies().getCommonName())) {
                            refDataID = refDataIDs[j];
                            break;
                        }
                    }
                }
            }
            if (refVar == null || refDataID == null) {
                Simulation refSim = refSimSymbolTable.getSimulation();
                throw new RuntimeException("The variable " + varsToCompare[i] + " was not found in Simulation (" + refSim.getName() + " " + refSim.getVersion().getDate() + ")\n");
            }
        }
        // 
        // Find TEST variable (assumed to have sims generated with a software version later than REFERENCE)
        // 
        Variable testVar = getSimVar(testSimSymbolTable, varsToCompare[i]);
        if (testVar == null) {
            // Should only happen if TEST sims were generated 'post-domains' and REFERENCE sims were generated 'pre-domains'
            System.out.println("TestVariable: using alternate method to find '" + varsToCompare[i] + "'");
            BioModel testBioModel = (BioModel) testDocument;
            SpeciesContext[] speciesContexts = testBioModel.getModel().getSpeciesContexts();
            boolean bSkip = false;
            for (int j = 0; j < speciesContexts.length; j++) {
                if (speciesContexts[j].getSpecies().getCommonName().equals(varsToCompare[i])) {
                    testVar = testSimSymbolTable.getVariable(speciesContexts[j].getName());
                    if (testVar == null) {
                        throw new RuntimeException("Speciescontext name '" + speciesContexts[j].getName() + "' not found in testsimsymboltable");
                    }
                    // If we got here it means at least one matching speciescontext was found in TEST with
                    // a species name matching varsToCompare[i].  We can skip because the matching speciesconetext
                    // will be used to do a comparison at some point.
                    bSkip = true;
                    break;
                }
            }
            if (bSkip) {
                // these are tested already using full simcontext names
                System.out.println("Skipping '" + varsToCompare[i] + "' as lookup in testSimSymbolTable");
                continue;
            }
            Simulation refSim = refSimSymbolTable.getSimulation();
            throw new RuntimeException("The variable " + varsToCompare[i] + " was not found in Simulation (" + refSim.getName() + " " + refSim.getVersion().getDate() + ")\n");
        }
        // for each time in timeArray. ('t' is used to index the testTimeArray, for interpolation purposes.)
        int t = 0;
        for (int j = 0; j < refTimeArray.length; j++) {
            // get data block from varName, data from datablock
            SimDataBlock refSimDataBlock = refDataManager.getSimDataBlock(refVar.getName(), refTimeArray[j]);
            double[] refData = refSimDataBlock.getData();
            double[] resampledTestData = null;
            if (bTimesEqual) {
                // If time arrays for both sims are equal, no need to resample/interpolate, just obtain the datablock from dataManager
                SimDataBlock testSimDataBlock = testDataManager.getSimDataBlock(testVar.getName(), testTimeArray[j]);
                resampledTestData = testSimDataBlock.getData();
            } else {
                // Time resampling (interpolation) needed.
                while ((t < testTimeArray.length - 2) && (refTimeArray[j] >= testTimeArray[t + 1])) {
                    t++;
                }
                SimDataBlock testSimDataBlock_1 = testDataManager.getSimDataBlock(testVar.getName(), testTimeArray[t]);
                double[] testData_1 = testSimDataBlock_1.getData();
                SimDataBlock testSimDataBlock_2 = testDataManager.getSimDataBlock(testVar.getName(), testTimeArray[t + 1]);
                double[] testData_2 = testSimDataBlock_2.getData();
                resampledTestData = new double[testData_1.length];
                // 
                for (int m = 0; m < testData_1.length; m++) {
                    resampledTestData[m] = testData_1[m] + (testData_2[m] - testData_1[m]) * (refTimeArray[j] - testTimeArray[t]) / (testTimeArray[t + 1] - testTimeArray[t]);
                }
            }
            // Spatial resampling (interpolation) ...
            double[] spaceResampledData = new double[refData.length];
            if (!testMathDesc.getGeometry().getExtent().compareEqual(refMathDesc.getGeometry().getExtent()) || !testMathDesc.getGeometry().getOrigin().compareEqual(refMathDesc.getGeometry().getOrigin())) {
                throw new RuntimeException("Different origins and/or extents for the 2 geometries. Cannot compare the 2 simulations");
            }
            if (testMesh.getSizeX() != refMesh.getSizeX() || testMesh.getSizeY() != refMesh.getSizeY() || testMesh.getSizeZ() != refMesh.getSizeZ()) {
                if (testVar instanceof VolVariable) {
                    if (testMathDesc.getGeometry().getDimension() == 1 && refMathDesc.getGeometry().getDimension() == 1) {
                        spaceResampledData = resample1DSpatial(resampledTestData, testMesh, refMesh);
                    } else if (testMathDesc.getGeometry().getDimension() == 2 && refMathDesc.getGeometry().getDimension() == 2) {
                        spaceResampledData = resample2DSpatial(resampledTestData, testMesh, refMesh);
                    } else if (testMathDesc.getGeometry().getDimension() == 3 && refMathDesc.getGeometry().getDimension() == 3) {
                        spaceResampledData = resample3DSpatial(resampledTestData, testMesh, refMesh);
                    } else {
                        throw new RuntimeException("Comparison of 2 simulations with different geometry dimensions are not handled at this time!");
                    }
                } else {
                    throw new RuntimeException("spatial resampling for variable type: " + testVar.getClass().getName() + " not supported");
                }
            } else {
                // no space resampling required
                if (testVar instanceof MemVariable) {
                    // 
                    if (membraneIndexMapping == null) {
                        membraneIndexMapping = testMesh.getMembraneIndexMapping(refMesh);
                    }
                    spaceResampledData = new double[resampledTestData.length];
                    for (int k = 0; k < resampledTestData.length; k++) {
                        spaceResampledData[k] = resampledTestData[membraneIndexMapping[k]];
                    }
                } else {
                    // 
                    // no reordering needed for other variable types.
                    // 
                    spaceResampledData = resampledTestData;
                }
            }
            // for each point in data block ...
            testDataInfoProvider.getPDEDataContext().setVariableName(testVar.getName());
            for (int k = 0; k < refData.length; k++) {
                if (!testDataInfoProvider.isDefined(k)) {
                    continue;
                }
                // Determine maxRef, minRef, maxAbsErr for variable
                // SubDomain testSubDomain = null;
                String sn = null;
                VariableType refVarType = refDataID.getVariableType();
                if (refVarType.equals(VariableType.VOLUME)) {
                    // testSubDomain = refVolSubDomainLookup[k];
                    sn = refVolSubDomainLookup[k].getName();
                } else if (refVarType.equals(VariableType.MEMBRANE)) {
                    // testSubDomain = refMemSubDomainLookup[k];
                    sn = refMemSubDomainLookup[k].getName();
                } else if (refVarType.equals(VariableType.MEMBRANE_REGION)) {
                    sn = "MRV_" + i;
                } else if (refVarType.equals(VariableType.VOLUME_REGION)) {
                    sn = "VRV_" + i;
                } else {
                    throw new RuntimeException("Var " + refVar.getName() + " not supported yet!");
                }
                // hashKey = refVar.getName()+":"+testSubDomain.getName();
                hashKey = refVar.getName() + ":" + sn;
                tempVar = tempVarHash.get(hashKey);
                if (tempVar == null) {
                    tempVar = new DataErrorSummary(null);
                    tempVarHash.put(hashKey, tempVar);
                }
                tempVar.addDataValues(refData[k], spaceResampledData[k], refTimeArray[j], k, absErrorThreshold, relErrorThreshold);
            }
        // end for (k)
        }
    // end for (j)
    }
    // end for (i)
    Enumeration<String> enumKeys = tempVarHash.keys();
    while (enumKeys.hasMoreElements()) {
        String key = enumKeys.nextElement();
        DataErrorSummary tempVarSummary = tempVarHash.get(key);
        simComparisonSummary.addVariableComparisonSummary(new VariableComparisonSummary(key, tempVarSummary.getMinRef(), tempVarSummary.getMaxRef(), tempVarSummary.getMaxAbsoluteError(), tempVarSummary.getMaxRelativeError(), tempVarSummary.getL2Norm(), tempVarSummary.getTimeAtMaxAbsoluteError(), tempVarSummary.getIndexAtMaxAbsoluteError(), tempVarSummary.getTimeAtMaxRelativeError(), tempVarSummary.getIndexAtMaxRelativeError()));
    }
    return simComparisonSummary;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) DataIdentifier(cbit.vcell.simdata.DataIdentifier) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) SensVariable(cbit.vcell.solver.ode.SensVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) SpeciesContext(cbit.vcell.model.SpeciesContext) SimDataBlock(cbit.vcell.simdata.SimDataBlock) MemVariable(cbit.vcell.math.MemVariable) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) VariableType(cbit.vcell.math.VariableType) VolVariable(cbit.vcell.math.VolVariable) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Simulation(cbit.vcell.solver.Simulation) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) BioModel(cbit.vcell.biomodel.BioModel)

Example 80 with Variable

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

the class FiniteVolumeFileWriter method writeCompartment_VarContext.

/**
 * Insert the method's description here.
 * Creation date: (5/9/2005 2:52:48 PM)
 * @throws ExpressionException
 */
private void writeCompartment_VarContext(CompartmentSubDomain volSubDomain) throws ExpressionException {
    Simulation simulation = simTask.getSimulation();
    // 
    // get list of volVariables participating in PDEs (anywhere).
    // 
    Vector<VolVariable> pdeVolVariableList = new Vector<VolVariable>();
    Variable[] variables = simTask.getSimulationJob().getSimulationSymbolTable().getVariables();
    for (int i = 0; i < variables.length; i++) {
        if (variables[i] instanceof VolVariable && simulation.getMathDescription().isPDE((VolVariable) variables[i])) {
            pdeVolVariableList.add((VolVariable) variables[i]);
        }
    }
    Enumeration<Equation> enum_equ = volSubDomain.getEquations();
    while (enum_equ.hasMoreElements()) {
        Equation equation = enum_equ.nextElement();
        // for chombo solver, only write equations for variables that are defined in this compartment
        if (!bChomboSolver || equation.getVariable().getDomain().getName().equals(volSubDomain.getName())) {
            if (equation instanceof VolumeRegionEquation) {
                writeCompartmentRegion_VarContext_Equation(volSubDomain, (VolumeRegionEquation) equation);
            } else if (equation instanceof MeasureEquation) {
                throw new RuntimeException("Measure Equation " + equation.getClass().getSimpleName() + " not yet supported in FiniteVolume solvers");
            } else {
                writeCompartment_VarContext_Equation(volSubDomain, equation);
            }
        }
        if (equation instanceof PdeEquation) {
            pdeVolVariableList.remove(equation.getVariable());
        }
    }
    // 
    if (!bChomboSolver) {
        for (int i = 0; i < pdeVolVariableList.size(); i++) {
            VolVariable volVar = pdeVolVariableList.elementAt(i);
            boolean bSteady = simulation.getMathDescription().isPdeSteady(volVar);
            PdeEquation dummyPdeEquation = new PdeEquation(volVar, bSteady, new Expression(0.0), new Expression(0.0), new Expression(0.0));
            writeCompartment_VarContext_Equation(volSubDomain, dummyPdeEquation);
        }
    }
}
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) VolVariable(cbit.vcell.math.VolVariable) 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) PdeEquation(cbit.vcell.math.PdeEquation) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) MeasureEquation(cbit.vcell.math.MeasureEquation) Vector(java.util.Vector)

Aggregations

Variable (cbit.vcell.math.Variable)108 Expression (cbit.vcell.parser.Expression)69 VolVariable (cbit.vcell.math.VolVariable)63 MemVariable (cbit.vcell.math.MemVariable)48 ReservedVariable (cbit.vcell.math.ReservedVariable)43 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)38 MathException (cbit.vcell.math.MathException)37 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)36 FilamentVariable (cbit.vcell.math.FilamentVariable)35 InsideVariable (cbit.vcell.math.InsideVariable)34 OutsideVariable (cbit.vcell.math.OutsideVariable)34 ExpressionException (cbit.vcell.parser.ExpressionException)34 Function (cbit.vcell.math.Function)32 MathDescription (cbit.vcell.math.MathDescription)32 Constant (cbit.vcell.math.Constant)31 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)29 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)25 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)24 ParticleVariable (cbit.vcell.math.ParticleVariable)24 Vector (java.util.Vector)23