use of cbit.vcell.solvers.FiniteVolumeFileWriter in project vcell by virtualcell.
the class OptXmlWriter method getModelXML.
public static Element getModelXML(PdeObjectiveFunction pdeObjectiveFunction, String[] parameterNames) {
Element modelElement = new Element(OptXmlTags.Model_Tag);
try {
SpatialReferenceData refData = pdeObjectiveFunction.getReferenceData();
double refDataEndTime = refData.getDataByRow(refData.getNumDataRows() - 1)[0];
//
// post the problem either as an IDA or CVODE model
//
org.vcell.util.document.SimulationVersion simVersion = new org.vcell.util.document.SimulationVersion(new KeyValue("12345"), "name", new org.vcell.util.document.User("user", new KeyValue("123")), new org.vcell.util.document.GroupAccessNone(), // versionBranchPointRef
null, // branchID
new java.math.BigDecimal(1.0), new java.util.Date(), org.vcell.util.document.VersionFlag.Archived, "", null);
Simulation simulation = new Simulation(simVersion, pdeObjectiveFunction.getMathDescription());
simulation.getMeshSpecification().setSamplingSize(refData.getDataISize());
double[] times = refData.getDataByColumn(0);
double minDt = Double.POSITIVE_INFINITY;
for (int i = 1; i < times.length; i++) {
minDt = Math.min(minDt, times[i] - times[i - 1]);
}
simulation.getSolverTaskDescription().setTimeBounds(new cbit.vcell.solver.TimeBounds(0.0, refDataEndTime));
simulation.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolume);
simulation.getSolverTaskDescription().setTimeStep(new TimeStep(minDt / 5, minDt / 5, minDt / 5));
// clone and resample geometry
Geometry resampledGeometry = null;
try {
resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
ISize newSize = simulation.getMeshSpecification().getSamplingSize();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
} catch (Exception e) {
e.printStackTrace();
throw new SolverException(e.getMessage());
}
SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, pdeObjectiveFunction.getFieldDataIDSs()), 0);
StringWriter simulationInputStringWriter = new StringWriter();
FiniteVolumeFileWriter fvFileWriter = new FiniteVolumeFileWriter(new PrintWriter(simulationInputStringWriter, true), simTask, resampledGeometry, pdeObjectiveFunction.getWorkingDirectory());
fvFileWriter.write(parameterNames);
simulationInputStringWriter.close();
modelElement.setAttribute(OptXmlTags.ModelType_Attr, OptXmlTags.ModelType_Attr_FVSOLVER);
CDATA simulationInputText = new CDATA(simulationInputStringWriter.getBuffer().toString());
modelElement.addContent(simulationInputText);
} catch (Exception e) {
e.printStackTrace(System.out);
throw new OptimizationException("failed to create fv input file: " + e.getMessage());
}
return modelElement;
}
Aggregations