Search in sources :

Example 11 with SubVolume

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

the class FRAPStudy method createNewRefBioModel.

public static BioModel createNewRefBioModel(FRAPStudy sourceFrapStudy, String baseDiffusionRate, TimeStep tStep, KeyValue simKey, User owner, FieldDataIdentifierSpec psfFDIS, int startingIndexForRecovery) throws Exception {
    if (owner == null) {
        throw new Exception("Owner is not defined");
    }
    ROI cellROI_2D = sourceFrapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
    Extent extent = sourceFrapStudy.getFrapData().getImageDataset().getExtent();
    TimeBounds timeBounds = FRAPOptData.getEstimatedRefTimeBound(sourceFrapStudy);
    double timeStepVal = FRAPOptData.REFERENCE_DIFF_DELTAT;
    int numX = cellROI_2D.getRoiImages()[0].getNumX();
    int numY = cellROI_2D.getRoiImages()[0].getNumY();
    int numZ = cellROI_2D.getRoiImages().length;
    short[] shortPixels = cellROI_2D.getRoiImages()[0].getPixels();
    byte[] bytePixels = new byte[numX * numY * numZ];
    final byte EXTRACELLULAR_PIXVAL = 0;
    final byte CYTOSOL_PIXVAL = 1;
    for (int i = 0; i < bytePixels.length; i++) {
        if (shortPixels[i] != 0) {
            bytePixels[i] = CYTOSOL_PIXVAL;
        }
    }
    VCImage maskImage;
    try {
        maskImage = new VCImageUncompressed(null, bytePixels, extent, numX, numY, numZ);
    } catch (ImageException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to create mask image for geometry");
    }
    Geometry geometry = new Geometry("geometry", maskImage);
    if (geometry.getGeometrySpec().getNumSubVolumes() != 2) {
        throw new Exception("Cell ROI has no ExtraCellular.");
    }
    int subVolume0PixVal = ((ImageSubVolume) geometry.getGeometrySpec().getSubVolume(0)).getPixelValue();
    geometry.getGeometrySpec().getSubVolume(0).setName((subVolume0PixVal == EXTRACELLULAR_PIXVAL ? EXTRACELLULAR_NAME : CYTOSOL_NAME));
    int subVolume1PixVal = ((ImageSubVolume) geometry.getGeometrySpec().getSubVolume(1)).getPixelValue();
    geometry.getGeometrySpec().getSubVolume(1).setName((subVolume1PixVal == CYTOSOL_PIXVAL ? CYTOSOL_NAME : EXTRACELLULAR_NAME));
    geometry.getGeometrySurfaceDescription().updateAll();
    BioModel bioModel = new BioModel(null);
    bioModel.setName("unnamed");
    Model model = new Model("model");
    bioModel.setModel(model);
    Feature extracellular = model.addFeature(EXTRACELLULAR_NAME);
    Feature cytosol = model.addFeature(CYTOSOL_NAME);
    Membrane plasmaMembrane = model.addMembrane(PLASMAMEMBRANE_NAME);
    String roiDataName = FRAPStudy.ROI_EXTDATA_NAME;
    final int ONE_DIFFUSION_SPECIES_COUNT = 1;
    final int MOBILE_SPECIES_INDEX = 0;
    Expression[] diffusionConstants = new Expression[ONE_DIFFUSION_SPECIES_COUNT];
    Species[] species = new Species[ONE_DIFFUSION_SPECIES_COUNT];
    SpeciesContext[] speciesContexts = new SpeciesContext[ONE_DIFFUSION_SPECIES_COUNT];
    Expression[] initialConditions = new Expression[ONE_DIFFUSION_SPECIES_COUNT];
    // Mobile Species
    diffusionConstants[MOBILE_SPECIES_INDEX] = new Expression(baseDiffusionRate);
    species[MOBILE_SPECIES_INDEX] = new Species(SPECIES_NAME_PREFIX_MOBILE, "Mobile bleachable species");
    speciesContexts[MOBILE_SPECIES_INDEX] = new SpeciesContext(null, species[MOBILE_SPECIES_INDEX].getCommonName(), species[MOBILE_SPECIES_INDEX], cytosol);
    FieldFunctionArguments postBleach_first = new FieldFunctionArguments(roiDataName, "postbleach_first", new Expression(0), VariableType.VOLUME);
    FieldFunctionArguments prebleach_avg = new FieldFunctionArguments(roiDataName, "prebleach_avg", new Expression(0), VariableType.VOLUME);
    Expression expPostBleach_first = new Expression(postBleach_first.infix());
    Expression expPreBleach_avg = new Expression(prebleach_avg.infix());
    initialConditions[MOBILE_SPECIES_INDEX] = Expression.div(expPostBleach_first, expPreBleach_avg);
    SimulationContext simContext = new SimulationContext(bioModel.getModel(), geometry);
    bioModel.addSimulationContext(simContext);
    FeatureMapping cytosolFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(cytosol);
    FeatureMapping extracellularFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(extracellular);
    MembraneMapping plasmaMembraneMapping = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(plasmaMembrane);
    SubVolume cytSubVolume = geometry.getGeometrySpec().getSubVolume(CYTOSOL_NAME);
    SubVolume exSubVolume = geometry.getGeometrySpec().getSubVolume(EXTRACELLULAR_NAME);
    SurfaceClass pmSurfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(exSubVolume, cytSubVolume);
    cytosolFeatureMapping.setGeometryClass(cytSubVolume);
    extracellularFeatureMapping.setGeometryClass(exSubVolume);
    plasmaMembraneMapping.setGeometryClass(pmSurfaceClass);
    cytosolFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    extracellularFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    plasmaMembraneMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    for (int i = 0; i < initialConditions.length; i++) {
        model.addSpecies(species[i]);
        model.addSpeciesContext(speciesContexts[i]);
    }
    for (int i = 0; i < speciesContexts.length; i++) {
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(speciesContexts[i]);
        scs.getInitialConditionParameter().setExpression(initialConditions[i]);
        scs.getDiffusionParameter().setExpression(diffusionConstants[i]);
    }
    MathMapping mathMapping = simContext.createNewMathMapping();
    MathDescription mathDesc = mathMapping.getMathDescription();
    // Add PSF function
    mathDesc.addVariable(new Function(Simulation.PSF_FUNCTION_NAME, new Expression(psfFDIS.getFieldFuncArgs().infix()), null));
    simContext.setMathDescription(mathDesc);
    SimulationVersion simVersion = new SimulationVersion(simKey, "sim1", owner, new GroupAccessNone(), new KeyValue("0"), new BigDecimal(0), new Date(), VersionFlag.Current, "", null);
    Simulation newSimulation = new Simulation(simVersion, simContext.getMathDescription());
    newSimulation.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
    simContext.addSimulation(newSimulation);
    newSimulation.getSolverTaskDescription().setTimeBounds(timeBounds);
    newSimulation.getSolverTaskDescription().setOutputTimeSpec(new UniformOutputTimeSpec(timeStepVal));
    newSimulation.getMeshSpecification().setSamplingSize(cellROI_2D.getISize());
    newSimulation.getSolverTaskDescription().setTimeStep(new TimeStep(timeStepVal, timeStepVal, timeStepVal));
    return bioModel;
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) ImageException(cbit.image.ImageException) KeyValue(org.vcell.util.document.KeyValue) Extent(org.vcell.util.Extent) SurfaceClass(cbit.vcell.geometry.SurfaceClass) MathDescription(cbit.vcell.math.MathDescription) VCImage(cbit.image.VCImage) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Feature(cbit.vcell.model.Feature) TimeBounds(cbit.vcell.solver.TimeBounds) Function(cbit.vcell.math.Function) GroupAccessNone(org.vcell.util.document.GroupAccessNone) TimeStep(cbit.vcell.solver.TimeStep) SimulationVersion(org.vcell.util.document.SimulationVersion) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SubVolume(cbit.vcell.geometry.SubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) Membrane(cbit.vcell.model.Membrane) Species(cbit.vcell.model.Species) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) VCImageUncompressed(cbit.image.VCImageUncompressed) SimulationContext(cbit.vcell.mapping.SimulationContext) ROI(cbit.vcell.VirtualMicroscopy.ROI) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) MathMapping(cbit.vcell.mapping.MathMapping)

