use of cbit.vcell.math.FilamentVariable in project vcell by virtualcell.
the class ModelOptimizationSpec method removeUncoupledParameters.
public void removeUncoupledParameters() {
try {
localIssueList.clear();
MathMapping mathMapping = getSimulationContext().createNewMathMapping();
MathDescription mathDesc = mathMapping.getMathDescription();
MathSystemHash mathSystemHash = fromMath(mathDesc);
Graph graph = mathSystemHash.getDependencyGraph(mathSystemHash.getSymbols());
Tree[] spanningTrees = graph.getSpanningForest();
//
for (int i = 0; i < spanningTrees.length; i++) {
Node[] treeNodes = spanningTrees[i].getNodes();
boolean bHasStateVariables = false;
for (int j = 0; j < treeNodes.length; j++) {
Node node = treeNodes[j];
Variable var = mathDesc.getVariable(node.getName());
if (var instanceof VolVariable || var instanceof MemVariable || var instanceof FilamentVariable || var instanceof VolumeRegionVariable || var instanceof MembraneRegionVariable || var instanceof FilamentRegionVariable) {
bHasStateVariables = true;
break;
}
}
if (!bHasStateVariables) {
spanningTrees = (Tree[]) BeanUtils.removeElement(spanningTrees, spanningTrees[i]);
i--;
}
}
//
// remove parameters not mapped to a surviving tree (not coupled to any state variables
//
ArrayList<ParameterMappingSpec> paramMappingSpecsList = new ArrayList<ParameterMappingSpec>();
paramMappingSpecsList.addAll(Arrays.asList(fieldParameterMappingSpecs));
for (int i = 0; i < paramMappingSpecsList.size(); i++) {
Parameter parameter = paramMappingSpecsList.get(i).getModelParameter();
String mathName = mathMapping.getMathSymbolMapping().getVariable(parameter).getName();
boolean bFoundInTree = false;
for (int j = 0; j < spanningTrees.length; j++) {
Node node = spanningTrees[j].getNode(mathName);
if (node != null) {
bFoundInTree = true;
}
}
if (!bFoundInTree) {
paramMappingSpecsList.remove(i);
i--;
}
}
ParameterMappingSpec[] parameterMappingSpecs = new ParameterMappingSpec[paramMappingSpecsList.size()];
paramMappingSpecsList.toArray(parameterMappingSpecs);
setParameterMappingSpecs(parameterMappingSpecs);
} catch (Exception e) {
e.printStackTrace(System.out);
localIssueList.add(new Issue(this, localIssueContext, IssueCategory.ParameterEstimationGeneralWarning, e.getMessage(), Issue.SEVERITY_WARNING));
// throw new RuntimeException(e.getMessage());
}
}
use of cbit.vcell.math.FilamentVariable 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.FilamentVariable in project vcell by virtualcell.
the class MathTestingUtilities method substituteWithExactSolution.
/**
* Insert the method's description here.
* Creation date: (1/24/2003 10:18:14 AM)
* @return cbit.vcell.parser.Expression
* @param origExp cbit.vcell.parser.Expression
* @param subDomain cbit.vcell.math.SubDomain
*/
private static Expression substituteWithExactSolution(Expression origExp, MembraneSubDomain subDomain, MathDescription exactMathDesc) throws ExpressionException {
Expression substitutedExp = new Expression(origExp);
substitutedExp.bindExpression(exactMathDesc);
substitutedExp = MathUtilities.substituteFunctions(substitutedExp, exactMathDesc);
substitutedExp.bindExpression(null);
substitutedExp = substitutedExp.flatten();
substitutedExp.bindExpression(exactMathDesc);
String[] symbols = substitutedExp.getSymbols();
for (int i = 0; symbols != null && i < symbols.length; i++) {
Variable var = (Variable) substitutedExp.getSymbolBinding(symbols[i]);
if (var instanceof MemVariable) {
String exactVarName = var.getName() + "_" + subDomain.getName() + "_exact";
substitutedExp.substituteInPlace(new Expression(var.getName()), new Expression(exactVarName));
} else if (var instanceof InsideVariable) {
String exactVarName = var.getName() + "_" + subDomain.getInsideCompartment().getName() + "_exact";
substitutedExp.substituteInPlace(new Expression(var.getName()), new Expression(exactVarName));
} else if (var instanceof OutsideVariable) {
String exactVarName = var.getName() + "_" + subDomain.getOutsideCompartment().getName() + "_exact";
substitutedExp.substituteInPlace(new Expression(var.getName()), new Expression(exactVarName));
} else if (var instanceof VolumeRegionVariable || var instanceof MemVariable || var instanceof MembraneRegionVariable || var instanceof FilamentVariable || var instanceof FilamentRegionVariable) {
throw new RuntimeException("variable substitution not yet implemented for Variable type " + var.getClass().getName() + "(" + var.getName() + ")");
}
}
substitutedExp.bindExpression(null);
return substitutedExp;
}
use of cbit.vcell.math.FilamentVariable in project vcell by virtualcell.
the class MathTestingUtilities method substituteWithExactSolution.
/**
* Insert the method's description here.
* Creation date: (1/24/2003 10:18:14 AM)
* @return cbit.vcell.parser.Expression
* @param origExp cbit.vcell.parser.Expression
* @param subDomain cbit.vcell.math.SubDomain
*/
private static Expression substituteWithExactSolution(Expression origExp, CompartmentSubDomain subDomain, MathDescription exactMathDesc) throws ExpressionException {
Expression substitutedExp = new Expression(origExp);
substitutedExp.bindExpression(exactMathDesc);
substitutedExp = MathUtilities.substituteFunctions(substitutedExp, exactMathDesc);
substitutedExp.bindExpression(null);
substitutedExp = substitutedExp.flatten();
substitutedExp.bindExpression(exactMathDesc);
String[] symbols = substitutedExp.getSymbols();
for (int i = 0; i < symbols.length; i++) {
Variable var = (Variable) substitutedExp.getSymbolBinding(symbols[i]);
if (var instanceof VolVariable) {
String exactVarName = var.getName() + "_" + subDomain.getName() + "_exact";
substitutedExp.substituteInPlace(new Expression(var.getName()), new Expression(exactVarName));
} else if (var instanceof VolumeRegionVariable || var instanceof MemVariable || var instanceof MembraneRegionVariable || var instanceof FilamentVariable || var instanceof FilamentRegionVariable) {
throw new RuntimeException("variable substitution not yet implemented for Variable type " + var.getClass().getName() + "(" + var.getName() + ")");
}
}
substitutedExp.bindExpression(null);
return substitutedExp;
}
Aggregations