use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class SmoldynFileWriter method writeMeshFile.
private void writeMeshFile() throws SolverException {
FileOutputStream fos = null;
try {
polygonMembaneElementMap = new HashMap<Polygon, MembraneElement>();
cartesianMesh = CartesianMesh.createSimpleCartesianMesh(resampledGeometry, polygonMembaneElementMap);
// Write Mesh file
File meshFile = new File(baseFileName + SimDataConstants.MESHFILE_EXTENSION);
fos = new FileOutputStream(meshFile);
cartesianMesh.write(new PrintStream(fos));
} catch (Exception e) {
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class SmoldynFileWriter method write.
@Override
public void write(String[] parameterNames) throws ExpressionException, MathException, SolverException, DataAccessException, IOException, ImageException, PropertyVetoException, GeometryException {
init();
setupMolecules();
if (bUseMessaging) {
writeJms(simulation);
}
writeRandomSeed();
writeSpecies();
writeDiffusions();
writeGraphicsOpenGL();
if (simulation.getSolverTaskDescription().getSmoldynSimulationOptions().isUseHighResolutionSample()) {
try {
writeHighResVolumeSamples();
} catch (Exception ex) {
ex.printStackTrace(System.out);
throw new SolverException(ex.getMessage() + "\n" + "Problem may be solved by disable \'fast mesh sampling\'. It may take much longer time to complete the simulation." + "\n" + "Select \'Edit Simulation\' -> \'Solver\' -> \'Advanced Solver Options\' -> uncheck \'fast mesh sampling\'.");
}
}
writeSurfaces();
writeCompartments();
// needs to be after dim=3 in input file (after geometry is written).
writeDrifts();
writeReactions();
writeMolecules();
writeSimulationTimes();
writeRuntimeCommands();
writeSimulationSettings();
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.end_file);
// SimulationWriter.write(SimulationJobToSmoldyn.convertSimulationJob(simulationJob, outputFile), printWriter, simulationJob);
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class SmoldynFileWriter method writeWallSurfaces.
private void writeWallSurfaces() throws SolverException {
GeometrySurfaceDescription geometrySurfaceDescription = resampledGeometry.getGeometrySurfaceDescription();
GeometrySpec geometrySpec = resampledGeometry.getGeometrySpec();
SubVolume[] subVolumes = geometrySpec.getSubVolumes();
printWriter.println("# boundaries");
Origin origin = geometrySpec.getOrigin();
Extent extent = geometrySpec.getExtent();
Coordinate lowWall = new Coordinate(origin.getX(), origin.getY(), origin.getZ());
Coordinate highWall = new Coordinate(origin.getX() + extent.getX(), origin.getY() + extent.getY(), origin.getZ() + extent.getZ());
// potential artifact.
if (bHasNoSurface) {
SubDomain subDomain0 = mathDesc.getSubDomains().nextElement();
CompartmentSubDomain compartSubDomain0 = null;
compartSubDomain0 = (CompartmentSubDomain) subDomain0;
// x
if (compartSubDomain0.getBoundaryConditionXm().isPERIODIC()) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.boundaries + " 0 " + lowWall.getX() + " " + highWall.getX() + " " + SmoldynVCellMapper.SmoldynKeyword.p);
} else {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.low_wall + " 0 " + lowWall.getX() + " " + (compartSubDomain0.getBoundaryConditionXm().isNEUMANN() ? SmoldynVCellMapper.SmoldynKeyword.r : SmoldynVCellMapper.SmoldynKeyword.a));
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.high_wall + " 0 " + highWall.getX() + " " + (compartSubDomain0.getBoundaryConditionXp().isNEUMANN() ? SmoldynVCellMapper.SmoldynKeyword.r : SmoldynVCellMapper.SmoldynKeyword.a));
}
if (dimension > 1) {
// y
if (compartSubDomain0.getBoundaryConditionYm().isPERIODIC()) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.boundaries + " 1 " + lowWall.getY() + " " + highWall.getY() + " " + SmoldynVCellMapper.SmoldynKeyword.p);
} else {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.low_wall + " 1 " + lowWall.getY() + " " + (compartSubDomain0.getBoundaryConditionYm().isNEUMANN() ? SmoldynVCellMapper.SmoldynKeyword.r : SmoldynVCellMapper.SmoldynKeyword.a));
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.high_wall + " 1 " + highWall.getY() + " " + (compartSubDomain0.getBoundaryConditionYp().isNEUMANN() ? SmoldynVCellMapper.SmoldynKeyword.r : SmoldynVCellMapper.SmoldynKeyword.a));
}
if (dimension > 2) {
// z
if (compartSubDomain0.getBoundaryConditionZm().isPERIODIC()) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.boundaries + " 2 " + lowWall.getZ() + " " + highWall.getZ() + " " + SmoldynVCellMapper.SmoldynKeyword.p);
} else {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.low_wall + " 2 " + lowWall.getZ() + " " + (compartSubDomain0.getBoundaryConditionZm().isNEUMANN() ? SmoldynVCellMapper.SmoldynKeyword.r : SmoldynVCellMapper.SmoldynKeyword.a));
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.high_wall + " 2 " + highWall.getZ() + " " + (compartSubDomain0.getBoundaryConditionZp().isNEUMANN() ? SmoldynVCellMapper.SmoldynKeyword.r : SmoldynVCellMapper.SmoldynKeyword.a));
}
}
}
printWriter.println();
} else {
// x
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.boundaries + " 0 " + lowWall.getX() + " " + highWall.getX());
if (dimension > 1) {
// y
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.boundaries + " 1 " + lowWall.getY() + " " + highWall.getY());
if (dimension > 2) {
// z
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.boundaries + " 2 " + lowWall.getZ() + " " + highWall.getZ());
}
}
printWriter.println();
// bounding walls as surfaces
// have to find boundary condition type
ISize sampleSize = simulation.getMeshSpecification().getSamplingSize();
int numX = sampleSize.getX();
int numY = dimension < 2 ? 1 : sampleSize.getY();
int numZ = dimension < 3 ? 1 : sampleSize.getZ();
if (dimension > 2) {
int[] k_wall = new int[] { 0, numZ - 1 };
for (int k = 0; k < k_wall.length; k++) {
for (int j = 0; j < numY; j++) {
for (int i = 0; i < numX; i++) {
int volIndex = k_wall[k] * numX * numY + j * numX + i;
for (SubVolume sv : subVolumes) {
// gather all the points in all the regions
GeometricRegion[] geometricRegions = geometrySurfaceDescription.getGeometricRegions(sv);
RegionInfo[] regionInfos = geometrySurfaceDescription.getRegionImage().getRegionInfos();
for (GeometricRegion gr : geometricRegions) {
VolumeGeometricRegion vgr = (VolumeGeometricRegion) gr;
for (RegionInfo ri : regionInfos) {
if (ri.getRegionIndex() == vgr.getRegionID() && ri.isIndexInRegion(volIndex)) {
boundaryZSubVolumes.add(sv);
}
}
}
}
}
}
}
}
if (dimension > 1) {
int[] j_wall = new int[] { 0, numY - 1 };
for (int k = 0; k < numZ; k++) {
for (int j = 0; j < j_wall.length; j++) {
for (int i = 0; i < numX; i++) {
int volIndex = k * numX * numY + j_wall[j] * numX + i;
for (SubVolume sv : subVolumes) {
// gather all the points in all the regions
GeometricRegion[] geometricRegions = geometrySurfaceDescription.getGeometricRegions(sv);
RegionInfo[] regionInfos = geometrySurfaceDescription.getRegionImage().getRegionInfos();
for (GeometricRegion gr : geometricRegions) {
VolumeGeometricRegion vgr = (VolumeGeometricRegion) gr;
for (RegionInfo ri : regionInfos) {
if (ri.getRegionIndex() == vgr.getRegionID() && ri.isIndexInRegion(volIndex)) {
boundaryYSubVolumes.add(sv);
}
}
}
}
}
}
}
}
int[] i_wall = new int[] { 0, numX - 1 };
for (int k = 0; k < numZ; k++) {
for (int j = 0; j < numY; j++) {
for (int i = 0; i < i_wall.length; i++) {
int volIndex = k * numX * numY + j * numX + i_wall[i];
for (SubVolume sv : subVolumes) {
// gather all the points in all the regions
GeometricRegion[] geometricRegions = geometrySurfaceDescription.getGeometricRegions(sv);
RegionInfo[] regionInfos = geometrySurfaceDescription.getRegionImage().getRegionInfos();
for (GeometricRegion gr : geometricRegions) {
VolumeGeometricRegion vgr = (VolumeGeometricRegion) gr;
for (RegionInfo ri : regionInfos) {
if (ri.getRegionIndex() == vgr.getRegionID() && ri.isIndexInRegion(volIndex)) {
boundaryXSubVolumes.add(sv);
}
}
}
}
}
}
}
Set<SubVolume> boundarySubVolumes = new HashSet<SubVolume>();
boundarySubVolumes.addAll(boundaryXSubVolumes);
boundarySubVolumes.addAll(boundaryYSubVolumes);
boundarySubVolumes.addAll(boundaryZSubVolumes);
BoundaryConditionType[] computedBct = new BoundaryConditionType[dimension * 2];
String[] smoldynBct = new String[dimension * 2];
String[] wallNames = new String[] { "Xm", "Xp", "Ym", "Yp", "Zm", "Zp" };
if (boundarySubVolumes.size() >= 1) {
for (SubVolume sv : boundarySubVolumes) {
CompartmentSubDomain csd = (CompartmentSubDomain) mathDesc.getSubDomain(sv.getName());
BoundaryConditionType[] bct = new BoundaryConditionType[] { csd.getBoundaryConditionXm(), csd.getBoundaryConditionXp(), csd.getBoundaryConditionYm(), csd.getBoundaryConditionYp(), csd.getBoundaryConditionZm(), csd.getBoundaryConditionZp() };
if (computedBct[0] == null) {
System.arraycopy(bct, 0, computedBct, 0, dimension * 2);
for (int i = 0; i < dimension * 2; i++) {
if (computedBct[i].isPERIODIC()) {
throw new SolverException("Models with both surfaces and periodic boundary conditions are not supported yet.");
}
smoldynBct[i] = computedBct[i].isDIRICHLET() ? SmoldynVCellMapper.SmoldynKeyword.absorb.name() : SmoldynVCellMapper.SmoldynKeyword.reflect.name();
}
} else {
for (int i = 0; i < dimension * 2; i++) {
if (!computedBct[i].compareEqual(bct[i])) {
throw new SolverException(wallNames[i] + " wall has different boundary conditions");
}
}
}
}
}
printWriter.println("# bounding wall surface");
// X walls
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.start_surface + " " + VCellSmoldynKeyword.bounding_wall_surface_X);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + "(" + SmoldynVCellMapper.SmoldynKeyword.up + ") " + SmoldynVCellMapper.SmoldynKeyword.both + " " + SmoldynVCellMapper.SmoldynKeyword.reflect);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + " " + SmoldynVCellMapper.SmoldynKeyword.front + " " + smoldynBct[0]);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + " " + SmoldynVCellMapper.SmoldynKeyword.back + " " + smoldynBct[1]);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.color + " " + SmoldynVCellMapper.SmoldynKeyword.both + " 1 1 1");
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.polygon + " " + SmoldynVCellMapper.SmoldynKeyword.both + " " + SmoldynVCellMapper.SmoldynKeyword.edge);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_panels + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " 2");
// yz walls
switch(dimension) {
case 1:
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " +0 " + lowWall.getX());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " -0 " + highWall.getX());
break;
case 2:
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " +0 " + lowWall.getX() + " " + lowWall.getY() + " " + extent.getY());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " -0 " + highWall.getX() + " " + lowWall.getY() + " " + extent.getY());
break;
case 3:
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " +0 " + lowWall.getX() + " " + lowWall.getY() + " " + lowWall.getZ() + " " + extent.getY() + " " + extent.getZ());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " -0 " + highWall.getX() + " " + lowWall.getY() + " " + lowWall.getZ() + " " + extent.getY() + " " + extent.getZ());
break;
}
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.end_surface);
printWriter.println();
if (dimension > 1) {
// Y walls
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.start_surface + " " + VCellSmoldynKeyword.bounding_wall_surface_Y);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + "(" + SmoldynVCellMapper.SmoldynKeyword.up + ") " + SmoldynVCellMapper.SmoldynKeyword.both + " " + SmoldynVCellMapper.SmoldynKeyword.reflect);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + " " + SmoldynVCellMapper.SmoldynKeyword.front + " " + smoldynBct[2]);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + " " + SmoldynVCellMapper.SmoldynKeyword.back + " " + smoldynBct[3]);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.color + " " + SmoldynVCellMapper.SmoldynKeyword.both + " 1 1 1");
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.polygon + " " + SmoldynVCellMapper.SmoldynKeyword.both + " " + SmoldynVCellMapper.SmoldynKeyword.edge);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_panels + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " 2");
// xz walls
switch(dimension) {
case 2:
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " +1 " + lowWall.getX() + " " + lowWall.getY() + " " + extent.getX());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " -1 " + lowWall.getX() + " " + highWall.getY() + " " + extent.getX());
break;
case 3:
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " +1 " + lowWall.getX() + " " + lowWall.getY() + " " + lowWall.getZ() + " " + extent.getX() + " " + extent.getZ());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " -1 " + lowWall.getX() + " " + highWall.getY() + " " + lowWall.getZ() + " " + extent.getX() + " " + extent.getZ());
break;
}
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.end_surface);
printWriter.println();
if (dimension > 2) {
// Z walls
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.start_surface + " " + VCellSmoldynKeyword.bounding_wall_surface_Z);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + "(" + SmoldynVCellMapper.SmoldynKeyword.up + ") " + SmoldynVCellMapper.SmoldynKeyword.both + " " + SmoldynVCellMapper.SmoldynKeyword.reflect);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + " " + SmoldynVCellMapper.SmoldynKeyword.front + " " + smoldynBct[4]);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + " " + SmoldynVCellMapper.SmoldynKeyword.back + " " + smoldynBct[5]);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.color + " " + SmoldynVCellMapper.SmoldynKeyword.both + " 1 1 1");
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.polygon + " " + SmoldynVCellMapper.SmoldynKeyword.both + " " + SmoldynVCellMapper.SmoldynKeyword.edge);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_panels + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " 2");
// xy walls
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " +2 " + lowWall.getX() + " " + lowWall.getY() + " " + lowWall.getZ() + " " + extent.getX() + " " + extent.getY());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.rect + " -2 " + lowWall.getX() + " " + lowWall.getY() + " " + highWall.getZ() + " " + extent.getX() + " " + extent.getY());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.end_surface);
printWriter.println();
}
}
}
}
Aggregations