use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class MathDescPanel method refreshEquations.
/**
* This method was created by a SmartGuide.
*/
private void refreshEquations() throws ExpressionException {
TreePath selectionPath = getselectionModel1().getSelectionPath();
if (selectionPath != null) {
BioModelNode node = (BioModelNode) selectionPath.getLastPathComponent();
Object[] objectPath = node.getUserObjectPath();
Object lastPathObject = objectPath[objectPath.length - 1];
// for non-stochastic
Expression[] expArray = null;
// for stochastic
String[] expString = null;
getExpressionCanvas1().setStrings(null);
getExpressionCanvas1().setExpressions(null);
if (lastPathObject instanceof Function) {
Function function = (Function) lastPathObject;
Expression exp = function.getExpression();
if (getJRadioButtonValue().isSelected()) {
exp.bindExpression(getMathDescription());
} else {
exp.bindExpression(null);
}
exp = exp.flatten();
// stochastic variable initial value must be an int, therefore we must make it here.
if (getMathDescription().isNonSpatialStoch() && function.getName().startsWith(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX)) {
try {
double value = exp.evaluateConstant();
expString = new String[] { function.getName() + " = " + Math.round(value) };
getExpressionCanvas1().setStrings(expString);
} catch (Exception e) {
expArray = new Expression[] { Expression.assign(new Expression(function.getName()), exp) };
getExpressionCanvas1().setExpressions(expArray);
}
} else {
expArray = new Expression[] { Expression.assign(new Expression(function.getName()), exp) };
getExpressionCanvas1().setExpressions(expArray);
}
} else if (lastPathObject instanceof Constant) {
Constant constant = (Constant) lastPathObject;
Expression exp = constant.getExpression();
if (getJRadioButtonValue().isSelected()) {
exp.bindExpression(getMathDescription());
} else {
exp.bindExpression(null);
}
exp = exp.flatten();
// stochastic variable initial value must be an int, therefore we must make it here.
if (getMathDescription().isNonSpatialStoch() && constant.getName().startsWith(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX)) {
try {
double value = exp.evaluateConstant();
expString = new String[] { constant.getName() + " = " + Math.round(value) };
getExpressionCanvas1().setStrings(expString);
} catch (Exception e) {
expArray = new Expression[] { Expression.assign(new Expression(constant.getName()), exp) };
getExpressionCanvas1().setExpressions(expArray);
}
} else {
expArray = new Expression[] { Expression.assign(new Expression(constant.getName()), exp) };
getExpressionCanvas1().setExpressions(expArray);
}
} else if (lastPathObject instanceof Equation) {
Equation equ = (Equation) lastPathObject;
Enumeration<Expression> enum_equ = equ.getTotalExpressions();
Vector<Expression> expList = new Vector<Expression>();
while (enum_equ.hasMoreElements()) {
Expression exp = new Expression(enum_equ.nextElement());
if (getJRadioButtonValue().isSelected()) {
exp.bindExpression(getMathDescription());
} else {
exp.bindExpression(null);
}
expList.addElement(exp.flatten());
}
expArray = new Expression[expList.size()];
expList.copyInto(expArray);
getExpressionCanvas1().setExpressions(expArray);
} else if (// added Sept 29, 2006
lastPathObject instanceof VarIniCondition) {
VarIniCondition varIni = (VarIniCondition) lastPathObject;
expString = new String[] { varIni.toString() };
getExpressionCanvas1().setStrings(expString);
} else if (// added Sept 29, 2006
lastPathObject instanceof Action) {
Action action = (Action) lastPathObject;
expString = new String[] { action.toString() };
getExpressionCanvas1().setStrings(expString);
} else if (// added Sept 29, 2006
lastPathObject instanceof String) {
// to check if the string is the probability string
int index1 = ((String) lastPathObject).indexOf("probability_rate");
int index2 = ((String) lastPathObject).indexOf("=");
if (// has probability eqution,but don't calculate prob string, since it is not a constant value.
(index1 == 0) && ((index2 + 2) < ((String) lastPathObject).length())) {
expString = new String[] { (String) lastPathObject };
getExpressionCanvas1().setStrings(expString);
}
}
} else {
getExpressionCanvas1().setExpressions(null);
getExpressionCanvas1().setStrings(null);
getExpressionCanvas1().repaint();
}
// Variable var = getMathDescription().getVariable(varName);
// SubDomain subDomain = getMathDescription().getSubDomain(subDomainName);
// Equation equ = null;
// if (var != null && subDomain != null){
// equ = subDomain.getEquation(var);
// }
// if (equ == null){
// if (subDomain instanceof MembraneSubDomain && var instanceof VolVariable){
// equ = ((MembraneSubDomain)subDomain).getJumpCondition((VolVariable)var);
// }
// }
// if (equ == null){
// Expression exp = null;
// String title = "hello";
// if (var instanceof Constant || var instanceof Function){
// exp = var.getExpression();
// title = "Expression for "+var.getName();
// }
// if (getJRadioButtonValue().isSelected()){
// exp.bindExpression(getMathDescription());
// }else{
// exp.bindExpression(null);
// }
// getExpressionCanvas1().setExpression(exp.flatten());
// getEquationTitleLabel().setText(title);
// }else{
// Enumeration enum_equ = equ.getTotalExpressions();
// Vector expList = new Vector();
// while (enum_equ.hasMoreElements()){
// Expression exp = new Expression((Expression)enum_equ.nextElement());
// if (getJRadioButtonValue().isSelected()){
// exp.bindExpression(getMathDescription());
// }else{
// exp.bindExpression(null);
// }
// expList.addElement(exp.flatten());
// }
// Expression expArray[] = new Expression[expList.size()];
// expList.copyInto(expArray);
// getExpressionCanvas1().setExpressions(expArray);
// getEquationTitleLabel().setText("Equations for "+var.getName()+" within "+subDomain.getName());
// }
// } catch (java.lang.Throwable ivjExc) {
// handleException(ivjExc);
// getEquationTitleLabel().setText("Equations for "+varName+" within "+subDomainName+" *** "+ivjExc.getMessage());
// }
// }
// }else{
// getEquationTitleLabel().setText("no variable selected");
// getExpressionCanvas1().setExpression((Expression)null);
// }
}
use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class MathDescriptionTreeModel method createBaseTree.
/**
* Insert the method's description here.
* Creation date: (11/28/00 1:06:51 PM)
* @return cbit.vcell.desktop.BioModelNode
* @param docManager cbit.vcell.clientdb.DocumentManager
*/
private BioModelNode createBaseTree() {
if (getMathDescription() == null) {
return new BioModelNode(" ", false);
}
//
// make root node
//
BioModelNode rootNode = new BioModelNode("math description", true);
//
// create subTree of Constants
//
BioModelNode constantRootNode = new BioModelNode("constants", true);
Enumeration<Constant> enum1 = getMathDescription().getConstants();
while (enum1.hasMoreElements()) {
Constant constant = enum1.nextElement();
BioModelNode constantNode = new BioModelNode(constant, false);
constantRootNode.add(constantNode);
}
if (constantRootNode.getChildCount() > 0) {
rootNode.add(constantRootNode);
}
//
// create subTree of Functions
//
BioModelNode functionRootNode = new BioModelNode("functions", true);
Enumeration<Function> enum2 = getMathDescription().getFunctions();
while (enum2.hasMoreElements()) {
Function function = enum2.nextElement();
BioModelNode functionNode = new BioModelNode(function, false);
functionRootNode.add(functionNode);
}
if (functionRootNode.getChildCount() > 0) {
rootNode.add(functionRootNode);
}
//
// create subTree of VolumeSubDomains and MembraneSubDomains
//
BioModelNode volumeRootNode = new BioModelNode("volume domains", true);
BioModelNode membraneRootNode = new BioModelNode("membrane domains", true);
Enumeration<SubDomain> enum3 = getMathDescription().getSubDomains();
while (enum3.hasMoreElements()) {
SubDomain subDomain = enum3.nextElement();
if (subDomain instanceof cbit.vcell.math.CompartmentSubDomain) {
CompartmentSubDomain volumeSubDomain = (CompartmentSubDomain) subDomain;
BioModelNode volumeSubDomainNode = new BioModelNode(volumeSubDomain, true);
if (// stochastic subtree
getMathDescription().isNonSpatialStoch()) {
// add stoch variable initial conditions
BioModelNode varIniConditionNode = new BioModelNode("variable_initial_conditions", true);
for (VarIniCondition varIni : volumeSubDomain.getVarIniConditions()) {
BioModelNode varIniNode = new BioModelNode(varIni, false);
varIniConditionNode.add(varIniNode);
}
volumeSubDomainNode.add(varIniConditionNode);
// add jump processes
for (JumpProcess jp : volumeSubDomain.getJumpProcesses()) {
BioModelNode jpNode = new BioModelNode(jp, true);
// add probability rate.
String probRate = "P_" + jp.getName();
BioModelNode prNode = new BioModelNode("probability_rate = " + probRate, false);
jpNode.add(prNode);
// add Actions
Enumeration<Action> actions = Collections.enumeration(jp.getActions());
while (actions.hasMoreElements()) {
Action action = actions.nextElement();
BioModelNode actionNode = new BioModelNode(action, false);
jpNode.add(actionNode);
}
volumeSubDomainNode.add(jpNode);
}
} else // non-stochastic subtree
{
//
// add equation children
//
Enumeration<Equation> eqnEnum = volumeSubDomain.getEquations();
while (eqnEnum.hasMoreElements()) {
Equation equation = eqnEnum.nextElement();
BioModelNode equationNode = new BioModelNode(equation, false);
volumeSubDomainNode.add(equationNode);
}
//
// add fast system
//
FastSystem fastSystem = volumeSubDomain.getFastSystem();
if (fastSystem != null) {
BioModelNode fsNode = new BioModelNode(fastSystem, true);
Enumeration<FastInvariant> enumFI = fastSystem.getFastInvariants();
while (enumFI.hasMoreElements()) {
FastInvariant fi = enumFI.nextElement();
fsNode.add(new BioModelNode(fi, false));
}
Enumeration<FastRate> enumFR = fastSystem.getFastRates();
while (enumFR.hasMoreElements()) {
FastRate fr = enumFR.nextElement();
fsNode.add(new BioModelNode(fr, false));
}
volumeSubDomainNode.add(fsNode);
}
}
volumeRootNode.add(volumeSubDomainNode);
} else if (subDomain instanceof MembraneSubDomain) {
MembraneSubDomain membraneSubDomain = (MembraneSubDomain) subDomain;
BioModelNode membraneSubDomainNode = new BioModelNode(membraneSubDomain, true);
//
// add equation children
//
Enumeration<Equation> eqnEnum = membraneSubDomain.getEquations();
while (eqnEnum.hasMoreElements()) {
Equation equation = eqnEnum.nextElement();
BioModelNode equationNode = new BioModelNode(equation, false);
membraneSubDomainNode.add(equationNode);
}
//
// add jump condition children
//
Enumeration<JumpCondition> jcEnum = membraneSubDomain.getJumpConditions();
while (jcEnum.hasMoreElements()) {
JumpCondition jumpCondition = jcEnum.nextElement();
BioModelNode jcNode = new BioModelNode(jumpCondition, false);
membraneSubDomainNode.add(jcNode);
}
//
// add fast system
//
FastSystem fastSystem = membraneSubDomain.getFastSystem();
if (fastSystem != null) {
BioModelNode fsNode = new BioModelNode(fastSystem, true);
Enumeration<FastInvariant> enumFI = fastSystem.getFastInvariants();
while (enumFI.hasMoreElements()) {
FastInvariant fi = enumFI.nextElement();
fsNode.add(new BioModelNode(fi, false));
}
Enumeration<FastRate> enumFR = fastSystem.getFastRates();
while (enumFR.hasMoreElements()) {
FastRate fr = enumFR.nextElement();
fsNode.add(new BioModelNode(fr, false));
}
membraneSubDomainNode.add(fsNode);
}
membraneRootNode.add(membraneSubDomainNode);
}
}
if (volumeRootNode.getChildCount() > 0) {
rootNode.add(volumeRootNode);
}
if (membraneRootNode.getChildCount() > 0) {
rootNode.add(membraneRootNode);
}
return rootNode;
}
use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class ApplicationConstraintsGenerator method steadyStateFromApplication.
/**
* Insert the method's description here.
* Creation date: (6/26/01 8:25:55 AM)
* @return cbit.vcell.constraints.ConstraintContainerImpl
*/
public static ConstraintContainerImpl steadyStateFromApplication(SimulationContext simContext, double tolerance) {
try {
ConstraintContainerImpl ccImpl = new ConstraintContainerImpl();
// ====================
// add physical limits
// ====================
//
// no negative concentrations
//
cbit.vcell.model.Model model = simContext.getModel();
cbit.vcell.model.SpeciesContext[] speciesContexts = model.getSpeciesContexts();
for (int i = 0; i < speciesContexts.length; i++) {
ccImpl.addSimpleBound(new SimpleBounds(speciesContexts[i].getName(), new RealInterval(0, Double.POSITIVE_INFINITY), AbstractConstraint.PHYSICAL_LIMIT, "non-negative concentration"));
}
for (int i = 0; i < speciesContexts.length; i++) {
SpeciesContextSpecParameter initParam = (simContext.getReactionContext().getSpeciesContextSpec(speciesContexts[i])).getInitialConditionParameter();
if (initParam != null) {
double initialValue = initParam.getExpression().evaluateConstant();
double lowInitialValue = Math.min(initialValue / tolerance, initialValue * tolerance);
double highInitialValue = Math.max(initialValue / tolerance, initialValue * tolerance);
ccImpl.addSimpleBound(new SimpleBounds(speciesContexts[i].getName(), new RealInterval(lowInitialValue, highInitialValue), AbstractConstraint.MODELING_ASSUMPTION, "close to specified \"initialCondition\""));
}
}
// =========================
// add modeling assumptions
// =========================
//
// mass action forward and reverse rates should be non-negative
//
cbit.vcell.model.ReactionStep[] reactionSteps = model.getReactionSteps();
for (int i = 0; i < reactionSteps.length; i++) {
Kinetics kinetics = reactionSteps[i].getKinetics();
if (kinetics instanceof MassActionKinetics) {
Expression forwardRateConstraintExp = new Expression(((MassActionKinetics) kinetics).getForwardRateParameter().getExpression().infix() + ">=0");
forwardRateConstraintExp = getSteadyStateExpression(forwardRateConstraintExp);
if (!forwardRateConstraintExp.compareEqual(new Expression(1.0))) {
ccImpl.addGeneralConstraint(new GeneralConstraint(forwardRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "non-negative forward rate"));
}
Expression reverseRateConstraintExp = new Expression(((MassActionKinetics) kinetics).getReverseRateParameter().getExpression().infix() + ">=0");
reverseRateConstraintExp = getSteadyStateExpression(reverseRateConstraintExp);
if (!reverseRateConstraintExp.compareEqual(new Expression(1.0))) {
ccImpl.addGeneralConstraint(new GeneralConstraint(reverseRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "non-negative reverse rate"));
}
}
KineticsParameter authoritativeParameter = kinetics.getAuthoritativeParameter();
Expression kineticRateConstraintExp = new Expression(authoritativeParameter.getName() + "==" + authoritativeParameter.getExpression().infix());
kineticRateConstraintExp = getSteadyStateExpression(kineticRateConstraintExp);
if (!kineticRateConstraintExp.compareEqual(new Expression(1.0))) {
ccImpl.addGeneralConstraint(new GeneralConstraint(kineticRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "definition"));
}
}
//
try {
simContext.setMathDescription(simContext.createNewMathMapping().getMathDescription());
} catch (Throwable e) {
e.printStackTrace(System.out);
throw new RuntimeException("cannot create mathDescription");
}
MathDescription mathDesc = simContext.getMathDescription();
if (mathDesc.getGeometry().getDimension() > 0) {
throw new RuntimeException("spatial simulations not yet supported");
}
CompartmentSubDomain subDomain = (CompartmentSubDomain) mathDesc.getSubDomains().nextElement();
java.util.Enumeration<Equation> enumEquations = subDomain.getEquations();
while (enumEquations.hasMoreElements()) {
Equation equation = (Equation) enumEquations.nextElement();
Expression rateConstraintExp = new Expression(equation.getRateExpression().infix() + "==0");
rateConstraintExp = getSteadyStateExpression(rateConstraintExp);
if (!rateConstraintExp.compareEqual(new Expression(1.0))) {
// not a trivial constraint (always true)
ccImpl.addGeneralConstraint(new GeneralConstraint(rateConstraintExp, AbstractConstraint.PHYSICAL_LIMIT, "definition of steady state"));
}
}
//
for (int i = 0; i < reactionSteps.length; i++) {
Kinetics kinetics = reactionSteps[i].getKinetics();
Kinetics.KineticsParameter[] parameters = kinetics.getKineticsParameters();
for (int j = 0; j < parameters.length; j++) {
Expression exp = parameters[j].getExpression();
if (exp.getSymbols() == null || exp.getSymbols().length == 0) {
//
try {
double constantValue = exp.evaluateConstant();
double lowValue = Math.min(constantValue / tolerance, constantValue * tolerance);
double highValue = Math.max(constantValue / tolerance, constantValue * tolerance);
RealInterval interval = new RealInterval(lowValue, highValue);
ccImpl.addSimpleBound(new SimpleBounds(parameters[j].getName(), interval, AbstractConstraint.MODELING_ASSUMPTION, "parameter close to model default"));
} catch (cbit.vcell.parser.ExpressionException e) {
System.out.println("error evaluating parameter " + parameters[j].getName() + " in reaction step " + reactionSteps[i].getName());
}
} else {
Expression parameterDefinitionExp = new Expression(parameters[j].getName() + "==" + parameters[j].getExpression().infix());
ccImpl.addGeneralConstraint(new GeneralConstraint(getSteadyStateExpression(parameterDefinitionExp), AbstractConstraint.MODELING_ASSUMPTION, "parameter definition"));
}
}
}
ccImpl.addSimpleBound(new SimpleBounds(model.getFARADAY_CONSTANT().getName(), new RealInterval(model.getFARADAY_CONSTANT().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "Faraday's constant"));
ccImpl.addSimpleBound(new SimpleBounds(model.getTEMPERATURE().getName(), new RealInterval(300), AbstractConstraint.PHYSICAL_LIMIT, "Absolute Temperature Kelvin"));
ccImpl.addSimpleBound(new SimpleBounds(model.getGAS_CONSTANT().getName(), new RealInterval(model.getGAS_CONSTANT().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "ideal gas constant"));
ccImpl.addSimpleBound(new SimpleBounds(model.getKMILLIVOLTS().getName(), new RealInterval(model.getKMILLIVOLTS().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "ideal gas constant"));
//
// add K_fluxs
//
java.util.Enumeration<Variable> enumVars = mathDesc.getVariables();
while (enumVars.hasMoreElements()) {
Variable var = (Variable) enumVars.nextElement();
if (var.getName().startsWith("Kflux_") && var instanceof Function) {
Expression kfluxExp = new Expression(((Function) var).getExpression());
kfluxExp.bindExpression(mathDesc);
kfluxExp = MathUtilities.substituteFunctions(kfluxExp, mathDesc);
kfluxExp = kfluxExp.flatten();
ccImpl.addSimpleBound(new SimpleBounds(var.getName(), new RealInterval(kfluxExp.evaluateConstant()), AbstractConstraint.MODELING_ASSUMPTION, "flux conversion factor"));
}
}
return ccImpl;
} catch (cbit.vcell.parser.ExpressionException e) {
e.printStackTrace(System.out);
return null;
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
return null;
}
}
use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class FiniteVolumeFileWriter method writeCompartment_VarContext.
/**
* Insert the method's description here.
* Creation date: (5/9/2005 2:52:48 PM)
* @throws ExpressionException
*/
private void writeCompartment_VarContext(CompartmentSubDomain volSubDomain) throws ExpressionException {
Simulation simulation = simTask.getSimulation();
//
// get list of volVariables participating in PDEs (anywhere).
//
Vector<VolVariable> pdeVolVariableList = new Vector<VolVariable>();
Variable[] variables = simTask.getSimulationJob().getSimulationSymbolTable().getVariables();
for (int i = 0; i < variables.length; i++) {
if (variables[i] instanceof VolVariable && simulation.getMathDescription().isPDE((VolVariable) variables[i])) {
pdeVolVariableList.add((VolVariable) variables[i]);
}
}
Enumeration<Equation> enum_equ = volSubDomain.getEquations();
while (enum_equ.hasMoreElements()) {
Equation equation = enum_equ.nextElement();
// for chombo solver, only write equations for variables that are defined in this compartment
if (!bChomboSolver || equation.getVariable().getDomain().getName().equals(volSubDomain.getName())) {
if (equation instanceof VolumeRegionEquation) {
writeCompartmentRegion_VarContext_Equation(volSubDomain, (VolumeRegionEquation) equation);
} else if (equation instanceof MeasureEquation) {
throw new RuntimeException("Measure Equation " + equation.getClass().getSimpleName() + " not yet supported in FiniteVolume solvers");
} else {
writeCompartment_VarContext_Equation(volSubDomain, equation);
}
}
if (equation instanceof PdeEquation) {
pdeVolVariableList.remove(equation.getVariable());
}
}
//
if (!bChomboSolver) {
for (int i = 0; i < pdeVolVariableList.size(); i++) {
VolVariable volVar = pdeVolVariableList.elementAt(i);
boolean bSteady = simulation.getMathDescription().isPdeSteady(volVar);
PdeEquation dummyPdeEquation = new PdeEquation(volVar, bSteady, new Expression(0.0), new Expression(0.0), new Expression(0.0));
writeCompartment_VarContext_Equation(volSubDomain, dummyPdeEquation);
}
}
}
use of cbit.vcell.math.Equation 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