use of cbit.vcell.math.SubDomain.BoundaryConditionSpec in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method returns a XML representation of a CompartmentSubDomain object.
* Creation date: (3/2/2001 1:18:55 PM)
* @return Element
* @param param cbit.vcell.math.CompartmentSubDomain
*/
private Element getXML(CompartmentSubDomain param) throws XmlParseException {
Element compartment = new Element(XMLTags.CompartmentSubDomainTag);
compartment.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
// Add boundaryType subelements
Element boundary;
// Xm
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXm().boundaryTypeStringValue());
compartment.addContent(boundary);
// Xp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXp().boundaryTypeStringValue());
compartment.addContent(boundary);
// Ym
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYm().boundaryTypeStringValue());
compartment.addContent(boundary);
// Yp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYp().boundaryTypeStringValue());
compartment.addContent(boundary);
// Zm
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZm().boundaryTypeStringValue());
compartment.addContent(boundary);
// Zp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZp().boundaryTypeStringValue());
compartment.addContent(boundary);
// add BoundaryConditionSpecs
for (BoundaryConditionSpec bcs : param.getBoundaryconditionSpecs()) {
compartment.addContent(getXML(bcs));
}
// Add Equations
Enumeration<Equation> enum1 = param.getEquations();
while (enum1.hasMoreElements()) {
Equation equ = enum1.nextElement();
compartment.addContent(getXML(equ));
}
// Add FastSystem
if (param.getFastSystem() != null) {
compartment.addContent(getXML(param.getFastSystem()));
}
// Add Variable Initial Condition
for (VarIniCondition varIni : param.getVarIniConditions()) {
compartment.addContent(getXML(varIni));
}
// Add JumpProcesses
for (JumpProcess jp : param.getJumpProcesses()) {
compartment.addContent(getXML(jp));
}
for (ParticleJumpProcess pjp : param.getParticleJumpProcesses()) {
compartment.addContent(getXML(pjp));
}
for (ParticleProperties pp : param.getParticleProperties()) {
compartment.addContent(getXML(pp));
}
return compartment;
}
use of cbit.vcell.math.SubDomain.BoundaryConditionSpec in project vcell by virtualcell.
the class PdeEquation method isDummy.
public boolean isDummy(MathSymbolTable simSymbolTable, CompartmentSubDomain thisCompartment) {
if (!(getVariable() instanceof VolVariable)) {
return false;
}
VolVariable volVar = (VolVariable) getVariable();
// in any case the initial conditions will be respected.
if (testZero(simSymbolTable, getRateExpression()) && testZero(simSymbolTable, velocityX) && testZero(simSymbolTable, velocityY) && testZero(simSymbolTable, velocityZ) && testZero(simSymbolTable, gradientX) && testZero(simSymbolTable, gradientY) && testZero(simSymbolTable, gradientZ)) {
if (testZero(simSymbolTable, diffusionExp)) {
// zero rate, velocity and diffusion
return true;
} else {
// for non-zero diffusion, look for non zero fluxes or non-uniform initial conditions.
if (testConstant(simSymbolTable, getInitialExpression()) && testZero(simSymbolTable, boundaryXm) && testZero(simSymbolTable, boundaryXp) && testZero(simSymbolTable, boundaryYm) && testZero(simSymbolTable, boundaryYp) && testZero(simSymbolTable, boundaryZm) && testZero(simSymbolTable, boundaryZp)) {
// 1. get THIS compartment
// 2. get all membranes that touch this compartment
// 3. get jump condition for this variable
// 4. check either influx or outflux
Enumeration<SubDomain> subDomainEnum = simSymbolTable.getMathDescription().getSubDomains();
while (subDomainEnum.hasMoreElements()) {
SubDomain subDomain = (SubDomain) subDomainEnum.nextElement();
if (subDomain instanceof MembraneSubDomain) {
MembraneSubDomain memSubDomain = (MembraneSubDomain) subDomain;
if (memSubDomain.getInsideCompartment() == thisCompartment) {
JumpCondition jump = memSubDomain.getJumpCondition(volVar);
if (jump != null && !testZero(simSymbolTable, jump.getInFluxExpression())) {
// non zero jump condition
return false;
}
} else if (memSubDomain.getOutsideCompartment() == thisCompartment) {
JumpCondition jump = memSubDomain.getJumpCondition(volVar);
if (jump != null && !testZero(simSymbolTable, jump.getOutFluxExpression())) {
// non zero jump condition
return false;
}
}
// check if BoundaryConditionValue is defined for var on membrane
try {
BoundaryConditionValue boundaryValue = getBoundaryConditionValue(memSubDomain.getName());
if (boundaryValue != null) {
Expression boundaryValExpr = boundaryValue.getBoundaryConditionExpression();
BoundaryConditionSpec boundarySpec = thisCompartment.getBoundaryConditionSpec(memSubDomain.getName());
if (boundarySpec != null) {
boolean bZeroFlux = boundarySpec.getBoundaryConditionType().isNEUMANN() && testZero(simSymbolTable, boundaryValExpr);
boolean bUniformDirichlet = boundarySpec.getBoundaryConditionType().isDIRICHLET() && testZero(simSymbolTable, Expression.add(boundaryValExpr, Expression.negate(getInitialExpression())));
if (!bZeroFlux && !bUniformDirichlet) {
return false;
}
}
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
// check fast system if jump conditions are all zero
FastSystem fastSystem = thisCompartment.getFastSystem();
if (fastSystem != null) {
Enumeration<FastInvariant> fastInvariants = fastSystem.getFastInvariants();
while (fastInvariants.hasMoreElements()) {
FastInvariant fi = fastInvariants.nextElement();
try {
// look for fast invariants that involve only this variable
// which means this variable is not affected by fast system
Expression exp = new Expression(fi.getFunction());
exp.bindExpression(simSymbolTable);
exp = exp.flatten();
SymbolTableEntry ste = exp.getSymbolBinding(volVar.getName());
if (ste != null && exp.getSymbols().length == 1) {
return true;
}
} catch (ExpressionException ex) {
ex.printStackTrace(System.out);
throw new RuntimeException("PdeEquation::isDummy(), not expected: " + ex.getMessage());
}
}
// the variable is not found to be invariant in this fast system, might be changed by fast system
return false;
}
// not changed by jump conditions, boundary conditions and fast system even if diffusion rate is non zero
return true;
}
}
}
// non zero rate or velocity
return false;
}
use of cbit.vcell.math.SubDomain.BoundaryConditionSpec in project vcell by virtualcell.
the class XmlReader method getBoundaryConditionSpec.
private BoundaryConditionSpec getBoundaryConditionSpec(Element param) throws XmlParseException, MathException {
// retrieve values
String boundarySubdomainName = unMangle(param.getAttributeValue(XMLTags.BoundarySubdomainNameTag));
String boundarySubdomainType = unMangle(param.getAttributeValue(XMLTags.BoundaryTypeTag));
if (boundarySubdomainName != null && boundarySubdomainType != null) {
BoundaryConditionSpec bcs = new BoundaryConditionSpec(boundarySubdomainName, new BoundaryConditionType(boundarySubdomainType));
return bcs;
}
return null;
}
use of cbit.vcell.math.SubDomain.BoundaryConditionSpec in project vcell by virtualcell.
the class FiniteVolumeFileWriter method writeMembrane_jumpConditions.
/**
*JUMP_CONDITION_BEGIN r
*INFLUX 0.0;
*OUTFLUX 0.0;
*JUMP_CONDITION_END
* @throws ExpressionException
* @throws MathException
*/
private void writeMembrane_jumpConditions(MembraneSubDomain msd) throws ExpressionException, MathException {
Enumeration<JumpCondition> enum1 = msd.getJumpConditions();
// equations for boundaryValues for inner compartment subdomain
CompartmentSubDomain innerCompSubDomain = msd.getInsideCompartment();
Enumeration<Equation> innercompSubDomEqnsEnum = innerCompSubDomain.getEquations();
while (innercompSubDomEqnsEnum.hasMoreElements()) {
Equation eqn = innercompSubDomEqnsEnum.nextElement();
if (eqn instanceof PdeEquation) {
PdeEquation pdeEqn = (PdeEquation) eqn;
BoundaryConditionValue boundaryValue = pdeEqn.getBoundaryConditionValue(msd.getName());
if (boundaryValue != null) {
// check if the type of BoundaryConditionSpec for this membraneSubDomain (msd) in the (inner) compartmentSubDomain is Flux; if not, it cannot be handled.
BoundaryConditionSpec bcs = innerCompSubDomain.getBoundaryConditionSpec(msd.getName());
if (bcs == null) {
throw new MathException("No Boundary type specified for '" + msd.getName() + "' in '" + innerCompSubDomain.getName() + "'.");
}
if (bcs != null && !bcs.getBoundaryConditionType().compareEqual(BoundaryConditionType.getNEUMANN()) && !bChomboSolver) {
throw new MathException("Boundary type '" + bcs.getBoundaryConditionType().boundaryTypeStringValue() + "' for compartmentSubDomain '" + innerCompSubDomain.getName() + "' not handled by the chosen solver. Expecting boundary condition of type 'Flux'.");
}
if (pdeEqn.getVariable().getDomain() == null || pdeEqn.getVariable().getDomain().getName().equals(msd.getInsideCompartment().getName())) {
printWriter.println("JUMP_CONDITION_BEGIN " + pdeEqn.getVariable().getName());
Expression flux = subsituteExpression(boundaryValue.getBoundaryConditionExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
printWriter.println(bcs.getBoundaryConditionType().boundaryTypeStringValue().toUpperCase() + " " + msd.getInsideCompartment().getName() + " " + infix + ";");
printWriter.println("JUMP_CONDITION_END");
printWriter.println();
}
}
}
}
// equations for boundaryValues for outer compartment subdomain
CompartmentSubDomain outerCompSubDomain = msd.getOutsideCompartment();
Enumeration<Equation> outerCompSubDomEqnsEnum = outerCompSubDomain.getEquations();
while (outerCompSubDomEqnsEnum.hasMoreElements()) {
Equation eqn = outerCompSubDomEqnsEnum.nextElement();
if (eqn instanceof PdeEquation) {
PdeEquation pdeEqn = (PdeEquation) eqn;
BoundaryConditionValue boundaryValue = pdeEqn.getBoundaryConditionValue(msd.getName());
if (boundaryValue != null) {
// check if the type of BoundaryConditionSpec for this membraneSubDomain (msd) in the (inner) compartmentSubDomain is Flux; if not, it cannot be handled.
BoundaryConditionSpec bcs = outerCompSubDomain.getBoundaryConditionSpec(msd.getName());
if (bcs != null && !bcs.getBoundaryConditionType().compareEqual(BoundaryConditionType.getNEUMANN()) && !bChomboSolver) {
throw new MathException("Boundary type '" + bcs.getBoundaryConditionType().boundaryTypeStringValue() + "' for compartmentSubDomain '" + outerCompSubDomain.getName() + "' not handled by the chosen solver. Expecting boundary condition of type 'Flux'.");
}
if (pdeEqn.getVariable().getDomain() == null || pdeEqn.getVariable().getDomain().getName().equals(msd.getOutsideCompartment().getName())) {
printWriter.println("JUMP_CONDITION_BEGIN " + pdeEqn.getVariable().getName());
Expression flux = subsituteExpression(boundaryValue.getBoundaryConditionExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
printWriter.println(bcs.getBoundaryConditionType().boundaryTypeStringValue().toUpperCase() + " " + msd.getOutsideCompartment().getName() + " " + infix + ";");
printWriter.println("JUMP_CONDITION_END");
printWriter.println();
}
}
}
}
while (enum1.hasMoreElements()) {
JumpCondition jc = enum1.nextElement();
printWriter.println("JUMP_CONDITION_BEGIN " + jc.getVariable().getName());
// influx
if (jc.getVariable().getDomain() == null || jc.getVariable().getDomain().getName().equals(msd.getInsideCompartment().getName())) {
Expression flux = subsituteExpression(jc.getInFluxExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
printWriter.println(BoundaryConditionType.NEUMANN_STRING.toUpperCase() + " " + msd.getInsideCompartment().getName() + " " + infix + ";");
}
if (jc.getVariable().getDomain() == null || jc.getVariable().getDomain().getName().equals(msd.getOutsideCompartment().getName())) {
// outflux
Expression flux = subsituteExpression(jc.getOutFluxExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
String infix = replaceVolumeVariable(simTask, msd, flux);
printWriter.println(BoundaryConditionType.NEUMANN_STRING.toUpperCase() + " " + msd.getOutsideCompartment().getName() + " " + infix + ";");
}
printWriter.println("JUMP_CONDITION_END");
printWriter.println();
}
}
Aggregations