Example 12 with SubVolume

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

the class AbstractMathMapping method getDefaultGeometryClass.

protected GeometryClass getDefaultGeometryClass(Expression expr) throws ExpressionException, MappingException {
    GeometryClass geometryClass = null;
    if (simContext.getGeometry().getDimension() == 0) {
        return null;
    }
    String[] symbols = expr.getSymbols();
    // if expr has no symbols, model param cannot be localized to a domain (its a const).
    if (symbols == null) {
        return null;
    } else {
        Expression modelParamExpr = substituteGlobalParameters(expr);
        symbols = modelParamExpr.getSymbols();
        for (int k = 0; symbols != null && k < symbols.length; k++) {
            Structure symbolStructure = null;
            SymbolTableEntry ste = modelParamExpr.getSymbolBinding(symbols[k]);
            if (ste instanceof SpeciesContext) {
                symbolStructure = ((SpeciesContext) ste).getStructure();
            } else if (ste instanceof StructureSize) {
                symbolStructure = ((StructureSize) ste).getStructure();
            } else if (ste instanceof MembraneVoltage) {
                symbolStructure = ((MembraneVoltage) ste).getMembrane();
            }
            if (symbolStructure != null) {
                StructureMapping sm = simContext.getGeometryContext().getStructureMapping(symbolStructure);
                GeometryClass symbolGeomClass = sm.getGeometryClass();
                if (geometryClass == null) {
                    geometryClass = symbolGeomClass;
                } else {
                    if (geometryClass != symbolGeomClass) {
                        if (geometryClass instanceof SurfaceClass) {
                            if (symbolGeomClass instanceof SurfaceClass) {
                                throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + geometryClass.getName() + "' & surface domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
                            } else if (symbolGeomClass instanceof SubVolume) {
                                // geomClass : surfaceClass; symbolGeomClass : subVol
                                if (!((SurfaceClass) geometryClass).isAdjacentTo((SubVolume) symbolGeomClass)) {
                                    throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + geometryClass.getName() + "' & volume domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
                                }
                            } else {
                                throw new MappingException("unexpected geometry class : " + symbolGeomClass.getClass());
                            }
                        } else if (geometryClass instanceof SubVolume) {
                            // geometryClass is a SubVolume
                            if (symbolGeomClass instanceof SubVolume) {
                                // check if adjacent; if so, choose separating membrane.
                                SurfaceClass surfaceClass = simContext.getGeometry().getGeometrySurfaceDescription().getSurfaceClass((SubVolume) symbolGeomClass, (SubVolume) geometryClass);
                                if (surfaceClass != null) {
                                    geometryClass = surfaceClass;
                                } else {
                                    throw new MappingException("The expression '" + expr.infix() + "' references variables in volume domain '" + geometryClass.getName() + "' & volume domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
                                }
                            } else {
                                // geomClass : subVol; symbolGeomClass = surfaceClass
                                SurfaceClass surfaceSymbolGeomClass = (SurfaceClass) symbolGeomClass;
                                if (!surfaceSymbolGeomClass.isAdjacentTo((SubVolume) geometryClass)) {
                                    throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + surfaceSymbolGeomClass.getName() + "' & volume domain '" + geometryClass.getName() + "' that cannot be evaluated.");
                                } else {
                                    geometryClass = symbolGeomClass;
                                }
                            }
                        } else {
                            throw new MappingException("unexpected geometry class : " + geometryClass.getClass());
                        }
                    }
                }
            }
        }
    }
    return geometryClass;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SpeciesContext(cbit.vcell.model.SpeciesContext) StructureSize(cbit.vcell.model.Structure.StructureSize) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Structure(cbit.vcell.model.Structure)

Example 13 with SubVolume

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

the class DiffEquMathMapping method computeBoundaryConditionSource.

// determine membrane inside and outside subvolume
public static Pair<SubVolume, SubVolume> computeBoundaryConditionSource(Model model, SimulationContext simContext, SurfaceClass surfaceClass) {
    SubVolume outerSubVolume = null;
    SubVolume innerSubVolume = null;
    Structure[] mappedStructures = simContext.getGeometryContext().getStructuresFromGeometryClass(surfaceClass);
    // inside and outside correspond to structure hierarchy when present
    for (Structure s : mappedStructures) {
        if (s instanceof Membrane) {
            Membrane m = (Membrane) s;
            Feature infeature = model.getStructureTopology().getInsideFeature(m);
            if (infeature != null) {
                FeatureMapping insm = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(infeature);
                if (insm.getGeometryClass() instanceof SubVolume) {
                    innerSubVolume = (SubVolume) insm.getGeometryClass();
                }
            }
            Feature outfeature = model.getStructureTopology().getOutsideFeature(m);
            if (outfeature != null) {
                FeatureMapping outsm = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(outfeature);
                if (outsm.getGeometryClass() instanceof SubVolume) {
                    outerSubVolume = (SubVolume) outsm.getGeometryClass();
                }
            }
        }
    }
    // make the choice deterministic
    if (innerSubVolume == null || outerSubVolume == null || innerSubVolume == outerSubVolume) {
        Set<SubVolume> sv = surfaceClass.getAdjacentSubvolumes();
        Iterator<SubVolume> iterator = sv.iterator();
        innerSubVolume = iterator.next();
        outerSubVolume = iterator.next();
        if (innerSubVolume.getName().compareTo(outerSubVolume.getName()) > 0) {
            SubVolume temp = innerSubVolume;
            innerSubVolume = outerSubVolume;
            outerSubVolume = temp;
        }
    }
    Pair<SubVolume, SubVolume> ret = new Pair<>(innerSubVolume, outerSubVolume);
    return ret;
}
Also used : SubVolume(cbit.vcell.geometry.SubVolume) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature) Pair(org.vcell.util.Pair)

