use of cbit.vcell.math.PseudoConstant in project vcell by virtualcell.
the class FastSystemAnalyzer method refreshSubstitutedRateExps.
/**
*/
private void refreshSubstitutedRateExps() throws MathException, ExpressionException {
//
// refresh PseudoConstants (temp constants involved with fastInvariants)
//
pseudoConstantList.removeAllElements();
Enumeration<FastInvariant> enum_fi = fastSystem.getFastInvariants();
while (enum_fi.hasMoreElements()) {
FastInvariant fi = enum_fi.nextElement();
Domain domain = new Domain(fastSystem.getSubDomain());
fi.getFunction().bindExpression(this);
PseudoConstant pc = new PseudoConstant(getAvailablePseudoConstantName(), fi.getFunction(), domain);
pseudoConstantList.addElement(pc);
// System.out.println("FastSystem.refreshSubstitutedRateExps() __C"+i+" = "+fi.getFunction());
}
//
// build expressions for dependent variables in terms of independent vars
// and pseudoConstants
//
dependencyExpList.removeAllElements();
for (int row = 0; row < dependentVarList.size(); row++) {
Expression exp = new Expression("0.0;");
//
for (int col = 0; col < independentVarList.size(); col++) {
Variable indepVar = (Variable) independentVarList.elementAt(col);
RationalExp coefExp = dependencyMatrix.get(row, col).simplify();
if (!coefExp.isZero()) {
exp = Expression.add(exp, new Expression(coefExp.infixString() + "*" + indepVar.getName()));
}
}
//
for (int col = independentVarList.size(); col < dependencyMatrix.getNumCols(); col++) {
PseudoConstant pc = (PseudoConstant) pseudoConstantList.elementAt(col - independentVarList.size());
RationalExp coefExp = dependencyMatrix.get(row, col);
if (!coefExp.isZero()) {
exp = Expression.add(exp, new Expression(coefExp.infixString() + "*" + pc.getName()));
}
}
exp.bindExpression(null);
exp = exp.flatten();
exp.bindExpression(this);
// System.out.println("FastSystem.refreshSubstitutedRateExps() "+((Variable)dependentVarList.elementAt(row)).getName()+" = "+exp.toString()+";");
dependencyExpList.addElement(exp);
}
//
// flatten functions, then substitute expressions for dependent vars into rate expressions
//
fastRateExpList.removeAllElements();
// VariableSymbolTable combinedSymbolTable = getCombinedSymbolTable();
Enumeration<FastRate> enum_fr = fastSystem.getFastRates();
while (enum_fr.hasMoreElements()) {
FastRate fr = enum_fr.nextElement();
Expression exp = new Expression(MathUtilities.substituteFunctions(new Expression(fr.getFunction()), this));
// System.out.println("FastSystem.refreshSubstitutedRateExps() fast rate before substitution = "+exp.toString());
for (int j = 0; j < dependentVarList.size(); j++) {
Variable depVar = (Variable) dependentVarList.elementAt(j);
Expression subExp = new Expression((Expression) dependencyExpList.elementAt(j));
exp.substituteInPlace(new Expression(depVar.getName()), subExp);
}
exp.bindExpression(null);
exp = exp.flatten();
// System.out.println("FastSystem.refreshSubstitutedRateExps() fast rate after substitution = "+exp.toString());
exp.bindExpression(this);
fastRateExpList.addElement(exp);
}
}
use of cbit.vcell.math.PseudoConstant in project vcell by virtualcell.
the class OutputFunctionContext method getEntries.
// public abstract void validateNamingConflicts(String symbolDescription, Class<?> newSymbolClass, String newSymbolName, PropertyChangeEvent e) throws PropertyVetoException ;
public void getEntries(Map<String, SymbolTableEntry> entryMap) {
// add all valid entries (variables) from mathdescription
MathDescription mathDescription = simulationOwner.getMathDescription();
if (mathDescription != null) {
Enumeration<Variable> varEnum = mathDescription.getVariables();
while (varEnum.hasMoreElements()) {
Variable var = varEnum.nextElement();
if (!(var instanceof PseudoConstant) && !(var instanceof Constant)) {
entryMap.put(var.getName(), var);
}
}
for (DataGenerator dataGenerator : mathDescription.getPostProcessingBlock().getDataGeneratorList()) {
entryMap.put(dataGenerator.getName(), dataGenerator);
}
}
entryMap.put(ReservedVariable.TIME.getName(), ReservedVariable.TIME);
int dimension = mathDescription.getGeometry().getDimension();
if (dimension > 0) {
entryMap.put(ReservedVariable.X.getName(), ReservedVariable.X);
if (dimension > 1) {
entryMap.put(ReservedVariable.Y.getName(), ReservedVariable.Y);
if (dimension > 2) {
entryMap.put(ReservedVariable.Z.getName(), ReservedVariable.Z);
}
}
}
// then add list of output functions.
for (SymbolTableEntry ste : outputFunctionsList) {
entryMap.put(ste.getName(), ste);
}
}
use of cbit.vcell.math.PseudoConstant in project vcell by virtualcell.
the class FastSystemAnalyzer method refreshSubstitutedRateExps.
/**
*/
private void refreshSubstitutedRateExps() throws MathException, ExpressionException {
//
// refresh PseudoConstants (temp constants involved with fastInvariants)
//
pseudoConstantList.removeAllElements();
Enumeration<FastInvariant> enum_fi = fastSystem.getFastInvariants();
while (enum_fi.hasMoreElements()) {
FastInvariant fi = enum_fi.nextElement();
fi.getFunction().bindExpression(this);
PseudoConstant pc = new PseudoConstant(getAvailablePseudoConstantName(), fi.getFunction(), MathMapping_4_8.nullDomain);
pseudoConstantList.addElement(pc);
// System.out.println("FastSystem.refreshSubstitutedRateExps() __C"+i+" = "+fi.getFunction());
}
//
// build expressions for dependent variables in terms of independent vars
// and pseudoConstants
//
dependencyExpList.removeAllElements();
for (int row = 0; row < dependentVarList.size(); row++) {
Expression exp = new Expression("0.0;");
//
for (int col = 0; col < independentVarList.size(); col++) {
Variable indepVar = (Variable) independentVarList.elementAt(col);
RationalExp coefExp = dependencyMatrix.get(row, col).simplify();
if (!coefExp.isZero()) {
exp = Expression.add(exp, new Expression(coefExp.infixString() + "*" + indepVar.getName()));
}
}
//
for (int col = independentVarList.size(); col < dependencyMatrix.getNumCols(); col++) {
PseudoConstant pc = (PseudoConstant) pseudoConstantList.elementAt(col - independentVarList.size());
RationalExp coefExp = dependencyMatrix.get(row, col);
if (!coefExp.isZero()) {
exp = Expression.add(exp, new Expression(coefExp.infixString() + "*" + pc.getName()));
}
}
exp.bindExpression(null);
exp = exp.flatten();
exp.bindExpression(this);
// System.out.println("FastSystem.refreshSubstitutedRateExps() "+((Variable)dependentVarList.elementAt(row)).getName()+" = "+exp.toString()+";");
dependencyExpList.addElement(exp);
}
//
// flatten functions, then substitute expressions for dependent vars into rate expressions
//
fastRateExpList.removeAllElements();
// VariableSymbolTable combinedSymbolTable = getCombinedSymbolTable();
Enumeration<FastRate> enum_fr = fastSystem.getFastRates();
while (enum_fr.hasMoreElements()) {
FastRate fr = enum_fr.nextElement();
Expression exp = new Expression(MathUtilities.substituteFunctions(new Expression(fr.getFunction()), this));
// System.out.println("FastSystem.refreshSubstitutedRateExps() fast rate before substitution = "+exp.toString());
for (int j = 0; j < dependentVarList.size(); j++) {
Variable depVar = (Variable) dependentVarList.elementAt(j);
Expression subExp = new Expression((Expression) dependencyExpList.elementAt(j));
exp.substituteInPlace(new Expression(depVar.getName()), subExp);
}
exp.bindExpression(null);
exp = exp.flatten();
// System.out.println("FastSystem.refreshSubstitutedRateExps() fast rate after substitution = "+exp.toString());
exp.bindExpression(this);
fastRateExpList.addElement(exp);
}
}
use of cbit.vcell.math.PseudoConstant in project vcell by virtualcell.
the class FiniteVolumeFileWriter method writeFastSystem.
/*private void writeDataProcessor() throws DataAccessException, IOException, MathException, DivideByZeroException, ExpressionException {
Simulation simulation = simTask.getSimulation();
DataProcessingInstructions dpi = simulation.getDataProcessingInstructions();
if (dpi == null) {
printWriter.println("DATA_PROCESSOR_BEGIN " + DataProcessingInstructions.ROI_TIME_SERIES);
printWriter.println("DATA_PROCESSOR_END");
printWriter.println();
return;
}
FieldDataIdentifierSpec fdis = dpi.getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in data processing instructions");
}
String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirProperty, null);
DataSetControllerImpl dsci = new DataSetControllerImpl(new NullSessionLog(),null,userDirectory.getParentFile(),secondarySimDataDir == null ? null : new File(secondarySimDataDir));
CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
SimDataBlock simDataBlock = dsci.getSimDataBlock(null,fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fdis.getFieldFuncArgs().getVariableType();
VariableType dataVarType = simDataBlock.getVariableType();
if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
}
double[] origData = simDataBlock.getData();
String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simulationJob.getJobIndex()) + FieldDataIdentifierSpec.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
File fdatFile = new File(userDirectory, filename);
DataSet.writeNew(fdatFile,
new String[] {fdis.getFieldFuncArgs().getVariableName()},
new VariableType[]{simDataBlock.getVariableType()},
new ISize(origMesh.getSizeX(),origMesh.getSizeY(),origMesh.getSizeZ()),
new double[][]{origData});
printWriter.println("DATA_PROCESSOR_BEGIN " + dpi.getScriptName());
printWriter.println(dpi.getScriptInput());
printWriter.println("SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile);
printWriter.println("DATA_PROCESSOR_END");
printWriter.println();
}
*/
/**
*# fast system dimension num_dependents
*FAST_SYSTEM_BEGIN 2 2
*INDEPENDENT_VARIALBES rf r
*DEPENDENT_VARIALBES rB rfB
*
*PSEUDO_CONSTANT_BEGIN
*__C0 (rfB + rf);
*__C1 (r + rB);
*PSEUDO_CONSTANT_END
*
*FAST_RATE_BEGIN
* - ((0.02 * ( - ( - r + __C1) - ( - rf + __C0) + (20.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0))) + _VCell_FieldData_0) * rf) - (0.1 * ( - rf + __C0)));
*((0.02 * r * ( - ( - r + __C1) - ( - rf + __C0) + (20.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0))) + _VCell_FieldData_0)) - (0.1 * ( - r + __C1)));
*FAST_RATE_END
*
*FAST_DEPENDENCY_BEGIN
*rB ( - r + __C1);
*rfB ( - rf + __C0);
*FAST_DEPENDENCY_END
*
*JACOBIAN_BEGIN
* - (0.1 + (0.02 * (1.0 + (0.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0)))) * rf) + (0.02 * ( - ( - r + __C1) - ( - rf + __C0) + (20.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0))) + _VCell_FieldData_0)));
* - (0.02 * (1.0 + (0.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0)))) * rf);
*(0.02 * r * (1.0 + (0.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0)))));
*(0.1 + (0.02 * ( - ( - r + __C1) - ( - rf + __C0) + (20.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0))) + _VCell_FieldData_0)) + (0.02 * r * (1.0 + (0.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0))))));
*JACOBIAN_END
*
*FAST_SYSTEM_END
* @throws ExpressionException
* @throws MathException
*/
private void writeFastSystem(SubDomain subDomain) throws MathException, ExpressionException {
VariableDomain variableDomain = (subDomain instanceof CompartmentSubDomain) ? VariableDomain.VARIABLEDOMAIN_VOLUME : VariableDomain.VARIABLEDOMAIN_MEMBRANE;
FastSystem fastSystem = subDomain.getFastSystem();
if (fastSystem == null) {
return;
}
FastSystemAnalyzer fs_analyzer = new FastSystemAnalyzer(fastSystem, simTask.getSimulationJob().getSimulationSymbolTable());
int numIndep = fs_analyzer.getNumIndependentVariables();
int numDep = fs_analyzer.getNumDependentVariables();
int numPseudo = fs_analyzer.getNumPseudoConstants();
printWriter.println("# fast system dimension num_dependents");
printWriter.println("FAST_SYSTEM_BEGIN " + numIndep + " " + numDep);
if (numIndep != 0) {
printWriter.print("INDEPENDENT_VARIALBES ");
Enumeration<Variable> enum1 = fs_analyzer.getIndependentVariables();
while (enum1.hasMoreElements()) {
Variable var = enum1.nextElement();
printWriter.print(var.getName() + " ");
}
printWriter.println();
}
if (numDep != 0) {
printWriter.print("DEPENDENT_VARIALBES ");
Enumeration<Variable> enum1 = fs_analyzer.getDependentVariables();
while (enum1.hasMoreElements()) {
Variable var = enum1.nextElement();
printWriter.print(var.getName() + " ");
}
printWriter.println();
}
printWriter.println();
if (numPseudo != 0) {
printWriter.println("PSEUDO_CONSTANT_BEGIN");
Enumeration<PseudoConstant> enum1 = fs_analyzer.getPseudoConstants();
while (enum1.hasMoreElements()) {
PseudoConstant pc = enum1.nextElement();
printWriter.println(pc.getName() + " " + subsituteExpression(pc.getPseudoExpression(), fs_analyzer, variableDomain).infix() + ";");
}
printWriter.println("PSEUDO_CONSTANT_END");
printWriter.println();
}
if (numIndep != 0) {
printWriter.println("FAST_RATE_BEGIN");
Enumeration<Expression> enum1 = fs_analyzer.getFastRateExpressions();
while (enum1.hasMoreElements()) {
Expression exp = enum1.nextElement();
printWriter.println(subsituteExpression(exp, fs_analyzer, variableDomain).infix() + ";");
}
printWriter.println("FAST_RATE_END");
printWriter.println();
}
if (numDep != 0) {
printWriter.println("FAST_DEPENDENCY_BEGIN");
Enumeration<Expression> enum_exp = fs_analyzer.getDependencyExps();
Enumeration<Variable> enum_var = fs_analyzer.getDependentVariables();
while (enum_exp.hasMoreElements()) {
Expression exp = enum_exp.nextElement();
Variable depVar = enum_var.nextElement();
printWriter.println(depVar.getName() + " " + subsituteExpression(exp, fs_analyzer, variableDomain).infix() + ";");
}
printWriter.println("FAST_DEPENDENCY_END");
printWriter.println();
}
if (numIndep != 0) {
printWriter.println("JACOBIAN_BEGIN");
Enumeration<Expression> enum_fre = fs_analyzer.getFastRateExpressions();
while (enum_fre.hasMoreElements()) {
Expression fre = enum_fre.nextElement();
Enumeration<Variable> enum_var = fs_analyzer.getIndependentVariables();
while (enum_var.hasMoreElements()) {
Variable var = enum_var.nextElement();
Expression exp = subsituteExpression(fre, fs_analyzer, variableDomain).flatten();
Expression differential = exp.differentiate(var.getName());
printWriter.println(subsituteExpression(differential, fs_analyzer, variableDomain).infix() + ";");
}
}
printWriter.println("JACOBIAN_END");
printWriter.println();
}
printWriter.println("FAST_SYSTEM_END");
printWriter.println();
}
use of cbit.vcell.math.PseudoConstant in project vcell by virtualcell.
the class OutputFunctionContext method getEntry.
public SymbolTableEntry getEntry(java.lang.String identifierString) {
//
// use MathDescription as the primary SymbolTable, just replace the Constants with the overrides.
//
SymbolTableEntry ste = null;
MathDescription mathDescription = simulationOwner.getMathDescription();
if (mathDescription != null) {
ste = mathDescription.getEntry(identifierString);
if (ste != null && !(ste instanceof PseudoConstant) && !(ste instanceof Constant)) {
return ste;
}
ste = mathDescription.getPostProcessingBlock().getDataGenerator(identifierString);
if (ste instanceof DataGenerator) {
return ste;
}
}
// see if it is an output function.
ste = getOutputFunction(identifierString);
return ste;
}
Aggregations