use of cbit.vcell.geometry.surface.VolumeGeometricRegion in project vcell by virtualcell.
the class MathModel_SBMLExporter method addGeometry.
private static void addGeometry(Model sbmlModel, MathModel vcMathModel) {
SpatialModelPlugin mplugin = (SpatialModelPlugin) sbmlModel.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
// Creates a geometry object via SpatialModelPlugin object.
org.sbml.jsbml.ext.spatial.Geometry sbmlGeometry = mplugin.getGeometry();
sbmlGeometry.setCoordinateSystem(GeometryKind.cartesian);
Geometry vcGeometry = vcMathModel.getGeometry();
//
// list of CoordinateComponents : 1 if geometry is 1-d, 2 if geometry is 2-d, 3 if geometry is 3-d
//
int dimension = vcGeometry.getDimension();
Extent vcExtent = vcGeometry.getExtent();
Origin vcOrigin = vcGeometry.getOrigin();
// add x coordinate component
CoordinateComponent coordCompX = sbmlGeometry.createCoordinateComponent();
coordCompX.setSpatialId("CoordCompX");
coordCompX.setType(CoordinateKind.cartesianX);
Boundary minX = coordCompX.getBoundaryMaximum();
minX.setSpatialId("Xmin");
minX.setValue(vcOrigin.getX());
Boundary maxX = coordCompX.getBoundaryMaximum();
maxX.setSpatialId("Xmax");
maxX.setValue(vcOrigin.getX() + (vcExtent.getX()));
Parameter parameterX = sbmlModel.createParameter();
// note for exporting BioModels rather than MathModels, get ReservedSymbol from Model with Role of ReservedSymbolRole.X
parameterX.setId(ReservedVariable.X.getName());
SpatialSymbolReference coordXSpatialRef = new SpatialSymbolReference();
coordXSpatialRef.setSpatialRef(coordCompX.getSpatialId());
SpatialParameterPlugin parameterXSpatialPlugin = (SpatialParameterPlugin) parameterX.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
parameterXSpatialPlugin.setParamType(coordXSpatialRef);
// add y coordinate component
if (dimension == 2 || dimension == 3) {
CoordinateComponent coordCompY = sbmlGeometry.createCoordinateComponent();
coordCompY.setSpatialId("CoordCompY");
coordCompY.setType(CoordinateKind.cartesianY);
Boundary minY = coordCompY.getBoundaryMinimum();
minY.setId("Ymin");
minY.setValue(vcOrigin.getY());
Boundary maxY = coordCompY.getBoundaryMaximum();
maxY.setId("Ymax");
maxY.setValue(vcOrigin.getY() + (vcExtent.getY()));
Parameter parameterY = sbmlModel.createParameter();
// note for exporting BioModels rather than MathModels, get ReservedSymbol from Model with Role of ReservedSymbolRole.Y
parameterY.setId(ReservedVariable.Y.getName());
SpatialSymbolReference coordYSpatialRef = new SpatialSymbolReference();
coordYSpatialRef.setSpatialRef(coordCompY.getSpatialId());
SpatialParameterPlugin parameterYSpatialPlugin = (SpatialParameterPlugin) parameterY.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
parameterYSpatialPlugin.setParamType(coordYSpatialRef);
}
// add z coordinate component
if (dimension == 3) {
CoordinateComponent coordCompZ = sbmlGeometry.createCoordinateComponent();
coordCompZ.setSpatialId("CoordCompZ");
coordCompZ.setType(CoordinateKind.cartesianZ);
Boundary minZ = coordCompZ.getBoundaryMinimum();
minZ.setId("Zmin");
minZ.setValue(vcOrigin.getZ());
Boundary maxZ = coordCompZ.getBoundaryMaximum();
maxZ.setId("Zmax");
maxZ.setValue(vcOrigin.getZ() + (vcExtent.getZ()));
Parameter parameterZ = sbmlModel.createParameter();
// note for exporting BioModels rather than MathModels, get ReservedSymbol from Model with Role of ReservedSymbolRole.Y
parameterZ.setId(ReservedVariable.Z.getName());
SpatialSymbolReference coordZSpatialRef = new SpatialSymbolReference();
coordZSpatialRef.setSpatialRef(coordCompZ.getSpatialId());
SpatialParameterPlugin parameterZSpatialPlugin = (SpatialParameterPlugin) parameterZ.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
parameterZSpatialPlugin.setParamType(coordZSpatialRef);
}
//
// list of domain types : subvolumes and surface classes from VC
// Also create compartments - one compartment for each geometryClass. set id and spatialDimension based on type of geometryClass.
//
boolean bAnalyticGeom = false;
boolean bImageGeom = false;
GeometryClass[] vcGeomClasses = vcGeometry.getGeometryClasses();
int numVCGeomClasses = vcGeomClasses.length;
for (int i = 0; i < numVCGeomClasses; i++) {
DomainType domainType = sbmlGeometry.createDomainType();
domainType.setId(vcGeomClasses[i].getName());
if (vcGeomClasses[i] instanceof SubVolume) {
if (((SubVolume) vcGeomClasses[i]) instanceof AnalyticSubVolume) {
bAnalyticGeom = true;
} else if (((SubVolume) vcGeomClasses[i]) instanceof ImageSubVolume) {
bImageGeom = true;
}
domainType.setSpatialDimensions(3);
} else if (vcGeomClasses[i] instanceof SurfaceClass) {
domainType.setSpatialDimensions(2);
}
}
//
// list of domains, adjacent domains : from VC geometricRegions
//
GeometrySurfaceDescription vcGSD = vcGeometry.getGeometrySurfaceDescription();
if (vcGSD.getRegionImage() == null) {
try {
vcGSD.updateAll();
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Unable to generate region images for geometry");
}
}
GeometricRegion[] vcGeometricRegions = vcGSD.getGeometricRegions();
ISize sampleSize = vcGSD.getVolumeSampleSize();
int numX = sampleSize.getX();
int numY = sampleSize.getY();
int numZ = sampleSize.getZ();
double ox = vcOrigin.getX();
double oy = vcOrigin.getY();
double oz = vcOrigin.getZ();
RegionInfo[] regionInfos = vcGSD.getRegionImage().getRegionInfos();
Compartment compartment = null;
for (int i = 0; i < vcGeometricRegions.length; i++) {
// domains
Domain domain = sbmlGeometry.createDomain();
domain.setId(vcGeometricRegions[i].getName());
compartment = sbmlModel.createCompartment();
compartment.setId("compartment" + i);
if (vcGeometricRegions[i] instanceof VolumeGeometricRegion) {
domain.setDomainType(((VolumeGeometricRegion) vcGeometricRegions[i]).getSubVolume().getName());
// domain.setImplicit(false);
compartment.setSpatialDimensions(3);
InteriorPoint interiorPt = domain.createInteriorPoint();
int regionID = ((VolumeGeometricRegion) vcGeometricRegions[i]).getRegionID();
boolean bFound = false;
int regInfoIndx = 0;
for (int j = 0; j < regionInfos.length; j++) {
regInfoIndx = j;
if (regionInfos[j].getRegionIndex() == regionID) {
int volIndx = 0;
for (int z = 0; z < numZ && !bFound; z++) {
for (int y = 0; y < numY && !bFound; y++) {
for (int x = 0; x < numX && !bFound; x++) {
if (regionInfos[j].isIndexInRegion(volIndx)) {
bFound = true;
double unit_z = (numZ > 1) ? ((double) z) / (numZ - 1) : 0.5;
double coordZ = oz + vcExtent.getZ() * unit_z;
double unit_y = (numY > 1) ? ((double) y) / (numY - 1) : 0.5;
double coordY = oy + vcExtent.getY() * unit_y;
double unit_x = (numX > 1) ? ((double) x) / (numX - 1) : 0.5;
double coordX = ox + vcExtent.getX() * unit_x;
interiorPt.setCoord1(coordX);
interiorPt.setCoord2(coordY);
interiorPt.setCoord3(coordZ);
}
volIndx++;
}
// end - for x
}
// end - for y
}
// end - for z
}
// end if
}
// end for regionInfos
if (!bFound) {
throw new RuntimeException("Unable to find interior point for region '" + regionInfos[regInfoIndx].toString());
}
} else if (vcGeometricRegions[i] instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion vcSurfaceGeomReg = (SurfaceGeometricRegion) vcGeometricRegions[i];
GeometricRegion geomRegion0 = vcSurfaceGeomReg.getAdjacentGeometricRegions()[0];
GeometricRegion geomRegion1 = vcSurfaceGeomReg.getAdjacentGeometricRegions()[1];
SurfaceClass surfaceClass = vcGSD.getSurfaceClass(((VolumeGeometricRegion) geomRegion0).getSubVolume(), ((VolumeGeometricRegion) geomRegion1).getSubVolume());
domain.setDomainType(surfaceClass.getName());
// domain.setImplicit(true);
compartment.setSpatialDimensions(2);
// adjacent domains : 2 adjacent domain objects for each surfaceClass in VC.
// adjacent domain 1
AdjacentDomains adjDomain = sbmlGeometry.createAdjacentDomain();
adjDomain.setId(TokenMangler.mangleToSName(vcSurfaceGeomReg.getName() + "_" + geomRegion0.getName()));
adjDomain.setDomain1(vcSurfaceGeomReg.getName());
adjDomain.setDomain2(geomRegion0.getName());
// adjacent domain 2
adjDomain = sbmlGeometry.createAdjacentDomain();
adjDomain.setId(TokenMangler.mangleToSName(vcSurfaceGeomReg.getName() + "_" + geomRegion1.getName()));
adjDomain.setDomain1(vcSurfaceGeomReg.getName());
adjDomain.setDomain2(geomRegion1.getName());
}
//
// Mathmodel does not have structureMapping, hence creating compartmentMapping while creating domains.
// @TODO : how to assign unitSize for compartmentMapping?
//
SpatialCompartmentPlugin cplugin = (SpatialCompartmentPlugin) compartment.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
CompartmentMapping compMapping = cplugin.getCompartmentMapping();
String compMappingId = TokenMangler.mangleToSName(domain.getDomainType() + "_" + compartment.getId());
compMapping.setId(compMappingId);
compMapping.setDomainType(TokenMangler.mangleToSName(domain.getDomainType()));
// try {
// compMapping.setUnitSize(1.0);
// } catch (ExpressionException e) {
// e.printStackTrace(System.out);
// throw new RuntimeException("Unable to create compartment mapping for structureMapping '" + compMapping.getId() +"' : " + e.getMessage());
// }
}
AnalyticGeometry sbmlAnalyticGeom = null;
SampledFieldGeometry sbmlSFGeom = null;
// both image and analytic subvolumes?? == not handled in SBML at this time.
if (bAnalyticGeom && !bImageGeom) {
sbmlAnalyticGeom = sbmlGeometry.createAnalyticGeometry();
sbmlAnalyticGeom.setId(TokenMangler.mangleToSName(vcGeometry.getName()));
} else if (bImageGeom && !bAnalyticGeom) {
// assuming image based geometry if not analytic geometry
sbmlSFGeom = sbmlGeometry.createSampledFieldGeometry();
sbmlSFGeom.setId(TokenMangler.mangleToSName(vcGeometry.getName()));
} else if (bAnalyticGeom && bImageGeom) {
throw new RuntimeException("Export to SBML of a combination of Image-based and Analytic geometries is not supported yet.");
} else if (!bAnalyticGeom && !bImageGeom) {
throw new RuntimeException("Unknown geometry type.");
}
//
for (int i = 0; i < vcGeomClasses.length; i++) {
if (vcGeomClasses[i] instanceof AnalyticSubVolume) {
// add analytiVols to sbmlAnalyticGeometry
if (sbmlAnalyticGeom != null) {
AnalyticVolume analyticVol = sbmlAnalyticGeom.createAnalyticVolume();
analyticVol.setId(vcGeomClasses[i].getName());
analyticVol.setDomainType(vcGeomClasses[i].getName());
analyticVol.setFunctionType(FunctionKind.layered);
analyticVol.setOrdinal(i);
Expression expr = ((AnalyticSubVolume) vcGeomClasses[i]).getExpression();
try {
String mathMLStr = ExpressionMathMLPrinter.getMathML(expr, true);
ASTNode mathMLNode = ASTNode.readMathMLFromString(mathMLStr);
analyticVol.setMath(mathMLNode);
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error converting VC subvolume expression to mathML" + e.getMessage());
}
} else {
throw new RuntimeException("SBML AnalyticGeometry is null.");
}
} else if (vcGeomClasses[i] instanceof ImageSubVolume) {
// add sampledVols to sbmlSFGeometry
if (sbmlSFGeom != null) {
SampledVolume sampledVol = sbmlSFGeom.createSampledVolume();
sampledVol.setId(vcGeomClasses[i].getName());
sampledVol.setDomainType(vcGeomClasses[i].getName());
sampledVol.setSampledValue(((ImageSubVolume) vcGeomClasses[i]).getPixelValue());
} else {
throw new RuntimeException("SBML SampledFieldGeometry is null.");
}
}
}
if (sbmlSFGeom != null) {
// add sampledField to sampledFieldGeometry
SampledField sampledField = sbmlGeometry.createSampledField();
VCImage vcImage = vcGeometry.getGeometrySpec().getImage();
sampledField.setId(vcImage.getName());
sampledField.setNumSamples1(vcImage.getNumX());
if (vcImage.getNumY() > 1) {
sampledField.setNumSamples2(vcImage.getNumY());
}
if (vcImage.getNumZ() > 1) {
sampledField.setNumSamples3(vcImage.getNumZ());
}
sampledField.setInterpolationType(InterpolationKind.nearestneighbor);
sampledField.setDataType(DataKind.UINT8);
// add image from vcGeometrySpec to sampledField.
try {
StringBuffer sb = new StringBuffer();
byte[] imagePixelsBytes = vcImage.getPixelsCompressed();
for (int i = 0; i < imagePixelsBytes.length; i++) {
int uint8_sample = ((int) imagePixelsBytes[i]) & 0xff;
sb.append(uint8_sample + " ");
}
sampledField.setSamplesLength(vcImage.getNumXYZ());
sampledField.setSamples(sb.toString().trim());
} catch (ImageException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Unable to export image from VCell to SBML : " + e.getMessage());
}
}
}
use of cbit.vcell.geometry.surface.VolumeGeometricRegion in project vcell by virtualcell.
the class Xmlproducer method getXML.
private Element getXML(GeometrySurfaceDescription param) throws XmlParseException {
Element gsd = new Element(XMLTags.SurfaceDescriptionTag);
// add attributes
ISize isize = param.getVolumeSampleSize();
if (isize == null) {
throw new XmlParseException("Unable to retrieve dimensions for surface descriptions for Geometry: " + param.getGeometry().getName());
}
gsd.setAttribute(XMLTags.NumSamplesXAttrTag, String.valueOf(isize.getX()));
gsd.setAttribute(XMLTags.NumSamplesYAttrTag, String.valueOf(isize.getY()));
gsd.setAttribute(XMLTags.NumSamplesZAttrTag, String.valueOf(isize.getZ()));
Double coFrequency = param.getFilterCutoffFrequency();
if (coFrequency == null) {
throw new XmlParseException("Unable to retrieve cutoff frequency for surface descriptions for Geometry: " + param.getGeometry().getName());
}
double cutoffFrequency = coFrequency.doubleValue();
gsd.setAttribute(XMLTags.CutoffFrequencyAttrTag, String.valueOf(cutoffFrequency));
// add subelements
GeometricRegion[] geomRegions = param.getGeometricRegions();
if (geomRegions != null) {
for (int i = 0; i < geomRegions.length; i++) {
if (geomRegions[i] instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion sgr = (SurfaceGeometricRegion) geomRegions[i];
Element membraneRegion = new Element(XMLTags.MembraneRegionTag);
membraneRegion.setAttribute(XMLTags.NameAttrTag, sgr.getName());
GeometricRegion[] adjacents = sgr.getAdjacentGeometricRegions();
if (adjacents == null || adjacents.length != 2) {
throw new XmlParseException("Wrong number of adjacent regions for surface descriptions for location: " + sgr.getName() + " in Geometry: " + param.getGeometry().getName());
}
membraneRegion.setAttribute(XMLTags.VolumeRegion_1AttrTag, adjacents[0].getName());
membraneRegion.setAttribute(XMLTags.VolumeRegion_2AttrTag, adjacents[1].getName());
double size = sgr.getSize();
if (size != -1) {
membraneRegion.setAttribute(XMLTags.SizeAttrTag, String.valueOf(size));
VCUnitDefinition unit = sgr.getSizeUnit();
if (unit != null) {
membraneRegion.setAttribute(XMLTags.VCUnitDefinitionAttrTag, unit.getSymbol());
}
}
gsd.addContent(membraneRegion);
} else if (geomRegions[i] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion vgr = (VolumeGeometricRegion) geomRegions[i];
Element volumeRegion = new Element(XMLTags.VolumeRegionTag);
volumeRegion.setAttribute(XMLTags.NameAttrTag, vgr.getName());
volumeRegion.setAttribute(XMLTags.RegionIDAttrTag, String.valueOf(vgr.getRegionID()));
volumeRegion.setAttribute(XMLTags.SubVolumeAttrTag, vgr.getSubVolume().getName());
double size = vgr.getSize();
if (size != -1) {
volumeRegion.setAttribute(XMLTags.SizeAttrTag, String.valueOf(size));
VCUnitDefinition unit = vgr.getSizeUnit();
if (unit != null) {
volumeRegion.setAttribute(XMLTags.VCUnitDefinitionAttrTag, unit.getSymbol());
}
}
gsd.addContent(volumeRegion);
}
}
}
return gsd;
}
use of cbit.vcell.geometry.surface.VolumeGeometricRegion in project vcell by virtualcell.
the class VolumeRegionObject method gatherIssues.
@Override
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
if (simulationContext.getGeometry().getGeometrySurfaceDescription() != null && simulationContext.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() != null) {
GeometricRegion[] regions = simulationContext.getGeometry().getGeometrySurfaceDescription().getGeometricRegions();
boolean bFound = false;
for (GeometricRegion region : regions) {
if (region instanceof VolumeGeometricRegion) {
VolumeGeometricRegion vr = (VolumeGeometricRegion) region;
if (getSubVolume() == vr.getSubVolume() && getRegionID() == vr.getRegionID()) {
bFound = true;
break;
}
}
}
if (!bFound) {
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "geometry missing volume region (subvolume " + subVolume.getName() + " region " + regionID + ")", Issue.Severity.ERROR));
}
}
}
use of cbit.vcell.geometry.surface.VolumeGeometricRegion 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);
}
}
}
use of cbit.vcell.geometry.surface.VolumeGeometricRegion in project vcell by virtualcell.
the class CartesianMesh method createSimpleCartesianMesh.
public static CartesianMesh createSimpleCartesianMesh(Geometry geometry, Map<Polygon, MembraneElement> polygonMembaneElementMap) throws IOException, MathFormatException {
GeometrySurfaceDescription geometrySurfaceDescription = geometry.getGeometrySurfaceDescription();
RegionImage regionImage = geometrySurfaceDescription.getRegionImage();
ISize iSize = new ISize(regionImage.getNumX(), regionImage.getNumY(), regionImage.getNumZ());
CartesianMesh mesh = createSimpleCartesianMesh(geometry.getOrigin(), geometry.getExtent(), iSize, regionImage);
GeometricRegion[] geometricRegions = geometrySurfaceDescription.getGeometricRegions();
if (geometricRegions != null) {
int memRegionCount = 0;
for (int i = 0; i < geometricRegions.length; i++) {
if (geometricRegions[i] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion vgr = (VolumeGeometricRegion) geometricRegions[i];
mesh.meshRegionInfo.mapVolumeRegionToSubvolume(vgr.getRegionID(), vgr.getSubVolume().getHandle(), vgr.getSize(), vgr.getName());
} else if (geometricRegions[i] instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion sgr = (SurfaceGeometricRegion) geometricRegions[i];
GeometricRegion[] neighbors = sgr.getAdjacentGeometricRegions();
VolumeGeometricRegion insideRegion = (VolumeGeometricRegion) neighbors[0];
VolumeGeometricRegion outsideRegion = (VolumeGeometricRegion) neighbors[1];
mesh.meshRegionInfo.mapMembraneRegionToVolumeRegion(memRegionCount, insideRegion.getRegionID(), outsideRegion.getRegionID(), sgr.getSize());
memRegionCount++;
}
}
}
SurfaceCollection surfaceCollection = geometrySurfaceDescription.getSurfaceCollection();
if (surfaceCollection != null) {
int numMembraneElement = surfaceCollection.getTotalPolygonCount();
mesh.membraneElements = new MembraneElement[numMembraneElement];
boolean bMembraneEdgeNeighborsAvailable = surfaceCollection.getMembraneEdgeNeighbors() != null && surfaceCollection.getMembraneEdgeNeighbors().length == surfaceCollection.getSurfaceCount();
int[] membraneElementMapMembraneRegion = new int[numMembraneElement];
mesh.meshRegionInfo.mapMembraneElementsToMembraneRegions(membraneElementMapMembraneRegion);
int memCount = 0;
// original values when no membraneedgeneighbors
int[] membraneNeighbors = new int[] { 0, 0, 0, 0 };
for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
Surface surface = surfaceCollection.getSurfaces(i);
bMembraneEdgeNeighborsAvailable = bMembraneEdgeNeighborsAvailable && surfaceCollection.getMembraneEdgeNeighbors()[i].length == surface.getPolygonCount();
for (int j = 0; j < surface.getPolygonCount(); j++) {
if (bMembraneEdgeNeighborsAvailable) {
membraneNeighbors = new int[MembraneElement.MAX_POSSIBLE_NEIGHBORS];
Arrays.fill(membraneNeighbors, MembraneElement.NEIGHBOR_UNDEFINED);
for (int k = 0; k < surfaceCollection.getMembraneEdgeNeighbors()[i][j].size(); k++) {
membraneNeighbors[k] = surfaceCollection.getMembraneEdgeNeighbors()[i][j].get(k).getMasterPolygonIndex();
}
}
Quadrilateral polygon = (Quadrilateral) surface.getPolygons(j);
int volNeighbor1Region = regionImage.getRegionInfoFromOffset(polygon.getVolIndexNeighbor1()).getRegionIndex();
int volNeighbor2Region = regionImage.getRegionInfoFromOffset(polygon.getVolIndexNeighbor2()).getRegionIndex();
HashMap<Integer, int[]> map = mesh.getMembraneRegionMapSubvolumesInOut();
Set<Entry<Integer, int[]>> entries = map.entrySet();
for (Entry<Integer, int[]> entry : entries) {
int[] volNeighbors = entry.getValue();
if (volNeighbors[0] == volNeighbor1Region && volNeighbors[1] == volNeighbor2Region || volNeighbors[1] == volNeighbor1Region && volNeighbors[0] == volNeighbor2Region) {
membraneElementMapMembraneRegion[memCount] = entry.getKey();
break;
}
}
mesh.membraneElements[memCount] = new MembraneElement(memCount, polygon.getVolIndexNeighbor1(), polygon.getVolIndexNeighbor2(), membraneNeighbors[0], membraneNeighbors[1], membraneNeighbors[2], membraneNeighbors[3], MembraneElement.AREA_UNDEFINED, 0, 0, 0, 0, 0, 0);
if (polygonMembaneElementMap != null) {
polygonMembaneElementMap.put(polygon, mesh.membraneElements[memCount]);
}
memCount++;
}
}
}
return mesh;
}
Aggregations