Example 14 with SubVolume

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

the class DiffEquMathMapping method refreshStructureAnalyzers.

/**
 * This method was created by a SmartGuide.
 */
private void refreshStructureAnalyzers() {
    structureAnalyzerList.removeAllElements();
    // 
    // update structureAnalyzer list if any subVolumes were added
    // 
    GeometryClass[] geometryClasses = simContext.getGeometryContext().getGeometry().getGeometryClasses();
    for (int j = 0; j < geometryClasses.length; j++) {
        if (geometryClasses[j] instanceof SubVolume) {
            SubVolume subVolume = (SubVolume) geometryClasses[j];
            if (getVolumeStructureAnalyzer(subVolume) == null) {
                structureAnalyzerList.addElement(new VolumeStructureAnalyzer(this, subVolume));
            }
        } else if (geometryClasses[j] instanceof SurfaceClass) {
            SurfaceClass surfaceClass = (SurfaceClass) geometryClasses[j];
            if (getMembraneStructureAnalyzer(surfaceClass) == null) {
                structureAnalyzerList.addElement(new MembraneStructureAnalyzer(this, surfaceClass));
            }
        }
    }
    // 
    // invoke all structuralAnalyzers
    // 
    Enumeration<StructureAnalyzer> enum1 = getStructureAnalyzers();
    while (enum1.hasMoreElements()) {
        StructureAnalyzer sa = enum1.nextElement();
        sa.refresh();
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume)

Example 15 with SubVolume

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

the class MathDescription method gatherIssues.

/**
 * This method was created in VisualAge.
 * @return boolean
 */
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
    issueContext = issueContext.newChildContext(ContextType.MathDescription, this);
    setWarning(null);
    if (geometry == null) {
        Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_NoGeometry, VCellErrorMessages.MATH_DESCRIPTION_GEOMETRY_1, Issue.SEVERITY_ERROR);
        issueList.add(issue);
    }
    if (isSpatialStoch() && geometry.getDimension() != 3) {
        Issue issue = new Issue(geometry, issueContext, IssueCategory.Smoldyn_Geometry_3DWarning, "VCell spatial stochastic models only support 3D geometry.", Issue.SEVERITY_ERROR);
        issueList.add(issue);
    }
    // check Constant are really constants
    for (int i = 0; i < variableList.size(); i++) {
        Variable var = variableList.get(i);
        if (var instanceof Constant) {
            try {
                ((Constant) var).getExpression().evaluateConstant();
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
                Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_Constant_NotANumber, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_CONSTANT, var.getExpression().infix()), Issue.SEVERITY_ERROR);
                issueList.add(issue);
            }
        }
    }
    // 
    // count number of variables of each type
    // 
    int volVarCount = 0;
    int memVarCount = 0;
    int filVarCount = 0;
    int volRegionVarCount = 0;
    int memRegionVarCount = 0;
    int filRegionVarCount = 0;
    int stochVarCount = 0;
    int pointVarCount = 0;
    for (int i = 0; i < variableList.size(); i++) {
        Variable var = variableList.get(i);
        if (var instanceof VolVariable) {
            volVarCount++;
        } else if (var instanceof MemVariable) {
            memVarCount++;
        } else if (var instanceof FilamentVariable) {
            filVarCount++;
        } else if (var instanceof VolumeRegionVariable) {
            volRegionVarCount++;
        } else if (var instanceof MembraneRegionVariable) {
            memRegionVarCount++;
        } else if (var instanceof FilamentRegionVariable) {
            filRegionVarCount++;
        } else if (var instanceof StochVolVariable) {
            stochVarCount++;
        } else if (var instanceof PointVariable) {
            pointVarCount++;
        }
    }
    // 
    for (int i = 0; i < subDomainList.size(); i++) {
        try {
            SubDomain subDomain = subDomainList.get(i);
            Enumeration<Equation> equEnum = subDomain.getEquations();
            while (equEnum.hasMoreElements()) {
                Equation equ = equEnum.nextElement();
                equ.checkValid(this, subDomain);
                equ.bind(this);
            }
            FastSystem fastSystem = subDomain.getFastSystem();
            if (fastSystem != null) {
                Enumeration<FastRate> frEnum = fastSystem.getFastRates();
                while (frEnum.hasMoreElements()) {
                    FastRate fr = frEnum.nextElement();
                    fr.bind(this);
                }
                Enumeration<FastInvariant> fiEnum = fastSystem.getFastInvariants();
                while (fiEnum.hasMoreElements()) {
                    FastInvariant fi = fiEnum.nextElement();
                    fi.bind(this);
                }
            }
            for (ParticleProperties pp : subDomain.getParticleProperties()) {
                pp.bind(this);
            }
            for (ParticleJumpProcess pjp : subDomain.getParticleJumpProcesses()) {
                pjp.bind(this);
                Expression rateDefinition = null;
                JumpProcessRateDefinition jprd = pjp.getParticleRateDefinition();
                if (jprd instanceof MacroscopicRateConstant) {
                    rateDefinition = MathUtilities.substituteFunctions(((MacroscopicRateConstant) jprd).getExpression(), this);
                } else if (jprd instanceof InteractionRadius) {
                    rateDefinition = MathUtilities.substituteFunctions(((InteractionRadius) jprd).getExpression(), this);
                } else {
                    new RuntimeException("The jump process rate definition is not supported");
                }
                String[] symbols = rateDefinition.getSymbols();
                if (symbols != null) {
                    for (String symbol : symbols) {
                        // throw exception for particle variables, particle variable cannot be referenced
                        Variable var = getVariable(symbol);
                        if (var instanceof ParticleVariable) {
                            throw new MathException("Stochastic variables can not be referenced in functions and equations.");
                        }
                        if (subDomain instanceof CompartmentSubDomain) {
                            if ((var instanceof MembraneRegionVariable || var instanceof MemVariable)) {
                                throw new MathException("Volume reaction: " + pjp.getName() + " cannot reference membrane variable: " + var.getName() + ".");
                            }
                        }
                    }
                }
            }
        } catch (ExpressionBindingException e) {
            Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_ExpressionBindingException, e.getMessage(), Issue.SEVERITY_ERROR);
            issueList.add(issue);
        } catch (ExpressionException e) {
            Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_ExpressionException, e.getMessage(), Issue.SEVERITY_ERROR);
            issueList.add(issue);
        } catch (MathException e) {
            Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_MathException, e.getMessage(), Issue.SEVERITY_ERROR);
            issueList.add(issue);
        }
    }
    // 
    if (geometry.getDimension() == 0) {
        // 
        if (subDomainList.size() != 1) {
            Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_1, Issue.SEVERITY_ERROR);
            issueList.add(issue);
        } else if (subDomainList.size() == 1) {
            if (!(subDomainList.get(0) instanceof CompartmentSubDomain)) {
                Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_2, Issue.SEVERITY_ERROR);
                issueList.add(issue);
            }
            CompartmentSubDomain subDomain = (CompartmentSubDomain) subDomainList.get(0);
            // distinguish ODE model and stochastic model
            if (isNonSpatialStoch()) {
                if (stochVarCount == 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_StochasticModel, VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_STOCHASTIC_MODEL_1, Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (subDomain.getJumpProcesses().size() == 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_StochasticModel, VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_STOCHASTIC_MODEL_2, Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                // check variable initial condition
                for (VarIniCondition varIniCondition : subDomain.getVarIniConditions()) {
                    Expression iniExp = varIniCondition.getIniVal();
                    try {
                        iniExp.bindExpression(this);
                    } catch (Exception ex) {
                        ex.printStackTrace(System.out);
                        setWarning(ex.getMessage());
                    }
                }
                // check probability rate
                for (JumpProcess jumpProcess : subDomain.getJumpProcesses()) {
                    Expression probExp = jumpProcess.getProbabilityRate();
                    try {
                        probExp.bindExpression(this);
                    } catch (Exception ex) {
                        ex.printStackTrace(System.out);
                        setWarning(ex.getMessage());
                    }
                }
            } else if (isRuleBased()) {
            } else {
                // ODE model
                // 
                // Check that all equations are ODEs
                // 
                int odeCount = 0;
                Enumeration<Equation> enum_equ = subDomain.getEquations();
                while (enum_equ.hasMoreElements()) {
                    Equation equ = enum_equ.nextElement();
                    if (equ instanceof OdeEquation) {
                        odeCount++;
                    } else {
                        Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_3, Issue.SEVERITY_ERROR);
                        issueList.add(issue);
                    }
                }
                if (odeCount == 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_4, Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (volVarCount != odeCount) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_5, Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (memVarCount > 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_6, VCML.MembraneVariable), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (filVarCount > 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_6, VCML.FilamentVariable), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (volRegionVarCount > 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_6, VCML.VolumeRegionVariable), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (memRegionVarCount > 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_6, VCML.MembraneRegionVariable), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (filRegionVarCount > 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_CompartmentalModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_COMPARTMENT_MODEL_6, VCML.FilamentRegionVariable), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
            }
        }
    // 
    // spatial (PDE and ODE)
    // 
    } else {
        // 
        // Check that the number of CompartmentSubdomains equals the number of VolumeSubVolumes in the Geometry
        // Check that the number of FilamentSubdomains equals the number of Filaments in the Geometry
        // 
        int compartmentCount = 0;
        int membraneCount = 0;
        int filamentCount = 0;
        int pointCount = 0;
        for (int i = 0; i < subDomainList.size(); i++) {
            SubDomain subDomain = (SubDomain) subDomainList.get(i);
            if (subDomain instanceof CompartmentSubDomain) {
                if (geometry.getGeometrySpec().getSubVolume(subDomain.getName()) == null) {
                    Issue issue = new Issue(subDomain, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_1, subDomain.getName()), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                compartmentCount++;
            } else if (subDomain instanceof MembraneSubDomain) {
                membraneCount++;
            } else if (subDomain instanceof FilamentSubDomain) {
                filamentCount++;
            } else if (subDomain instanceof PointSubDomain) {
                pointCount++;
            } else {
                Issue issue = new Issue(subDomain, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_2, subDomain.getName()), Issue.SEVERITY_ERROR);
                issueList.add(issue);
            }
        }
        if (geometry.getGeometrySpec().getNumSubVolumes() != compartmentCount) {
            Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_SpatialModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_3, geometry.getGeometrySpec().getNumSubVolumes(), compartmentCount), Issue.SEVERITY_ERROR);
            issueList.add(issue);
        }
        if (geometry.getGeometrySpec().getFilamentGroup().getFilamentCount() != filamentCount) {
        // setWarning("Spatial model, there are "+geometry.getGeometrySpec().getFilamentGroup().getFilamentCount()+" filaments in geometry, but "+filamentCount+" "+VCML.FilamentSubDomain+"'s, must be equal");
        // return false;
        }
        if (filamentCount == 0 && (filVarCount > 0 || filRegionVarCount > 0)) {
            Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_SpatialModel, VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_4, Issue.SEVERITY_ERROR);
            issueList.add(issue);
        }
        if (membraneCount == 0 && (memVarCount > 0 || memRegionVarCount > 0)) {
            Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_SpatialModel, VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_5, Issue.SEVERITY_ERROR);
            issueList.add(issue);
        }
        // 
        for (int i = 0; i < subDomainList.size(); i++) {
            SubDomain subDomain1 = (SubDomain) subDomainList.get(i);
            for (int j = 0; j < subDomainList.size(); j++) {
                if (i != j) {
                    SubDomain subDomain2 = (SubDomain) subDomainList.get(j);
                    if (subDomain1.getName().equals(subDomain2.getName())) {
                        Issue issue = new Issue(subDomain1, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_6, subDomain1.getName(), subDomain2.getName()), Issue.SEVERITY_ERROR);
                        issueList.add(issue);
                    }
                    if (subDomain1 instanceof MembraneSubDomain && subDomain2 instanceof MembraneSubDomain) {
                        MembraneSubDomain memSubDomain1 = (MembraneSubDomain) subDomain1;
                        MembraneSubDomain memSubDomain2 = (MembraneSubDomain) subDomain2;
                        if ((memSubDomain1.getInsideCompartment() == memSubDomain2.getInsideCompartment() && memSubDomain1.getOutsideCompartment() == memSubDomain2.getOutsideCompartment()) || (memSubDomain1.getInsideCompartment() == memSubDomain2.getOutsideCompartment() && memSubDomain1.getOutsideCompartment() == memSubDomain2.getInsideCompartment())) {
                            Issue issue = new Issue(subDomain1, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_7, memSubDomain1.getInsideCompartment().getName(), memSubDomain1.getOutsideCompartment().getName()), Issue.SEVERITY_ERROR);
                            issueList.add(issue);
                        }
                    }
                }
            }
        }
        // check periodic boundary conditons
        for (int i = 0; i < subDomainList.size(); i++) {
            SubDomain subDomain = (SubDomain) subDomainList.get(i);
            if (subDomain instanceof CompartmentSubDomain) {
                CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) subDomain;
                BoundaryConditionType bctM = compartmentSubDomain.getBoundaryConditionXm();
                BoundaryConditionType bctP = compartmentSubDomain.getBoundaryConditionXp();
                if (bctM.isPERIODIC() && !bctP.isPERIODIC() || !bctM.isPERIODIC() && bctP.isPERIODIC()) {
                    Issue issue = new Issue(subDomain, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_9, "Xm", "Xp", subDomain.getName()), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                bctM = compartmentSubDomain.getBoundaryConditionYm();
                bctP = compartmentSubDomain.getBoundaryConditionYp();
                if (bctM.isPERIODIC() && !bctP.isPERIODIC() || !bctM.isPERIODIC() && bctP.isPERIODIC()) {
                    Issue issue = new Issue(subDomain, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_9, "Ym", "Yp", subDomain.getName()), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                bctM = compartmentSubDomain.getBoundaryConditionZm();
                bctP = compartmentSubDomain.getBoundaryConditionZp();
                if (bctM.isPERIODIC() && !bctP.isPERIODIC() || !bctM.isPERIODIC() && bctP.isPERIODIC()) {
                    Issue issue = new Issue(subDomain, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_9, "Zm", "Zp", subDomain.getName()), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
            } else if (subDomain instanceof MembraneSubDomain) {
                MembraneSubDomain membraneSubDomain = (MembraneSubDomain) subDomain;
                BoundaryConditionType bctM = membraneSubDomain.getBoundaryConditionXm();
                BoundaryConditionType bctP = membraneSubDomain.getBoundaryConditionXp();
                if (bctM.isPERIODIC() && !bctP.isPERIODIC() || !bctM.isPERIODIC() && bctP.isPERIODIC()) {
                    Issue issue = new Issue(subDomain, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_9, "Xm", "Xp", subDomain.getName()), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                bctM = membraneSubDomain.getBoundaryConditionYm();
                bctP = membraneSubDomain.getBoundaryConditionYp();
                if (bctM.isPERIODIC() && !bctP.isPERIODIC() || !bctM.isPERIODIC() && bctP.isPERIODIC()) {
                    Issue issue = new Issue(subDomain, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_9, "Ym", "Yp", subDomain.getName()), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                bctM = membraneSubDomain.getBoundaryConditionZm();
                bctP = membraneSubDomain.getBoundaryConditionZp();
                if (bctM.isPERIODIC() && !bctP.isPERIODIC() || !bctM.isPERIODIC() && bctP.isPERIODIC()) {
                    Issue issue = new Issue(subDomain, issueContext, IssueCategory.MathDescription_SpatialModel_Subdomain, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_9, "Zm", "Zp", subDomain.getName()), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
            }
        }
        try {
            if (geometry.getGeometrySpec().getDimension() > 0) {
                // 
                // Check that there is a MembraneSubdomain for each unique subVolume-subVolume interface in Geometry
                // each ResolvedSurfaceLocation is an instance of a subVolume-subVolume interface (one-to-one with region boundaries).
                // 
                GeometricRegion[] regions = geometry.getGeometrySurfaceDescription().getGeometricRegions();
                // }
                if (regions == null) {
                    Issue issue = new Issue(geometry, issueContext, IssueCategory.MathDescription_SpatialModel_Geometry, VCellErrorMessages.MATH_DESCRIPTION_GEOMETRY_2, Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                } else {
                    for (int i = 0; i < regions.length; i++) {
                        if (regions[i] instanceof SurfaceGeometricRegion) {
                            SurfaceGeometricRegion surfaceRegion = (SurfaceGeometricRegion) regions[i];
                            SubVolume subVolume1 = ((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[0]).getSubVolume();
                            CompartmentSubDomain compartment1 = getCompartmentSubDomain(subVolume1.getName());
                            if (compartment1 == null) {
                                Issue issue = new Issue(geometry, issueContext, IssueCategory.MathDescription_SpatialModel_Geometry, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_GEOMETRY_3, getGeometry().getName(), subVolume1.getName()), Issue.SEVERITY_ERROR);
                                issueList.add(issue);
                            }
                            SubVolume subVolume2 = ((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[1]).getSubVolume();
                            CompartmentSubDomain compartment2 = getCompartmentSubDomain(subVolume2.getName());
                            if (compartment2 == null) {
                                Issue issue = new Issue(geometry, issueContext, IssueCategory.MathDescription_SpatialModel_Geometry, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_GEOMETRY_3, getGeometry().getName(), subVolume2.getName()), Issue.SEVERITY_ERROR);
                                issueList.add(issue);
                            }
                            MembraneSubDomain membraneSubDomain = getMembraneSubDomain(compartment1, compartment2);
                            if (compartment2 != null && compartment1 != null && membraneSubDomain == null) {
                                Issue issue = new Issue(geometry, issueContext, IssueCategory.MathDescription_SpatialModel_Geometry, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_GEOMETRY_4, compartment1.getName(), compartment2.getName()), Issue.SEVERITY_ERROR);
                                issueList.add(issue);
                            }
                        }
                    }
                    // 
                    for (int i = 0; i < subDomainList.size(); i++) {
                        if (subDomainList.get(i) instanceof MembraneSubDomain) {
                            MembraneSubDomain membraneSubDomain = (MembraneSubDomain) subDomainList.get(i);
                            boolean bFoundSurfaceInGeometry = false;
                            for (int j = 0; j < regions.length; j++) {
                                if (regions[j] instanceof SurfaceGeometricRegion) {
                                    SurfaceGeometricRegion surfaceRegion = (SurfaceGeometricRegion) regions[j];
                                    VolumeGeometricRegion volumeRegion1 = (VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[0];
                                    VolumeGeometricRegion volumeRegion2 = (VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[1];
                                    String memInsideName = membraneSubDomain.getInsideCompartment().getName();
                                    String memOutsideName = membraneSubDomain.getOutsideCompartment().getName();
                                    if ((memInsideName.equals(volumeRegion1.getSubVolume().getName()) && memOutsideName.equals(volumeRegion2.getSubVolume().getName())) || (memInsideName.equals(volumeRegion2.getSubVolume().getName()) && memOutsideName.equals(volumeRegion1.getSubVolume().getName()))) {
                                        bFoundSurfaceInGeometry = true;
                                        break;
                                    }
                                }
                            }
                            if (!bFoundSurfaceInGeometry) {
                                Issue issue = new Issue(geometry, issueContext, IssueCategory.MathDescription_SpatialModel_Geometry, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_GEOMETRY_5, membraneSubDomain.getInsideCompartment().getName(), membraneSubDomain.getOutsideCompartment().getName()), Issue.SEVERITY_ERROR);
                                issueList.add(issue);
                            }
                        }
                    }
                }
            }
        // }catch (GeometryException e){
        // e.printStackTrace(System.out);
        // setWarning("error validating MathDescription: "+e.getMessage());
        // return false;
        // }catch (ImageException e){
        // e.printStackTrace(System.out);
        // setWarning("error validating MathDescription: "+e.getMessage());
        // return false;
        // }catch (ExpressionException e){
        // e.printStackTrace(System.out);
        // setWarning("error validating MathDescription: "+e.getMessage());
        // return false;
        } catch (Exception e) {
            e.printStackTrace(System.out);
            Issue issue = new Issue(geometry, issueContext, IssueCategory.MathDescription_SpatialModel_Geometry, e.getMessage(), Issue.SEVERITY_ERROR);
            issueList.add(issue);
        }
        // 
        for (int i = 0; i < variableList.size(); i++) {
            Variable var = variableList.get(i);
            String varName = var.getName();
            if (var instanceof VolVariable) {
                VolVariable volVar = (VolVariable) var;
                int pdeRefCount = 0;
                int odeRefCount = 0;
                int steadyPdeCount = 0;
                int measureCount = 0;
                for (int j = 0; j < subDomainList.size(); j++) {
                    SubDomain subDomain = subDomainList.get(j);
                    Equation equ = subDomain.getEquation(volVar);
                    if (equ instanceof PdeEquation) {
                        if (((PdeEquation) equ).isSteady()) {
                            steadyPdeCount++;
                        } else {
                            pdeRefCount++;
                        }
                        // 
                        for (int k = 0; k < subDomainList.size(); k++) {
                            SubDomain subDomain2 = subDomainList.get(k);
                            if (subDomain2 instanceof MembraneSubDomain) {
                                MembraneSubDomain membraneSubDomain = (MembraneSubDomain) subDomain2;
                                if (membraneSubDomain.getInsideCompartment() == subDomain || membraneSubDomain.getOutsideCompartment() == subDomain) {
                                    JumpCondition jumpCondition = membraneSubDomain.getJumpCondition(volVar);
                                    BoundaryConditionValue boundaryValue = ((PdeEquation) equ).getBoundaryConditionValue(membraneSubDomain.getName());
                                    // if PDE variable does not have jump condition OR boundaryValue (neither or both are not allowed), its an error.
                                    if ((jumpCondition == null && boundaryValue == null) || (jumpCondition != null && boundaryValue != null)) {
                                        Issue issue = new Issue(equ, issueContext, IssueCategory.MathDescription_SpatialModel_Equation, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_10, varName, subDomain.getName(), membraneSubDomain.getName()), Issue.SEVERITY_ERROR);
                                        issueList.add(issue);
                                    }
                                    if (boundaryValue != null && (subDomain.getBoundaryConditionSpec(membraneSubDomain.getName()) == null)) {
                                        Issue issue = new Issue(equ, issueContext, IssueCategory.MathDescription_SpatialModel_Equation, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_10A, varName, subDomain.getName(), membraneSubDomain.getName(), membraneSubDomain.getName(), subDomain.getName()), Issue.SEVERITY_ERROR);
                                        issueList.add(issue);
                                    }
                                }
                            }
                        }
                    } else if (equ instanceof OdeEquation) {
                        odeRefCount++;
                    } else if (equ instanceof MeasureEquation) {
                        measureCount++;
                    }
                    // 
                    if (subDomain instanceof MembraneSubDomain) {
                        MembraneSubDomain memSubDomain = (MembraneSubDomain) subDomain;
                        JumpCondition jumpCondition = memSubDomain.getJumpCondition(volVar);
                        if (jumpCondition != null) {
                            boolean bInsidePresent = (memSubDomain.getInsideCompartment().getEquation(volVar) instanceof PdeEquation);
                            boolean bOutsidePresent = (memSubDomain.getOutsideCompartment().getEquation(volVar) instanceof PdeEquation);
                            if (!bInsidePresent && !bOutsidePresent) {
                                Issue issue = new Issue(equ, issueContext, IssueCategory.MathDescription_SpatialModel_Equation, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_11, varName, memSubDomain.getName(), memSubDomain.getInsideCompartment().getName(), memSubDomain.getOutsideCompartment().getName()), Issue.SEVERITY_ERROR);
                                issueList.add(issue);
                            }
                            // 
                            if (!bInsidePresent && !jumpCondition.getInFluxExpression().isZero()) {
                                Issue issue = new Issue(equ, issueContext, IssueCategory.MathDescription_SpatialModel_Equation, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_12, varName, memSubDomain.getName(), memSubDomain.getInsideCompartment().getName()), Issue.SEVERITY_ERROR);
                                issueList.add(issue);
                            }
                            if (!bOutsidePresent && !jumpCondition.getOutFluxExpression().isZero()) {
                                Issue issue = new Issue(equ, issueContext, IssueCategory.MathDescription_SpatialModel_Equation, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_13, varName, memSubDomain.getName(), memSubDomain.getOutsideCompartment().getName()), Issue.SEVERITY_ERROR);
                                issueList.add(issue);
                            }
                        }
                    }
                }
                if (odeRefCount > 0 && pdeRefCount > 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_SpatialModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_14, varName), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (steadyPdeCount > 0 && pdeRefCount > 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_SpatialModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_15, varName), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (odeRefCount == 0 && pdeRefCount == 0 && steadyPdeCount == 0 && measureCount == 0) {
                    Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_SpatialModel, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_16, varName), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
            } else // 
            if (var instanceof MemVariable) {
                int pdeRefCount = 0;
                int odeRefCount = 0;
                int steadyPdeCount = 0;
                for (int j = 0; j < subDomainList.size(); j++) {
                    SubDomain subDomain = subDomainList.get(j);
                    Equation equ = subDomain.getEquation(var);
                    if (equ instanceof PdeEquation) {
                        if (((PdeEquation) equ).isSteady()) {
                            steadyPdeCount++;
                        } else {
                            pdeRefCount++;
                        }
                    } else if (equ instanceof OdeEquation) {
                        odeRefCount++;
                    }
                }
                if (odeRefCount > 0 && pdeRefCount > 0) {
                    Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_SpatialModel_Variable, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_14, varName), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (steadyPdeCount > 0 && pdeRefCount > 0) {
                    Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_SpatialModel_Variable, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_15, varName), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
                if (odeRefCount == 0 && pdeRefCount == 0 && steadyPdeCount == 0) {
                    Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_SpatialModel_Variable, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_16, varName), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
            } else // 
            if (var instanceof FilamentVariable) {
                for (int j = 0; j < subDomainList.size(); j++) {
                    SubDomain subDomain = subDomainList.get(j);
                    if (subDomain instanceof FilamentSubDomain) {
                        Equation equ = subDomain.getEquation(var);
                        if (!(equ instanceof OdeEquation)) {
                            Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_SpatialModel_Variable, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_21, varName, subDomain.getName()), Issue.SEVERITY_ERROR);
                            issueList.add(issue);
                        }
                    }
                }
            } else // 
            if (var instanceof VolumeRegionVariable) {
                VolumeRegionVariable volRegionVar = (VolumeRegionVariable) var;
                int count = 0;
                for (int j = 0; j < subDomainList.size(); j++) {
                    SubDomain subDomain = subDomainList.get(j);
                    if (subDomain instanceof CompartmentSubDomain) {
                        Equation equ = subDomain.getEquation(volRegionVar);
                        if (equ instanceof VolumeRegionEquation) {
                            count++;
                            // 
                            for (int k = 0; k < subDomainList.size(); k++) {
                                SubDomain subDomain2 = subDomainList.get(k);
                                if (subDomain2 instanceof MembraneSubDomain) {
                                    MembraneSubDomain membraneSubDomain = (MembraneSubDomain) subDomain2;
                                    if (membraneSubDomain.getInsideCompartment() == subDomain || membraneSubDomain.getOutsideCompartment() == subDomain) {
                                        if (membraneSubDomain.getJumpCondition(volRegionVar) == null) {
                                            Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_SpatialModel_Variable, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_17, varName, subDomain.getName(), membraneSubDomain.getName()), Issue.SEVERITY_ERROR);
                                            issueList.add(issue);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (count == 0) {
                    Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_SpatialModel_Variable, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_18, varName), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
            } else // 
            if (var instanceof MembraneRegionVariable) {
                int count = 0;
                for (int j = 0; j < subDomainList.size(); j++) {
                    SubDomain subDomain = subDomainList.get(j);
                    if (subDomain instanceof MembraneSubDomain) {
                        Equation equ = subDomain.getEquation(var);
                        if (equ instanceof MembraneRegionEquation) {
                            count++;
                        }
                    }
                }
                if (count == 0) {
                    Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_SpatialModel_Variable, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_19, varName), Issue.SEVERITY_ERROR);
                    issueList.add(issue);
                }
            } else // 
            if (var instanceof FilamentRegionVariable) {
                for (int j = 0; j < subDomainList.size(); j++) {
                    SubDomain subDomain = subDomainList.get(j);
                    if (subDomain instanceof FilamentSubDomain) {
                        Equation equ = subDomain.getEquation(var);
                        if (!(equ instanceof FilamentRegionEquation)) {
                            Issue issue = new Issue(var, issueContext, IssueCategory.MathDescription_SpatialModel_Variable, VCellErrorMessages.getErrorMessage(VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_20, varName, subDomain.getName()), Issue.SEVERITY_ERROR);
                            issueList.add(issue);
                        }
                    }
                }
            }
        }
    }
    if (eventList.size() > 0 && isSpatial()) {
        Issue issue = new Issue(this, issueContext, IssueCategory.MathDescription_SpatialModel, VCellErrorMessages.MATH_DESCRIPTION_SPATIAL_MODEL_22, Issue.SEVERITY_ERROR);
        issueList.add(issue);
    }
    for (Event event : eventList) {
        try {
            event.bind(this);
        } catch (ExpressionBindingException e) {
            Issue issue = new Issue(event, issueContext, IssueCategory.MathDescription_SpatialModel_Event, e.getMessage(), Issue.SEVERITY_ERROR);
            issueList.add(issue);
        }
    }
    for (DataGenerator dataGenerator : postProcessingBlock.getDataGeneratorList()) {
        try {
            dataGenerator.bind(this);
        } catch (ExpressionBindingException e) {
            Issue issue = new Issue(dataGenerator, issueContext, IssueCategory.MathDescription_SpatialModel_PostProcessingBlock, e.getMessage(), Issue.SEVERITY_ERROR);
            issueList.add(issue);
        }
    }
}
Also used : Issue(org.vcell.util.Issue) ExpressionException(cbit.vcell.parser.ExpressionException) SubVolume(cbit.vcell.geometry.SubVolume) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) NoSuchElementException(java.util.NoSuchElementException) ExpressionException(cbit.vcell.parser.ExpressionException) BoundaryConditionValue(cbit.vcell.math.PdeEquation.BoundaryConditionValue) Expression(cbit.vcell.parser.Expression) ChangeEvent(javax.swing.event.ChangeEvent)

Aggregations

SubVolume (cbit.vcell.geometry.SubVolume)84 SurfaceClass (cbit.vcell.geometry.SurfaceClass)42 Expression (cbit.vcell.parser.Expression)33 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)26 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)22 GeometryClass (cbit.vcell.geometry.GeometryClass)21 ArrayList (java.util.ArrayList)21 Geometry (cbit.vcell.geometry.Geometry)20 MathDescription (cbit.vcell.math.MathDescription)17 SpeciesContext (cbit.vcell.model.SpeciesContext)17 PropertyVetoException (java.beans.PropertyVetoException)17 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)16 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)15 Model (cbit.vcell.model.Model)15 ImageException (cbit.image.ImageException)14 VCImage (cbit.image.VCImage)14 Feature (cbit.vcell.model.Feature)14 Structure (cbit.vcell.model.Structure)14 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)13 ExpressionException (cbit.vcell.parser.ExpressionException)13