use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.
the class RunSims method isSmoldynTimeStepOK.
private boolean isSmoldynTimeStepOK(Simulation sim) {
for (int jobIndex = 0; jobIndex < sim.getScanCount(); jobIndex++) {
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, jobIndex);
double Dmax = 0;
MathDescription mathDesc = sim.getMathDescription();
Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
while (subDomainEnumeration.hasMoreElements()) {
SubDomain subDomain = subDomainEnumeration.nextElement();
// }
for (ParticleProperties particleProperties : subDomain.getParticleProperties()) {
try {
Expression newExp = new Expression(particleProperties.getDiffusion());
newExp.bindExpression(simSymbolTable);
newExp = simSymbolTable.substituteFunctions(newExp).flatten();
try {
double diffConstant = newExp.evaluateConstant();
Dmax = Math.max(Dmax, diffConstant);
} catch (ExpressionException ex) {
throw new ExpressionException("diffusion coefficient for variable " + particleProperties.getVariable().getQualifiedName() + " is not a constant. Constants are required for all diffusion coefficients");
}
} catch (Exception ex) {
}
}
}
double s = sim.getMeshSpecification().getDx(sim.hasCellCenteredMesh());
double dt = sim.getSolverTaskDescription().getTimeStep().getDefaultTimeStep();
if (dt >= s * s / (2 * Dmax)) {
smoldynTimestepVars = new SmoldynTimeStepVars(s, Dmax);
return false;
}
}
return true;
}
use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.
the class SmoldynFileWriter method writeDiffusions.
private void writeDiffusions() throws ExpressionBindingException, ExpressionException, MathException {
// writer diffusion properties
printWriter.println("# diffusion properties");
Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
while (subDomainEnumeration.hasMoreElements()) {
SubDomain subDomain = subDomainEnumeration.nextElement();
List<ParticleProperties> particlePropertiesList = subDomain.getParticleProperties();
for (ParticleProperties pp : particlePropertiesList) {
String variableName = null;
if (subDomain instanceof MembraneSubDomain) {
variableName = getVariableName(pp.getVariable(), subDomain);
} else {
variableName = getVariableName(pp.getVariable(), null);
}
try {
double diffConstant = subsituteFlattenToConstant(pp.getDiffusion());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.difc + " " + variableName + " " + diffConstant);
} catch (NotAConstantException ex) {
throw new ExpressionException("diffusion coefficient for variable " + variableName + " is not a constant. Constants are required for all diffusion coefficients");
}
}
}
printWriter.println();
}
use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.
the class MembraneParticleDiffusionVisitor method hasMembraneDiffusion.
private boolean hasMembraneDiffusion(MathDescription mathDesc) throws ExpressionException {
//
for (SubDomain subDomain : Collections.list(mathDesc.getSubDomains())) {
if (subDomain instanceof MembraneSubDomain) {
MembraneSubDomain membraneSubDomain = (MembraneSubDomain) subDomain;
for (ParticleProperties particleProperties : membraneSubDomain.getParticleProperties()) {
Expression diffusionCoef = particleProperties.getDiffusion();
diffusionCoef = MathUtilities.substituteFunctions(diffusionCoef, mathDesc);
diffusionCoef = diffusionCoef.flatten();
if (!diffusionCoef.isZero()) {
return true;
}
}
}
}
return false;
}
Aggregations