use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class SimulationWarning method analyzeDiffusion.
/**
* make sure diffusion expressions are constants, store for later use
* @throws ExpressionException
*/
private static Map<MembraneSubDomain, List<DiffusionValue>> analyzeDiffusion(Simulation simulation, double timeStep, IssueContext issueContext, List<Issue> issueList) throws ExpressionException {
Map<MembraneSubDomain, List<DiffusionValue>> diffusionValuesMap = new IdentityHashMap<>();
diffusionValuesMap.clear();
MutableDouble value = new MutableDouble();
MathDescription cm = simulation.getMathDescription();
Objects.requireNonNull(cm);
MathDescription localMath = new MathDescription(cm);
SimulationSymbolTable symTable = new SimulationSymbolTable(simulation, 0);
Map<MembraneSubDomain, List<DiffusionValue>> dvMap = new HashMap<>();
double maxDiffValue = Double.MIN_VALUE;
List<DiffusionValue> diffusionList = new ArrayList<>();
for (SubDomain sd : localMath.getSubDomainCollection()) {
final boolean isMembrane = sd instanceof MembraneSubDomain;
diffusionList.clear();
for (ParticleProperties pp : sd.getParticleProperties()) {
String name = pp.getVariable().getName();
Expression diffExp = pp.getDiffusion();
Expression flattened = MathUtilities.substituteFunctions(diffExp, symTable).flatten();
if (isConstant(flattened, value)) {
if (isMembrane) {
DiffusionValue dv = new DiffusionValue(name, value.doubleValue());
maxDiffValue = Math.max(maxDiffValue, dv.value);
diffusionList.add(dv);
}
} else {
String s = "Smoldyn only supports constant diffusion, " + name + " is variable";
Issue i = new Issue(simulation, issueContext, IssueCategory.SMOLYDN_DIFFUSION, s, s, Severity.ERROR);
issueList.add(i);
}
}
if (isMembrane && !diffusionList.isEmpty()) {
dvMap.put((MembraneSubDomain) sd, diffusionList);
}
}
diffusionValuesMap.putAll(dvMap);
MeshSpecification ms = simulation.getMeshSpecification();
Geometry g = ms.getGeometry();
int dim = g.getDimension();
double minDelta = Double.MAX_VALUE;
switch(dim) {
case 3:
minDelta = Math.min(minDelta, ms.getDz(true));
// fall-through
case 2:
minDelta = Math.min(minDelta, ms.getDy(true));
// fall-through
case 1:
minDelta = Math.min(minDelta, ms.getDx(true));
break;
default:
throw new RuntimeException("Invalid dimension " + dim + " for smoldyn solver");
}
double minArea = minDelta * minDelta / 2;
double limit = PRECHECK_LIMIT_ADJUST * minArea / maxDiffValue;
boolean warn = (timeStep > limit);
if (lg.isDebugEnabled()) {
lg.debug("Min delta " + minDelta + ", min area " + minArea + " time limit " + limit + " timeStep " + timeStep + " -> warn = " + warn);
}
if (warn) {
String s = "Time step " + timeStep + " may be too large, performing further analysis ...";
Issue i = new Issue(simulation, issueContext, IssueCategory.SMOLYDN_DIFFUSION, s, s, Severity.WARNING);
issueList.add(i);
}
lg.debug("end of diffusion analysis");
return diffusionValuesMap;
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class XmlHelper method XMLToSim.
public static Simulation XMLToSim(String xmlString) throws XmlParseException {
Simulation sim = null;
Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
try {
if (xmlString == null || xmlString.length() == 0) {
throw new XmlParseException("Invalid xml for Simulation: " + xmlString);
}
// default parser and no validation
Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
Element simElement = root.getChild(XMLTags.SimulationTag, ns);
Element mdElement = root.getChild(XMLTags.MathDescriptionTag, ns);
Element geomElement = root.getChild(XMLTags.GeometryTag, ns);
XmlReader reader = new XmlReader(true, ns);
Geometry geom = null;
if (geomElement != null) {
geom = reader.getGeometry(geomElement);
}
MathDescription md = reader.getMathDescription(mdElement, geom);
sim = reader.getSimulation(simElement, md);
} catch (Exception pve) {
pve.printStackTrace();
throw new XmlParseException("Unable to parse simulation string.", pve);
}
sim.refreshDependencies();
return sim;
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class XmlHelper method XMLToSimTask.
public static SimulationTask XMLToSimTask(String xmlString) throws XmlParseException, ExpressionException {
Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
try {
if (xmlString == null || xmlString.length() == 0) {
throw new XmlParseException("Invalid xml for Simulation: " + xmlString);
}
// default parser and no validation
Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
if (!root.getName().equals(SimulationTask_tag)) {
throw new RuntimeException("expecting top level element to be " + SimulationTask_tag);
}
int taskId = Integer.parseInt(root.getAttributeValue(TaskId_attr));
int jobIndex = Integer.parseInt(root.getAttributeValue(JobIndex_attr));
String computeResource = root.getChildTextTrim(ComputeResource_tag, ns);
List<?> children = root.getChildren(FieldFunctionIdentifierSpec_tag, ns);
ArrayList<FieldDataIdentifierSpec> fdisArrayList = new ArrayList<FieldDataIdentifierSpec>();
for (Object child : children) {
if (child instanceof Element) {
String fdisText = ((Element) child).getTextTrim();
FieldDataIdentifierSpec fdis = FieldDataIdentifierSpec.fromCSVString(fdisText);
fdisArrayList.add(fdis);
}
}
FieldDataIdentifierSpec[] fdisArray = fdisArrayList.toArray(new FieldDataIdentifierSpec[0]);
Element simElement = root.getChild(XMLTags.SimulationTag, ns);
Element mdElement = root.getChild(XMLTags.MathDescriptionTag, ns);
Element geomElement = root.getChild(XMLTags.GeometryTag, ns);
XmlReader reader = new XmlReader(true, ns);
Geometry geom = null;
if (geomElement != null) {
geom = reader.getGeometry(geomElement);
}
MathDescription md = reader.getMathDescription(mdElement, geom);
Simulation sim = reader.getSimulation(simElement, md);
sim.refreshDependencies();
SimulationJob simJob = new SimulationJob(sim, jobIndex, fdisArray);
SimulationTask simTask = new SimulationTask(simJob, taskId, computeResource);
return simTask;
} catch (Exception pve) {
pve.printStackTrace();
throw new XmlParseException("Unable to parse simulation string.", pve);
}
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class MeshSpecification method setGeometry.
/**
* Sets the geometry property (cbit.vcell.geometry.Geometry) value.
* @param geometry The new value for the property.
* @see #getGeometry
*/
public void setGeometry(Geometry geometry) {
Geometry oldGeometry = fieldGeometry;
fieldGeometry = geometry;
firePropertyChange("geometry", oldGeometry, fieldGeometry);
if (oldGeometry == null || fieldGeometry.getDimension() != oldGeometry.getDimension()) {
resetSamplingSize();
}
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class OptimizationService method updateMath.
private static void updateMath(SimulationContext simulationContext, final NetworkGenerationRequirements networkGenerationRequirements) throws Exception {
Geometry geometry = simulationContext.getGeometry();
if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
geometry.getGeometrySurfaceDescription().updateAll();
}
simulationContext.checkValidity();
MathMapping mathMapping = simulationContext.createNewMathMapping(callback, networkGenerationRequirements);
MathDescription mathDesc = mathMapping.getMathDescription(callback);
callback.setProgressFraction(1.0f / 3.0f * 2.0f);
if (mathDesc != null) {
simulationContext.setMathDescription(mathDesc);
}
}
Aggregations