use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class TestingFrameworkWindowManager method addTestCases.
/**
* Insert the method's description here.
* Creation date: (4/10/2003 11:27:32 AM)
* @param testCase cbit.vcell.numericstestingframework.TestCase
*/
public String addTestCases(final TestSuiteInfoNew tsInfo, final TestCaseNew[] testCaseArray, int regrRefFlag, ClientTaskStatusSupport pp) {
if (tsInfo == null) {
throw new IllegalArgumentException("TestSuiteInfo cannot be null");
}
if (testCaseArray == null || testCaseArray.length == 0) {
throw new IllegalArgumentException("TestCases cannot be null / empty");
}
// make modifiable list
List<TestCaseNew> testCases = new ArrayList<>(Arrays.asList(testCaseArray));
StringBuffer errors = new StringBuffer();
// When a testCase (mathmodel/biomodel) is added to a testSuite, a new version of the mathModel/biomodel should be created.
// Also, the simulations in the original mathmodel/biomodel should be rid of their parent simulation reference.
pp.setMessage("Getting testSuite");
pp.setProgress(1);
TestSuiteNew testSuite = null;
try {
testSuite = getRequestManager().getDocumentManager().getTestSuite(tsInfo.getTSKey());
} catch (Throwable e) {
throw new RuntimeException("couldn't get test suite " + tsInfo.getTSID() + "\n" + e.getClass().getName() + " mesg=" + e.getMessage() + "\n");
}
if (testSuite != null && testSuite.getTSInfoNew().isLocked()) {
throw new RuntimeException("Cannot addTestCases to locked table");
}
if (testSuite != null) {
// Saving BioModels
TestCaseNew[] existingTestCases = testSuite.getTestCases();
java.util.HashMap<KeyValue, BioModel> bioModelHashMap = new java.util.HashMap<KeyValue, BioModel>();
// if(existingTestCases != null){
// Find BioModels, Using the same BM reference for sibling Applications
int pcounter = 0;
// use iterator to allow removal of test case from collection if exception
Iterator<TestCaseNew> iter = testCases.iterator();
while (iter.hasNext()) {
TestCaseNew testCase = iter.next();
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
if (testCase instanceof TestCaseNewBioModel) {
TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
//
if (bioModelHashMap.get(bioTestCase.getBioModelInfo().getVersion().getVersionKey()) == null) {
pp.setMessage("Getting BM " + testCase.getVersion().getName());
BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bioTestCase.getBioModelInfo().getVersion().getVersionKey());
if (!bioModel.getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
throw new Exception("BioModel does not belong to VCELLTESTACCOUNT, cannot proceed with test!");
}
//
// if biomodel already exists in same testsuite, then use this BioModel edition
//
BioModel newBioModel = null;
if (existingTestCases != null) {
for (int j = 0; newBioModel == null && j < existingTestCases.length; j++) {
if (existingTestCases[j] instanceof TestCaseNewBioModel) {
TestCaseNewBioModel existingTestCaseBioModel = (TestCaseNewBioModel) existingTestCases[j];
//
if (existingTestCaseBioModel.getBioModelInfo().getVersion().getBranchID().equals(bioTestCase.getBioModelInfo().getVersion().getBranchID())) {
//
if (existingTestCaseBioModel.getBioModelInfo().getVersion().getVersionKey().equals(bioTestCase.getBioModelInfo().getVersion().getVersionKey())) {
//
// same, store this "unchanged" in bioModelHashMap
//
newBioModel = bioModel;
} else {
//
throw new Exception("can't add new test case using (" + bioTestCase.getBioModelInfo().getVersion().getName() + " " + bioTestCase.getBioModelInfo().getVersion().getDate() + ")\n" + "a test case already exists with different edition of same BioModel dated " + existingTestCaseBioModel.getBioModelInfo().getVersion().getDate());
}
}
}
}
}
if (newBioModel == null) {
pp.setMessage("Saving BM " + testCase.getVersion().getName());
//
// some older models have membrane voltage variable names which are not unique
// (e.g. membranes 'pm' and 'nm' both have membrane voltage variables named 'Voltage_Membrane0')
//
// if this is the case, we will try to repair the conflict (for math testing purposes only) by renaming the voltage variables to their default values.
//
// Ordinarily, the conflict will be identified as an "Error" issue and the user will be prompted to repair before saving or math generation.
//
bioModel.refreshDependencies();
boolean bFoundIdentifierConflictUponLoading = hasDuplicateIdentifiers(bioModel);
if (bFoundIdentifierConflictUponLoading) {
//
// look for two MembraneVoltage instances with same variable name, rename all
//
HashSet<String> membraneVoltageVarNames = new HashSet<String>();
ArrayList<MembraneVoltage> membraneVoltageVars = new ArrayList<MembraneVoltage>();
for (Structure struct : bioModel.getModel().getStructures()) {
if (struct instanceof Membrane) {
MembraneVoltage membraneVoltage = ((Membrane) struct).getMembraneVoltage();
if (membraneVoltage != null) {
membraneVoltageVars.add(membraneVoltage);
membraneVoltageVarNames.add(membraneVoltage.getName());
}
}
}
if (membraneVoltageVars.size() != membraneVoltageVarNames.size()) {
// rename them all to the default names
for (MembraneVoltage memVoltage : membraneVoltageVars) {
memVoltage.setName(Membrane.getDefaultMembraneVoltageName(memVoltage.getMembrane().getName()));
}
}
}
SimulationContext[] simContexts = bioModel.getSimulationContexts();
for (int j = 0; j < simContexts.length; j++) {
simContexts[j].clearVersion();
GeometrySurfaceDescription gsd = simContexts[j].getGeometry().getGeometrySurfaceDescription();
if (gsd != null) {
GeometricRegion[] grArr = gsd.getGeometricRegions();
if (grArr == null) {
gsd.updateAll();
}
}
MathMapping mathMapping = simContexts[j].createNewMathMapping();
// for older models that do not have absolute compartment sizes set, but have relative sizes (SVR/VF); or if there is only one compartment with size not set,
// compute absolute compartment sizes using relative sizes and assuming a default value of '1' for one of the compartments.
// Otherwise, the math generation will fail, since for the relaxed topology (VCell 5.3 and later) absolute compartment sizes are required.
GeometryContext gc = simContexts[j].getGeometryContext();
if (simContexts[j].getGeometry().getDimension() == 0 && ((gc.isAllSizeSpecifiedNull() && !gc.isAllVolFracAndSurfVolSpecifiedNull()) || (gc.getModel().getStructures().length == 1 && gc.isAllSizeSpecifiedNull()))) {
// choose the first structure in model and set its size to '1'.
Structure struct = simContexts[j].getModel().getStructure(0);
double structSize = 1.0;
StructureSizeSolver.updateAbsoluteStructureSizes(simContexts[j], struct, structSize, struct.getStructureSize().getUnitDefinition());
}
simContexts[j].setMathDescription(mathMapping.getMathDescription());
}
Simulation[] sims = bioModel.getSimulations();
String[] simNames = new String[sims.length];
for (int j = 0; j < sims.length; j++) {
// prevents parent simulation (from the original mathmodel) reference connection
// Otherwise it will refer to data from previous (parent) simulation.
sims[j].clearVersion();
simNames[j] = sims[j].getName();
// if(sims[j].getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)){
// sims[j].getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
// }
}
newBioModel = getRequestManager().getDocumentManager().save(bioModel, simNames);
}
bioModelHashMap.put(bioTestCase.getBioModelInfo().getVersion().getVersionKey(), newBioModel);
}
}
} catch (Throwable e) {
String identifier = testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey();
if (lg.isInfoEnabled()) {
lg.info(identifier, e);
}
errors.append("Error collecting BioModel for TestCase " + identifier + '\n' + e.getClass().getName() + " " + e.getMessage() + '\n');
// remove to avoid further processing attempts
iter.remove();
}
}
// }
// then process each BioModelTestCase individually
// if(bioModelHashMap != null){
pcounter = 0;
for (TestCaseNew testCase : testCases) {
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
AddTestCasesOP testCaseOP = null;
if (testCase instanceof TestCaseNewBioModel) {
pp.setMessage("Processing BM " + testCase.getVersion().getName());
TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
BioModel newBioModel = (BioModel) bioModelHashMap.get(bioTestCase.getBioModelInfo().getVersion().getVersionKey());
if (newBioModel == null) {
throw new Exception("BioModel not found");
}
SimulationContext simContext = null;
for (int j = 0; j < newBioModel.getSimulationContexts().length; j++) {
if (newBioModel.getSimulationContext(j).getName().equals(bioTestCase.getSimContextName())) {
simContext = newBioModel.getSimulationContext(j);
}
}
Simulation[] newSimulations = simContext.getSimulations();
AddTestCriteriaOPBioModel[] testCriteriaOPs = new AddTestCriteriaOPBioModel[newSimulations.length];
for (int j = 0; j < newSimulations.length; j++) {
TestCriteriaNewBioModel tcritOrigForSimName = null;
for (int k = 0; bioTestCase.getTestCriterias() != null && k < bioTestCase.getTestCriterias().length; k += 1) {
if (bioTestCase.getTestCriterias()[k].getSimInfo().getName().equals(newSimulations[j].getName())) {
tcritOrigForSimName = (TestCriteriaNewBioModel) bioTestCase.getTestCriterias()[k];
break;
}
}
KeyValue regressionBioModelKey = null;
KeyValue regressionBioModelSimKey = null;
if (bioTestCase.getType().equals(TestCaseNew.REGRESSION)) {
if (regrRefFlag == TestingFrameworkWindowManager.COPY_REGRREF) {
regressionBioModelKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionBioModelInfo() != null ? tcritOrigForSimName.getRegressionBioModelInfo().getVersion().getVersionKey() : null);
regressionBioModelSimKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionSimInfo() != null ? tcritOrigForSimName.getRegressionSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNORIGINAL_REGRREF) {
regressionBioModelKey = (tcritOrigForSimName != null ? bioTestCase.getBioModelInfo().getVersion().getVersionKey() : null);
regressionBioModelSimKey = (tcritOrigForSimName != null ? tcritOrigForSimName.getSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNNEW_REGRREF) {
regressionBioModelKey = newBioModel.getVersion().getVersionKey();
regressionBioModelSimKey = newSimulations[j].getVersion().getVersionKey();
} else {
throw new IllegalArgumentException(this.getClass().getName() + ".addTestCases(...) BIOMODEL Unknown Regression Operation Flag");
}
}
testCriteriaOPs[j] = new AddTestCriteriaOPBioModel(testCase.getTCKey(), newSimulations[j].getVersion().getVersionKey(), regressionBioModelKey, regressionBioModelSimKey, (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxAbsError() : new Double(1e-16)), (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxRelError() : new Double(1e-9)), null);
}
testCaseOP = new AddTestCasesOPBioModel(new BigDecimal(tsInfo.getTSKey().toString()), newBioModel.getVersion().getVersionKey(), simContext.getKey(), bioTestCase.getType(), bioTestCase.getAnnotation(), testCriteriaOPs);
getRequestManager().getDocumentManager().doTestSuiteOP(testCaseOP);
}
} catch (Throwable e) {
errors.append("Error processing Biomodel for TestCase " + (testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey()) + "\n" + e.getClass().getName() + " " + e.getMessage() + "\n");
}
}
// }
// Process MathModels
pcounter = 0;
for (TestCaseNew testCase : testCases) {
pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
pp.setMessage("Checking " + testCase.getVersion().getName());
try {
AddTestCasesOP testCaseOP = null;
if (testCase instanceof TestCaseNewMathModel) {
TestCaseNewMathModel mathTestCase = (TestCaseNewMathModel) testCase;
pp.setMessage("Getting MathModel " + testCase.getVersion().getName());
MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mathTestCase.getMathModelInfo().getVersion().getVersionKey());
if (!mathModel.getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
throw new Exception("MathModel does not belong to VCELLTESTACCOUNT, cannot proceed with test!");
}
Simulation[] sims = mathModel.getSimulations();
String[] simNames = new String[sims.length];
for (int j = 0; j < sims.length; j++) {
// prevents parent simulation (from the original mathmodel) reference connection
// Otherwise it will refer to data from previous (parent) simulation.
sims[j].clearVersion();
simNames[j] = sims[j].getName();
// if(sims[j].getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)){
// sims[j].getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
// }
}
pp.setMessage("Saving MathModel " + testCase.getVersion().getName());
MathModel newMathModel = getRequestManager().getDocumentManager().save(mathModel, simNames);
Simulation[] newSimulations = newMathModel.getSimulations();
AddTestCriteriaOPMathModel[] testCriteriaOPs = new AddTestCriteriaOPMathModel[newSimulations.length];
for (int j = 0; j < newSimulations.length; j++) {
TestCriteriaNewMathModel tcritOrigForSimName = null;
for (int k = 0; mathTestCase.getTestCriterias() != null && k < mathTestCase.getTestCriterias().length; k += 1) {
if (mathTestCase.getTestCriterias()[k].getSimInfo().getName().equals(newSimulations[j].getName())) {
tcritOrigForSimName = (TestCriteriaNewMathModel) mathTestCase.getTestCriterias()[k];
break;
}
}
KeyValue regressionMathModelKey = null;
KeyValue regressionMathModelSimKey = null;
if (mathTestCase.getType().equals(TestCaseNew.REGRESSION)) {
if (regrRefFlag == TestingFrameworkWindowManager.COPY_REGRREF) {
regressionMathModelKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionMathModelInfo() != null ? tcritOrigForSimName.getRegressionMathModelInfo().getVersion().getVersionKey() : null);
regressionMathModelSimKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionSimInfo() != null ? tcritOrigForSimName.getRegressionSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNORIGINAL_REGRREF) {
regressionMathModelKey = (tcritOrigForSimName != null ? mathTestCase.getMathModelInfo().getVersion().getVersionKey() : null);
regressionMathModelSimKey = (tcritOrigForSimName != null ? tcritOrigForSimName.getSimInfo().getVersion().getVersionKey() : null);
} else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNNEW_REGRREF) {
regressionMathModelKey = newMathModel.getVersion().getVersionKey();
regressionMathModelSimKey = newSimulations[j].getVersion().getVersionKey();
} else {
throw new IllegalArgumentException(this.getClass().getName() + ".addTestCases(...) MATHMODEL Unknown Regression Operation Flag");
}
}
testCriteriaOPs[j] = new AddTestCriteriaOPMathModel(testCase.getTCKey(), newSimulations[j].getVersion().getVersionKey(), regressionMathModelKey, regressionMathModelSimKey, (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxAbsError() : new Double(1e-16)), (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxRelError() : new Double(1e-9)), null);
}
testCaseOP = new AddTestCasesOPMathModel(new BigDecimal(tsInfo.getTSKey().toString()), newMathModel.getVersion().getVersionKey(), mathTestCase.getType(), mathTestCase.getAnnotation(), testCriteriaOPs);
getRequestManager().getDocumentManager().doTestSuiteOP(testCaseOP);
}
} catch (Throwable e) {
errors.append("Error processing MathModel for TestCase " + (testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey()) + "\n" + e.getClass().getName() + " " + e.getMessage() + "\n");
}
}
}
if (errors.length() > 0) {
return errors.toString();
}
return null;
}
use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class FiniteVolumeFileWriter method writeChomboSpec.
private void writeChomboSpec() throws ExpressionException, SolverException, PropertyVetoException, ClassNotFoundException, IOException, GeometryException, ImageException {
if (!bChomboSolver) {
return;
}
GeometrySpec geometrySpec = resampledGeometry.getGeometrySpec();
int dimension = geometrySpec.getDimension();
if (dimension == 1) {
throw new SolverException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " is only supported for simulations with 2D or 3D geometry.");
}
Simulation simulation = getSimulationTask().getSimulation();
SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
ChomboSolverSpec chomboSolverSpec = solverTaskDescription.getChomboSolverSpec();
printWriter.println(FVInputFileKeyword.CHOMBO_SPEC_BEGIN);
printWriter.println(FVInputFileKeyword.DIMENSION + " " + geometrySpec.getDimension());
Extent extent = geometrySpec.getExtent();
Origin origin = geometrySpec.getOrigin();
ISize isize = simulation.getMeshSpecification().getSamplingSize();
switch(geometrySpec.getDimension()) {
case 2:
printWriter.println(FVInputFileKeyword.MESH_SIZE + " " + isize.getX() + " " + isize.getY());
printWriter.println(FVInputFileKeyword.DOMAIN_SIZE + " " + extent.getX() + " " + extent.getY());
printWriter.println(FVInputFileKeyword.DOMAIN_ORIGIN + " " + origin.getX() + " " + origin.getY());
break;
case 3:
printWriter.println(FVInputFileKeyword.MESH_SIZE + " " + isize.getX() + " " + isize.getY() + " " + isize.getZ());
printWriter.println(FVInputFileKeyword.DOMAIN_SIZE + " " + extent.getX() + " " + extent.getY() + " " + extent.getZ());
printWriter.println(FVInputFileKeyword.DOMAIN_ORIGIN + " " + origin.getX() + " " + origin.getY() + " " + origin.getZ());
break;
}
List<CompartmentSubDomain> featureList = new ArrayList<CompartmentSubDomain>();
Enumeration<SubDomain> enum1 = simulation.getMathDescription().getSubDomains();
while (enum1.hasMoreElements()) {
SubDomain sd = enum1.nextElement();
if (sd instanceof CompartmentSubDomain) {
featureList.add((CompartmentSubDomain) sd);
}
}
int numFeatures = featureList.size();
CompartmentSubDomain[] features = featureList.toArray(new CompartmentSubDomain[0]);
int[] phases = new int[numFeatures];
Arrays.fill(phases, -1);
phases[numFeatures - 1] = 0;
int[] numAssigned = new int[] { 1 };
assignPhases(features, numFeatures - 1, phases, numAssigned);
Map<String, Integer> subDomainPhaseMap = new HashMap<String, Integer>();
for (int i = 0; i < phases.length; ++i) {
if (phases[i] == -1) {
throw new SolverException("Failed to assign a phase to CompartmentSubdomain '" + features[i].getName() + "'. It might be caused by too coarsh a mesh.");
}
subDomainPhaseMap.put(features[i].getName(), phases[i]);
}
SubVolume[] subVolumes = geometrySpec.getSubVolumes();
if (geometrySpec.hasImage()) {
Geometry geometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
Geometry simGeometry = geometry;
VCImage img = geometry.getGeometrySpec().getImage();
int factor = Math.max(Math.max(img.getNumX(), img.getNumY()), img.getNumZ()) < 512 ? 2 : 1;
ISize distanceMapMeshSize = new ISize(img.getNumX() * factor, img.getNumY() * factor, img.getNumZ() * factor);
Vect3d deltaX = null;
boolean bCellCentered = false;
double dx = 0.5;
double dy = 0.5;
double dz = 0.5;
int Nx = distanceMapMeshSize.getX();
int Ny = distanceMapMeshSize.getY();
int Nz = distanceMapMeshSize.getZ();
if (dimension == 2) {
// pad the 2D image with itself in order to obtain a 3D image used to compute the distance map
// because the distance map algorithm is 3D only (using distance to triangles)
byte[] oldPixels = img.getPixels();
byte[] newPixels = new byte[oldPixels.length * 3];
System.arraycopy(oldPixels, 0, newPixels, 0, oldPixels.length);
System.arraycopy(oldPixels, 0, newPixels, oldPixels.length, oldPixels.length);
System.arraycopy(oldPixels, 0, newPixels, oldPixels.length * 2, oldPixels.length);
double distX = geometry.getExtent().getX() / img.getNumX();
double distY = geometry.getExtent().getY() / img.getNumY();
// we set the distance on the z axis to something that makes sense
double distZ = Math.max(distX, distY);
Extent newExtent = new Extent(geometry.getExtent().getX(), geometry.getExtent().getY(), distZ * 3);
VCImage newImage = new VCImageUncompressed(null, newPixels, newExtent, img.getNumX(), img.getNumY(), 3);
// copy the pixel classes too
ArrayList<VCPixelClass> newPixelClasses = new ArrayList<VCPixelClass>();
for (VCPixelClass origPixelClass : geometry.getGeometrySpec().getImage().getPixelClasses()) {
SubVolume origSubvolume = geometry.getGeometrySpec().getImageSubVolumeFromPixelValue(origPixelClass.getPixel());
newPixelClasses.add(new VCPixelClass(null, origSubvolume.getName(), origPixelClass.getPixel()));
}
newImage.setPixelClasses(newPixelClasses.toArray(new VCPixelClass[newPixelClasses.size()]));
simGeometry = new Geometry(geometry, newImage);
Nz = 3;
}
GeometrySpec simGeometrySpec = simGeometry.getGeometrySpec();
Extent simExtent = simGeometrySpec.getExtent();
dx = simExtent.getX() / (Nx - 1);
dy = simExtent.getY() / (Ny - 1);
dz = simExtent.getZ() / (Nz - 1);
if (Math.abs(dx - dy) > 0.1 * Math.max(dx, dy)) {
dx = Math.min(dx, dy);
dy = dx;
Nx = (int) (simExtent.getX() / dx + 1);
Ny = (int) (simExtent.getY() / dx + 1);
if (dimension == 3) {
dz = dx;
Nz = (int) (simExtent.getZ() / dx + 1);
}
}
deltaX = new Vect3d(dx, dy, dz);
// one more point in each direction
distanceMapMeshSize = new ISize(Nx + 1, Ny + 1, Nz + 1);
Extent distanceMapExtent = new Extent(simExtent.getX() + dx, simExtent.getY() + dy, simExtent.getZ() + dz);
simGeometrySpec.setExtent(distanceMapExtent);
GeometrySurfaceDescription geoSurfaceDesc = simGeometry.getGeometrySurfaceDescription();
geoSurfaceDesc.setVolumeSampleSize(distanceMapMeshSize);
geoSurfaceDesc.updateAll();
VCImage vcImage = RayCaster.sampleGeometry(simGeometry, distanceMapMeshSize, bCellCentered);
SubvolumeSignedDistanceMap[] distanceMaps = DistanceMapGenerator.computeDistanceMaps(simGeometry, vcImage, bCellCentered);
if (dimension == 2) {
distanceMaps = DistanceMapGenerator.extractMiddleSlice(distanceMaps);
}
printWriter.println(FVInputFileKeyword.SUBDOMAINS + " " + simGeometrySpec.getNumSubVolumes() + " " + FVInputFileKeyword.DISTANCE_MAP);
for (int i = 0; i < subVolumes.length; i++) {
File distanceMapFile = new File(workingDirectory, getSimulationTask().getSimulationJobID() + "_" + subVolumes[i].getName() + DISTANCE_MAP_FILE_EXTENSION);
writeDistanceMapFile(deltaX, distanceMaps[i], distanceMapFile);
int phase = subDomainPhaseMap.get(subVolumes[i].getName());
printWriter.println(subVolumes[i].getName() + " " + phase + " " + distanceMapFile.getAbsolutePath());
}
} else {
printWriter.println(FVInputFileKeyword.SUBDOMAINS + " " + geometrySpec.getNumSubVolumes());
Expression[] rvachevExps = convertAnalyticGeometryToRvachevFunction(geometrySpec);
for (int i = 0; i < subVolumes.length; i++) {
if (subVolumes[i] instanceof AnalyticSubVolume) {
String name = subVolumes[i].getName();
int phase = subDomainPhaseMap.get(name);
printWriter.println(name + " " + phase + " ");
printWriter.println(FVInputFileKeyword.IF + " " + rvachevExps[i].infix() + ";");
printWriter.println(FVInputFileKeyword.USER + " " + ((AnalyticSubVolume) subVolumes[i]).getExpression().infix() + ";");
}
}
}
printWriter.println(FVInputFileKeyword.MAX_BOX_SIZE + " " + chomboSolverSpec.getMaxBoxSize());
printWriter.println(FVInputFileKeyword.FILL_RATIO + " " + chomboSolverSpec.getFillRatio());
printWriter.println(FVInputFileKeyword.RELATIVE_TOLERANCE + " " + simulation.getSolverTaskDescription().getErrorTolerance().getRelativeErrorTolerance());
printWriter.println(FVInputFileKeyword.SAVE_VCELL_OUTPUT + " " + chomboSolverSpec.isSaveVCellOutput());
printWriter.println(FVInputFileKeyword.SAVE_CHOMBO_OUTPUT + " " + chomboSolverSpec.isSaveChomboOutput());
printWriter.println(FVInputFileKeyword.ACTIVATE_FEATURE_UNDER_DEVELOPMENT + " " + chomboSolverSpec.isActivateFeatureUnderDevelopment());
printWriter.println(FVInputFileKeyword.SMALL_VOLFRAC_THRESHOLD + " " + chomboSolverSpec.getSmallVolfracThreshold());
printWriter.println(FVInputFileKeyword.BLOCK_FACTOR + " " + chomboSolverSpec.getBlockFactor());
printWriter.println(FVInputFileKeyword.TAGS_GROW + " " + chomboSolverSpec.getTagsGrow());
// Refinement
int numLevels = chomboSolverSpec.getNumRefinementLevels();
// Refinements #Levels ratio 1, ratio 2, etc
printWriter.print(FVInputFileKeyword.REFINEMENTS + " " + (numLevels + 1));
List<Integer> ratios = chomboSolverSpec.getRefineRatioList();
for (int i : ratios) {
printWriter.print(" " + i);
}
// write last refinement ratio, fake
printWriter.println(" 2");
// membrane rois
List<RefinementRoi> memRios = chomboSolverSpec.getMembraneRefinementRois();
printWriter.println(FVInputFileKeyword.REFINEMENT_ROIS + " " + RoiType.Membrane + " " + memRios.size());
for (RefinementRoi roi : memRios) {
if (roi.getRoiExpression() == null) {
throw new SolverException("ROI expression cannot be null");
}
// level tagsGrow ROIexpression
printWriter.println(roi.getLevel() + " " + roi.getRoiExpression().infix() + ";");
}
List<RefinementRoi> volRios = chomboSolverSpec.getVolumeRefinementRois();
printWriter.println(FVInputFileKeyword.REFINEMENT_ROIS + " " + RoiType.Volume + " " + volRios.size());
for (RefinementRoi roi : volRios) {
if (roi.getRoiExpression() == null) {
throw new SolverException("ROI expression cannot be null");
}
printWriter.println(roi.getLevel() + " " + roi.getRoiExpression().infix() + ";");
}
printWriter.println(FVInputFileKeyword.VIEW_LEVEL + " " + chomboSolverSpec.getViewLevel());
printWriter.println(FVInputFileKeyword.CHOMBO_SPEC_END);
printWriter.println();
}
use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class MovingBoundarySolver method getResampledGeometry.
/*
@Override
protected String[] getMathExecutableCommand() {
String exeSuffix = System.getProperty(PropertyLoader.exesuffixProperty); // ".exe";
String baseName = "MovingBoundary" ;
File exeFile = new File(getSaveDirectory(), baseName + exeSuffix);
return new String[] { exeFile.getAbsolutePath() };
}
*/
public Geometry getResampledGeometry() throws SolverException {
if (resampledGeometry == null) {
// clone and resample geometry
try {
resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simTask.getSimulation().getMathDescription().getGeometry());
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
ISize newSize = simTask.getSimulation().getMeshSpecification().getSamplingSize();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
} catch (Exception e) {
e.printStackTrace();
throw new SolverException(e.getMessage());
}
}
return resampledGeometry;
}
use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class GeomDbDriver method insertGeometrySurfaceDescriptionSQL.
/**
* This method was created in VisualAge.
* @param vcimage cbit.image.VCImage
* @param userid java.lang.String
* @exception java.rmi.RemoteException The exception description.
*/
// default access for this method, to allow retrofitting surfaces to geometries.
void insertGeometrySurfaceDescriptionSQL(InsertHashtable hash, Connection con, Geometry geom, KeyValue geomKey) throws SQLException, cbit.image.ImageException, DataAccessException, ObjectNotFoundException {
String sql;
GeometrySurfaceDescription geoSurfaceDescription = geom.getGeometrySurfaceDescription();
//
// store GeometrySurfaceDescription (sampleSize and filterFrequency for now)
//
KeyValue newGeomSurfDescKey = keyFactory.getNewKey(con);
sql = "INSERT INTO " + geoSurfaceTable.getTableName() + " " + geoSurfaceTable.getSQLColumnList() + " VALUES " + geoSurfaceTable.getSQLValueList(newGeomSurfDescKey, geoSurfaceDescription, geomKey);
// System.out.println(sql);
updateCleanSQL(con, sql);
//
// store GeometricRegions
//
GeometricRegion[] regions = geoSurfaceDescription.getGeometricRegions();
// }
if (regions == null) {
throw new DataAccessException("geometry '" + geom.getName() + " didn't have region information");
}
//
for (int i = 0; i < regions.length; i++) {
if (regions[i] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion volumeRegion = (VolumeGeometricRegion) regions[i];
if (hash.getDatabaseKey(volumeRegion) == null) {
KeyValue newVolumeRegionKey = keyFactory.getNewKey(con);
KeyValue subvolumeKey = hash.getDatabaseKey(volumeRegion.getSubVolume());
sql = "INSERT INTO " + geoRegionTable.getTableName() + " " + geoRegionTable.getSQLColumnList() + " VALUES " + geoRegionTable.getSQLValueList(newVolumeRegionKey, volumeRegion, subvolumeKey, geomKey);
// System.out.println(sql);
updateCleanSQL(con, sql);
hash.put(volumeRegion, newVolumeRegionKey);
}
}
}
//
for (int i = 0; i < regions.length; i++) {
if (regions[i] instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion surfaceRegion = (SurfaceGeometricRegion) regions[i];
if (hash.getDatabaseKey(surfaceRegion) == null) {
KeyValue newSurfaceRegionKey = keyFactory.getNewKey(con);
KeyValue volumeRegion1Key = hash.getDatabaseKey((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[0]);
KeyValue volumeRegion2Key = hash.getDatabaseKey((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[1]);
sql = "INSERT INTO " + geoRegionTable.getTableName() + " " + geoRegionTable.getSQLColumnList() + " VALUES " + geoRegionTable.getSQLValueList(newSurfaceRegionKey, surfaceRegion, volumeRegion1Key, volumeRegion2Key, geomKey);
// System.out.println(sql);
updateCleanSQL(con, sql);
hash.put(surfaceRegion, newSurfaceRegionKey);
}
}
}
}
use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class SmoldynFileWriter method init.
private void init() throws SolverException {
simulation = simTask.getSimulation();
mathDesc = simulation.getMathDescription();
simulationSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
particleVariableList = new ArrayList<ParticleVariable>();
Variable[] variables = simulationSymbolTable.getVariables();
for (Variable variable : variables) {
if (variable instanceof ParticleVariable) {
if (variable.getDomain() == null) {
throw new SolverException("Particle Variables are required to be defined in a subdomain using syntax Subdomain::Variable.");
}
particleVariableList.add((ParticleVariable) variable);
}
}
// write geometry
Geometry geometry = mathDesc.getGeometry();
dimension = geometry.getDimension();
try {
// clone and resample geometry
resampledGeometry = (Geometry) BeanUtils.cloneSerializable(geometry);
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
ISize newSize = simulation.getMeshSpecification().getSamplingSize();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
bHasNoSurface = geoSurfaceDesc.getSurfaceClasses() == null || geoSurfaceDesc.getSurfaceClasses().length == 0;
} catch (Exception e) {
e.printStackTrace();
throw new SolverException(e.getMessage());
}
if (!bGraphicOpenGL) {
writeMeshFile();
}
colors = ColorUtil.generateAutoColor(particleVariableList.size() + resampledGeometry.getGeometrySurfaceDescription().getSurfaceClasses().length, bg, new Integer(5));
}
Aggregations