use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class FiniteVolumeFileWriter method writeVariables.
/**
*# Variables : type name unit time_dependent_flag advection_flag solve_whole_mesh_flag solve_regions
*VARIABLE_BEGIN
*VOLUME_ODE rB uM
*VOLUME_PDE rf uM false false
*VOLUME_PDE r uM false false
*VOLUME_ODE rfB uM
*VARIABLE_END
* @throws MathException
* @throws ExpressionException
* @throws IOException
*/
private void writeVariables() throws MathException, ExpressionException, IOException {
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
printWriter.println("# Variables : type name domain time_dependent_flag advection_flag grad_flag solve_whole_mesh_flag solve_regions");
printWriter.println(FVInputFileKeyword.VARIABLE_BEGIN);
MathDescription mathDesc = simSymbolTable.getSimulation().getMathDescription();
Variable[] vars = simSymbolTable.getVariables();
ArrayList<RandomVariable> rvList = new ArrayList<RandomVariable>();
for (int i = 0; i < vars.length; i++) {
String varName = vars[i].getName();
String domainName = vars[i].getDomain() == null ? null : vars[i].getDomain().getName();
if (vars[i] instanceof VolumeRandomVariable || vars[i] instanceof MembraneRandomVariable) {
rvList.add((RandomVariable) vars[i]);
} else if (vars[i] instanceof VolVariable) {
if (bChomboSolver && domainName == null) {
throw new MathException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " requires that every variable is defined in a single domain");
}
VolVariable volVar = (VolVariable) vars[i];
if (mathDesc.isPDE(volVar)) {
boolean hasTimeVaryingDiffusionOrAdvection = simSymbolTable.hasTimeVaryingDiffusionOrAdvection(volVar);
final boolean hasVelocity = mathDesc.hasVelocity(volVar);
final boolean hasGradient = mathDesc.hasGradient(volVar);
if (mathDesc.isPdeSteady(volVar)) {
printWriter.print("VOLUME_PDE_STEADY ");
} else {
printWriter.print("VOLUME_PDE ");
}
printWriter.print(varName + " " + domainName + " " + hasTimeVaryingDiffusionOrAdvection + " " + hasVelocity + " " + hasGradient);
} else {
printWriter.print("VOLUME_ODE " + varName + " " + domainName);
}
if (domainName == null) {
Vector<SubDomain> listOfSubDomains = new Vector<SubDomain>();
int totalNumCompartments = 0;
Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
while (subDomainEnum.hasMoreElements()) {
SubDomain subDomain = subDomainEnum.nextElement();
if (subDomain instanceof CompartmentSubDomain) {
CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) subDomain;
totalNumCompartments++;
Equation varEquation = subDomain.getEquation(vars[i]);
if (varEquation != null) {
if (!(varEquation instanceof PdeEquation) || !((PdeEquation) varEquation).isDummy(simSymbolTable, compartmentSubDomain)) {
listOfSubDomains.add(compartmentSubDomain);
}
}
}
}
if ((totalNumCompartments == listOfSubDomains.size()) || (listOfSubDomains.size() == 0 && simTask.getSimulation().getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE))) {
printWriter.print(" true");
} else {
printWriter.print(" false");
for (int j = 0; j < listOfSubDomains.size(); j++) {
CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) listOfSubDomains.elementAt(j);
printWriter.print(" " + compartmentSubDomain.getName());
}
}
printWriter.println();
} else {
printWriter.println(" false " + domainName);
}
} else if (vars[i] instanceof VolumeParticleVariable) {
printWriter.println(FVInputFileKeyword.VOLUME_PARTICLE + " " + varName + " " + domainName);
} else if (vars[i] instanceof MembraneParticleVariable) {
printWriter.println(FVInputFileKeyword.MEMBRANE_PARTICLE + " " + varName + " " + domainName);
} else if (vars[i] instanceof VolumeRegionVariable) {
printWriter.println("VOLUME_REGION " + varName + " " + domainName);
} else if (vars[i] instanceof MemVariable) {
if (bChomboSolver && domainName == null) {
throw new MathException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " requires that every variable is defined in a single domain");
}
MemVariable memVar = (MemVariable) vars[i];
if (mathDesc.isPDE(memVar)) {
printWriter.println("MEMBRANE_PDE " + varName + " " + domainName + " " + simSymbolTable.hasTimeVaryingDiffusionOrAdvection(memVar));
} else {
printWriter.println("MEMBRANE_ODE " + varName + " " + domainName);
}
} else if (vars[i] instanceof MembraneRegionVariable) {
printWriter.println("MEMBRANE_REGION " + varName + " " + domainName);
} else if (vars[i] instanceof FilamentVariable) {
throw new RuntimeException("Filament application not supported yet");
}
}
int numRandomVariables = rvList.size();
if (numRandomVariables > 0) {
ISize samplingSize = simTask.getSimulation().getMeshSpecification().getSamplingSize();
String[] varNameArr = new String[numRandomVariables];
VariableType[] varTypeArr = new VariableType[numRandomVariables];
double[][] dataArr = new double[numRandomVariables][];
for (int i = 0; i < numRandomVariables; i++) {
RandomVariable rv = rvList.get(i);
varNameArr[i] = rv.getName();
int numRandomNumbers = 0;
if (rv instanceof VolumeRandomVariable) {
printWriter.print("VOLUME_RANDOM");
varTypeArr[i] = VariableType.VOLUME;
numRandomNumbers = samplingSize.getXYZ();
} else if (rv instanceof MembraneRandomVariable) {
printWriter.print("MEMBRANE_RANDOM");
varTypeArr[i] = VariableType.MEMBRANE;
numRandomNumbers = resampledGeometry.getGeometrySurfaceDescription().getSurfaceCollection().getTotalPolygonCount();
} else {
throw new RuntimeException("Unknown RandomVariable type");
}
printWriter.println(" " + varNameArr[i]);
dataArr[i] = generateRandomNumbers(rv, numRandomNumbers);
}
File rvFile = new File(workingDirectory, simTask.getSimulationJobID() + RANDOM_VARIABLE_FILE_EXTENSION);
DataSet.writeNew(rvFile, varNameArr, varTypeArr, samplingSize, dataArr);
}
printWriter.println(FVInputFileKeyword.VARIABLE_END);
printWriter.println();
}
use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class Xmlproducer method getXML.
private Element getXML(PointSubDomain param) throws XmlParseException {
Element pointSubDomain = new Element(XMLTags.PointSubDomainTag);
// Add attributes
pointSubDomain.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
// Add Equation subelements
Enumeration<Equation> enum1 = param.getEquations();
while (enum1.hasMoreElements()) {
Equation equ = enum1.nextElement();
pointSubDomain.addContent(getXML(equ));
}
if (param.getPositionX() != null) {
Element positionX = new Element(XMLTags.PositionXTag);
positionX.addContent(param.getPositionX().infix());
pointSubDomain.addContent(positionX);
}
if (param.getPositionY() != null) {
Element positionY = new Element(XMLTags.PositionYTag);
positionY.addContent(param.getPositionY().infix());
pointSubDomain.addContent(positionY);
}
if (param.getPositionZ() != null) {
Element positionZ = new Element(XMLTags.PositionZTag);
positionZ.addContent(param.getPositionZ().infix());
pointSubDomain.addContent(positionZ);
}
return pointSubDomain;
}
use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class MovingBoundaryFileWriter method manageCompartment.
private void manageCompartment(Element e, SubDomain sd) {
try {
if (!sd.getEquationCollection().isEmpty()) {
Element se = getXMLSubdomain(sd);
if (sd instanceof CompartmentSubDomain || sd instanceof PointSubDomain) {
for (Equation equation : sd.getEquationCollection()) {
System.out.println("add this: " + equation.getVariable().getName());
se.addContent(getSpecies(equation));
}
e.addContent(se);
}
}
} catch (Exception exc) {
throw new RuntimeException("error managing compartment", exc);
}
}
use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class DefaultODESolver method createStateVariables.
/**
* This method was created in VisualAge.
*/
private Vector<StateVariable> createStateVariables() throws MathException, ExpressionException {
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
Simulation sim = simSymbolTable.getSimulation();
Vector<StateVariable> stateVariables = new Vector<StateVariable>();
// get Ode's from MathDescription and create ODEStateVariables
Enumeration<Equation> enum1 = getSubDomain().getEquations();
while (enum1.hasMoreElements()) {
Equation equation = enum1.nextElement();
if (equation instanceof OdeEquation) {
stateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
} else {
throw new MathException("encountered non-ode equation, unsupported");
}
}
MathDescription mathDescription = sim.getMathDescription();
if (rateSensitivity == null) {
rateSensitivity = new RateSensitivity(mathDescription, mathDescription.getSubDomains().nextElement());
}
if (jacobian == null) {
jacobian = new Jacobian(mathDescription, mathDescription.getSubDomains().nextElement());
}
// get Jacobian and RateSensitivities from MathDescription and create SensStateVariables
for (int v = 0; v < fieldSensVariables.size(); v++) {
stateVariables.addElement(new SensStateVariable(fieldSensVariables.elementAt(v), rateSensitivity, jacobian, fieldSensVariables, simSymbolTable));
}
if (stateVariables.size() == 0) {
throw new MathException("there are no equations defined");
}
return (stateVariables);
}
use of cbit.vcell.math.Equation in project vcell by virtualcell.
the class RateSensitivity method parseMathDesc.
/**
* This method was created by a SmartGuide.
* @exception java.lang.Exception The exception description.
*/
private void parseMathDesc() throws MathException {
Vector equationList = new Vector();
Enumeration enum1 = subDomain.getEquations();
while (enum1.hasMoreElements()) {
Equation equ = (Equation) enum1.nextElement();
if (equ instanceof OdeEquation) {
equationList.addElement(equ);
} else {
throw new MathException("encountered non-ode equation, unsupported");
}
}
Vector constantList = new Vector();
enum1 = mathDesc.getVariables();
while (enum1.hasMoreElements()) {
Variable var = (Variable) enum1.nextElement();
if (var instanceof Constant) {
constantList.addElement(var);
}
}
numConstants = constantList.size();
numRates = equationList.size();
rates = new Expression[numRates];
vars = new Variable[numRates];
consts = new Constant[numConstants];
for (int i = 0; i < numRates; i++) {
OdeEquation odeEqu = (OdeEquation) equationList.elementAt(i);
rates[i] = odeEqu.getRateExpression();
vars[i] = odeEqu.getVariable();
}
for (int i = 0; i < numConstants; i++) {
consts[i] = (Constant) constantList.elementAt(i);
}
}
Aggregations