use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class FiniteVolumeFileWriter method assignPhases.
private void assignPhases(CompartmentSubDomain[] subDomains, int startingIndex, int[] phases, int[] numAssigned) throws SolverException {
if (phases[startingIndex] == -1) {
return;
}
if (numAssigned[0] == subDomains.length) {
return;
}
for (int j = subDomains.length - 1; j >= 0; j--) {
if (startingIndex == j) {
continue;
}
MembraneSubDomain mem = getSimulationTask().getSimulation().getMathDescription().getMembraneSubDomain(subDomains[startingIndex], subDomains[j]);
if (mem != null) {
int newPhase = phases[startingIndex] == 0 ? 1 : 0;
if (phases[j] == -1) {
numAssigned[0]++;
// membrane between i and j, different phase
phases[j] = newPhase;
assignPhases(subDomains, j, phases, numAssigned);
} else if (phases[j] != newPhase) {
throw new SolverException("Geometry is invalid for " + getSimulationTask().getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + ": domains are not properly nested (membrane branching). \n\n(domain " + subDomains[j].getName() + " was assigned to phase " + phases[j] + ", is again being assigned to phase " + newPhase + ".)");
}
}
}
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class FiniteVolumeFileWriter method writePostProcessingBlock.
private void writePostProcessingBlock() throws Exception {
// SolverException, ExpressionException and exceptions from roiDataGenerator.getROIDataGeneratorDescription()
PostProcessingBlock postProcessingBlock = simTask.getSimulation().getMathDescription().getPostProcessingBlock();
if (postProcessingBlock.getNumDataGenerators() == 0) {
// to make c++ code write default var statisitcs, without the token it won't write anything
printWriter.println(FVInputFileKeyword.POST_PROCESSING_BLOCK_BEGIN);
printWriter.println(FVInputFileKeyword.POST_PROCESSING_BLOCK_END);
printWriter.println();
return;
}
if (bChomboSolver && postProcessingBlock.getDataGeneratorList().size() > 0) {
throw new Exception("Data generators are not supported by " + simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel());
}
printWriter.println(" # Post Processing Block");
printWriter.println(FVInputFileKeyword.POST_PROCESSING_BLOCK_BEGIN);
for (DataGenerator dataGenerator : postProcessingBlock.getDataGeneratorList()) {
String varName = dataGenerator.getName();
Domain domain = dataGenerator.getDomain();
String domainName = domain == null ? null : domain.getName();
if (dataGenerator instanceof ProjectionDataGenerator) {
ProjectionDataGenerator pdg = (ProjectionDataGenerator) dataGenerator;
Expression function = subsituteExpression(pdg.getFunction(), VariableDomain.VARIABLEDOMAIN_VOLUME);
printWriter.println(FVInputFileKeyword.PROJECTION_DATA_GENERATOR + " " + varName + " " + domainName + " " + pdg.getAxis() + " " + pdg.getOperation() + " " + function.infix() + ";");
} else if (dataGenerator instanceof ConvolutionDataGenerator) {
ConvolutionDataGenerator convolutionDataGenerator = (ConvolutionDataGenerator) dataGenerator;
ConvolutionDataGeneratorKernel kernel = convolutionDataGenerator.getKernel();
if (kernel instanceof GaussianConvolutionDataGeneratorKernel) {
GaussianConvolutionDataGeneratorKernel gck = (GaussianConvolutionDataGeneratorKernel) kernel;
Expression volFunction = subsituteExpression(convolutionDataGenerator.getVolFunction(), VariableDomain.VARIABLEDOMAIN_VOLUME);
Expression memFunction = subsituteExpression(convolutionDataGenerator.getMemFunction(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
Expression sigmaXY = subsituteExpression(gck.getSigmaXY_um(), VariableDomain.VARIABLEDOMAIN_VOLUME);
Expression sigmaZ = subsituteExpression(gck.getSigmaZ_um(), VariableDomain.VARIABLEDOMAIN_VOLUME);
String volFuncStr = volFunction.infix();
String memFuncStr = memFunction.infix();
printWriter.println(FVInputFileKeyword.GAUSSIAN_CONVOLUTION_DATA_GENERATOR + " " + varName + " " + domainName + " " + sigmaXY.infix() + " " + sigmaZ.infix() + " " + FVInputFileKeyword.GAUSSIAN_CONVOLUTION_VOL_FUNCTION + " " + volFuncStr + "; " + FVInputFileKeyword.GAUSSIAN_CONVOLUTION_MEM_FUNCTION + " " + memFuncStr + ";");
}
} else if (dataGenerator instanceof cbit.vcell.microscopy.ROIDataGenerator) {
/*
ROI_DATA_GENERATOR_BEGIN roidata
VolumePoints 20
2667 2676 2679 2771 2969 2877 3067 3277 3185 3283 3473 3580 3690 3687 3878 4086 3990 4182 4193 1077 (all points in one line)
SampleImage 9 0 1341426862190 vcField('sumROIData','roiSumDataVar',0.0,'Volume')
StoreEnabled false
SampleImageFile roiSumDataVar 0.0 C:\Users\abcde\VirtualMicroscopy\SimulationData\SimID_1341426862125_0_sumROIData_roiSumDataVar_0_0_Volume.fdat
DATA_PROCESSOR_END
*/
cbit.vcell.microscopy.ROIDataGenerator roiDataGenerator = (cbit.vcell.microscopy.ROIDataGenerator) dataGenerator;
printWriter.println(roiDataGenerator.getROIDataGeneratorDescription(workingDirectory, simTask.getSimulationJob()));
} else if (dataGenerator instanceof org.vcell.vmicro.workflow.data.ROIDataGenerator) {
/*
ROI_DATA_GENERATOR_BEGIN roidata
VolumePoints 20
2667 2676 2679 2771 2969 2877 3067 3277 3185 3283 3473 3580 3690 3687 3878 4086 3990 4182 4193 1077 (all points in one line)
SampleImage 9 0 1341426862190 vcField('sumROIData','roiSumDataVar',0.0,'Volume')
StoreEnabled false
SampleImageFile roiSumDataVar 0.0 C:\Users\abcde\VirtualMicroscopy\SimulationData\SimID_1341426862125_0_sumROIData_roiSumDataVar_0_0_Volume.fdat
DATA_PROCESSOR_END
*/
org.vcell.vmicro.workflow.data.ROIDataGenerator roiDataGenerator = (org.vcell.vmicro.workflow.data.ROIDataGenerator) dataGenerator;
printWriter.println(roiDataGenerator.getROIDataGeneratorDescription(workingDirectory, simTask.getSimulationJob()));
} else {
throw new SolverException(dataGenerator.getClass() + " : data generator not supported yet.");
}
}
printWriter.println(FVInputFileKeyword.POST_PROCESSING_BLOCK_END);
printWriter.println();
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class HTCSolver method writeJavaInputFile.
protected void writeJavaInputFile() throws SolverException {
PrintWriter pw = null;
try {
File inputFile = new File(getBaseName() + JAVA_INPUT_EXTENSION);
if (!inputFile.exists()) {
// write input file which is just xml
String xmlString = XmlHelper.simToXML(simTask.getSimulation());
pw = new PrintWriter(inputFile);
pw.println(xmlString);
pw.close();
}
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
} finally {
if (pw != null) {
pw.close();
}
}
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class MovingBoundaryFileWriter method writeMovingBoundaryXML.
//
// XML producer - here all the work is done
//
public Element writeMovingBoundaryXML(SimulationTask simTask) throws SolverException {
try {
int subdomainsWithPdeEquations = subdomainsSanityCheck();
if (subdomainsWithPdeEquations != 1) {
throw new RuntimeException("MovingBoundary Solver only accepts ONE subdomain containing PDE equations.");
}
Element rootElement = new Element(MBTags.MovingBoundarySetup);
if (bUseMessaging) {
// jms
rootElement.addContent(getXMLJms());
}
// problem
rootElement.addContent(getXMLProblem());
// report
rootElement.addContent(getXMLReport());
// progress
rootElement.addContent(getXMLProgress());
// trace
rootElement.addContent(getXMLTrace());
// debug
rootElement.addContent(getXMLDebug());
Element tr = getXMLTextReport();
if (tr != null) {
rootElement.addContent(tr);
}
return rootElement;
} catch (Exception e) {
throw new SolverException("Can't generate MovingBoundary input", e);
}
}
use of cbit.vcell.solver.SolverException 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