use of cbit.vcell.solver.Simulation in project vcell by virtualcell.
the class MathTestingUtilities method getConstructedResultSet.
/**
* Insert the method's description here.
* Creation date: (1/17/2003 3:47:43 PM)
* @return cbit.vcell.solver.ode.ODESolverResultSet
* @param sim cbit.vcell.solver.Simulation
*/
public static ODESolverResultSet getConstructedResultSet(MathDescription mathDesc, double[] time) throws Exception {
if (mathDesc.getGeometry().getDimension() != 0) {
throw new RuntimeException("can only handle non-spatial simulations.");
}
Simulation sim = new Simulation(mathDesc);
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, 0);
ODESolverResultSet resultSet = new ODESolverResultSet();
resultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
for (int i = 0; i < time.length; i++) {
resultSet.addRow(new double[] { time[i] });
}
java.util.Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
String errorString = "Variable(s) : ";
while (subDomainEnum.hasMoreElements()) {
SubDomain subDomain = subDomainEnum.nextElement();
java.util.Enumeration<Equation> enumEquations = subDomain.getEquations();
while (enumEquations.hasMoreElements()) {
Equation equation = enumEquations.nextElement();
Expression constructedSolution = equation.getExactSolution();
if (constructedSolution != null) {
constructedSolution = new Expression(constructedSolution);
constructedSolution.bindExpression(simSymbolTable);
constructedSolution = simSymbolTable.substituteFunctions(constructedSolution);
constructedSolution = constructedSolution.flatten();
resultSet.addFunctionColumn(new FunctionColumnDescription(constructedSolution, equation.getVariable().getName(), null, equation.getVariable().getName(), false));
} else {
errorString = errorString + equation.getVariable().getName() + ", ";
}
}
}
if (!errorString.equals("Variable(s) : ")) {
throw new RuntimeException(errorString + " don't have a constructed solution");
}
return resultSet;
}
use of cbit.vcell.solver.Simulation in project vcell by virtualcell.
the class MathTestingUtilities method getExactResultSet.
/**
* Insert the method's description here.
* Creation date: (1/17/2003 3:47:43 PM)
* @return cbit.vcell.solver.ode.ODESolverResultSet
* @param sim cbit.vcell.solver.Simulation
*/
public static ODESolverResultSet getExactResultSet(MathDescription mathDesc, double[] time, Constant sensitivityParam) throws Exception {
if (mathDesc.getGeometry().getDimension() != 0) {
throw new RuntimeException("can only handle non-spatial simulations.");
}
Simulation sim = new Simulation(mathDesc);
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, 0);
ODESolverResultSet resultSet = new ODESolverResultSet();
resultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
for (int i = 0; i < time.length; i++) {
resultSet.addRow(new double[] { time[i] });
}
java.util.Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
while (subDomainEnum.hasMoreElements()) {
SubDomain subDomain = subDomainEnum.nextElement();
java.util.Enumeration<Equation> enumEquations = subDomain.getEquations();
while (enumEquations.hasMoreElements()) {
Equation equation = enumEquations.nextElement();
Expression exactSolution = equation.getExactSolution();
if (exactSolution != null) {
exactSolution = new Expression(exactSolution);
exactSolution.bindExpression(simSymbolTable);
exactSolution = simSymbolTable.substituteFunctions(exactSolution);
exactSolution.bindExpression(simSymbolTable);
exactSolution = exactSolution.flatten();
resultSet.addFunctionColumn(new FunctionColumnDescription(exactSolution, equation.getVariable().getName(), null, equation.getVariable().getName(), false));
if (sensitivityParam != null) {
exactSolution = equation.getExactSolution();
Expression exactSensitivity = new Expression(exactSolution);
exactSensitivity.bindExpression(simSymbolTable);
exactSensitivity = simSymbolTable.substituteFunctions(exactSensitivity);
exactSensitivity.bindExpression(simSymbolTable);
exactSensitivity = exactSensitivity.differentiate(sensitivityParam.getName());
exactSensitivity = exactSensitivity.flatten();
VolVariable volVar = (VolVariable) equation.getVariable();
String sensName = SensVariable.getSensName(volVar, sensitivityParam);
resultSet.addFunctionColumn(new FunctionColumnDescription(exactSensitivity, sensName, null, sensName, false));
}
} else {
throw new RuntimeException("variable " + equation.getVariable().getName() + " doesn't have an exact solution");
}
}
}
return resultSet;
}
use of cbit.vcell.solver.Simulation in project vcell by virtualcell.
the class AbstractCompiledSolver method getProgress.
/**
* Insert the method's description here.
* Creation date: (6/28/01 2:48:52 PM)
* @return double
*/
public double getProgress() {
Simulation simulation = simTask.getSimulationJob().getSimulation();
TimeBounds timeBounds = simulation.getSolverTaskDescription().getTimeBounds();
double startTime = timeBounds.getStartingTime();
double endTime = timeBounds.getEndingTime();
return (currentTime - startTime) / (endTime - startTime);
}
use of cbit.vcell.solver.Simulation in project vcell by virtualcell.
the class FVSolverStandalone method getChomboCommands.
private Collection<ExecutableCommand> getChomboCommands() {
assert (isChombo);
ArrayList<ExecutableCommand> commands = new ArrayList<ExecutableCommand>(2);
String inputFilename = getInputFilename();
String executableName = null;
Simulation simulation = getSimulationJob().getSimulation();
SolverTaskDescription sTaskDesc = simulation.getSolverTaskDescription();
final boolean isParallel = sTaskDesc.isParallel();
int dimension = simulation.getMeshSpecification().getGeometry().getDimension();
switch(dimension) {
case 2:
try {
executableName = SolverUtilities.getExes(SolverDescription.Chombo)[0].getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("failed to get executable for 2D solver " + SolverDescription.Chombo.getDisplayLabel() + ": " + e.getMessage(), e);
}
break;
case 3:
try {
executableName = SolverUtilities.getExes(SolverDescription.Chombo)[1].getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("failed to get executable for 3D solver " + SolverDescription.Chombo.getDisplayLabel() + ": " + e.getMessage(), e);
}
break;
default:
throw new IllegalArgumentException("VCell Chombo solver does not support " + dimension + "problems");
}
if (isParallel) {
String parallelName = executableName + "parallel";
ExecutableCommand solve = new ExecutableCommand(new ExecutableCommand.LibraryPath(ResourceUtil.getLocalSolversDirectory().getAbsolutePath()), true, true, parallelName, inputFilename);
commands.add(solve);
ChomboSolverSpec css = sTaskDesc.getChomboSolverSpec();
Objects.requireNonNull(css);
if (css.isSaveVCellOutput()) {
ExecutableCommand convertChomboData = new ExecutableCommand(new ExecutableCommand.LibraryPath(ResourceUtil.getLocalSolversDirectory().getAbsolutePath()), true, false, executableName, "-ccd", inputFilename);
commands.add(convertChomboData);
}
} else {
ExecutableCommand ec = new ExecutableCommand(new ExecutableCommand.LibraryPath(ResourceUtil.getLocalSolversDirectory().getAbsolutePath()), true, false, executableName, inputFilename);
commands.add(ec);
primaryCommand = ec;
}
return commands;
}
use of cbit.vcell.solver.Simulation in project vcell by virtualcell.
the class FiniteVolumeFileWriter method write.
/**
* Insert the method's description here.
* Creation date: (5/9/2005 2:52:48 PM)
* @throws MathException
* @throws ExpressionException
* @throws DataAccessException
* @throws IOException
*/
public void write(String[] parameterNames) throws Exception {
Variable[] originalVars = null;
Simulation simulation = simTask.getSimulation();
MathDescription mathDesc = simulation.getMathDescription();
if (bChomboSolver) {
writeJMSParamters();
writeSimulationParamters();
writeModelDescription();
writeChomboSpec();
writeVariables();
writePostProcessingBlock();
writeCompartments();
writeMembranes();
} else {
if (simTask.getSimulation().isSerialParameterScan()) {
originalVars = (Variable[]) BeanUtils.getArray(mathDesc.getVariables(), Variable.class);
Variable[] allVars = (Variable[]) BeanUtils.getArray(mathDesc.getVariables(), Variable.class);
MathOverrides mathOverrides = simulation.getMathOverrides();
String[] scanParameters = mathOverrides.getOverridenConstantNames();
for (int i = 0; i < scanParameters.length; i++) {
String scanParameter = scanParameters[i];
Variable mathVariable = mathDesc.getVariable(scanParameter);
//
if (mathVariable instanceof Constant) {
Constant origConstant = (Constant) mathVariable;
for (int j = 0; j < allVars.length; j++) {
if (allVars[j].equals(origConstant)) {
allVars[j] = new ParameterVariable(origConstant.getName());
break;
}
}
}
}
mathDesc.setAllVariables(allVars);
}
writeJMSParamters();
writeSimulationParamters();
writeModelDescription();
writeMeshFile();
writeVariables();
if (mathDesc.isSpatialHybrid()) {
writeSmoldyn();
}
writeParameters(parameterNames);
writeSerialParameterScans();
writeFieldData();
writePostProcessingBlock();
writeCompartments();
writeMembranes();
if (originalVars != null) {
mathDesc.setAllVariables(originalVars);
}
}
}
Aggregations