use of cbit.vcell.geometry.SubVolume in project vcell by virtualcell.
the class ComsolModelBuilder method getVCCModel.
public static VCCModel getVCCModel(SimulationJob vcellSimJob) throws ExpressionException {
MathDescription vcellMathDesc = vcellSimJob.getSimulation().getMathDescription();
Geometry vcellGeometry = vcellMathDesc.getGeometry();
GeometrySpec vcellGeometrySpec = vcellGeometry.getGeometrySpec();
int vcellDim = vcellGeometrySpec.getDimension();
VCCModel model = new VCCModel("Model", vcellDim);
model.modelpath = "D:\\Developer\\eclipse\\workspace_refactor\\comsol_java\\src";
model.comments = "Untitled\n\n";
VCCModelNode comp1 = new VCCModelNode("comp1");
model.modelnodes.add(comp1);
// if (vcellDim != 2){
// throw new RuntimeException("expecting 2D simulation");
// }
//
// assume initial geometry is circle centered at 0.5, 0.5 of radius 0.3
//
// String comsolOutsideDomainName = "dif1";
// String comsolInsideDomainName = "c1";
VCCGeomSequence geom1 = new VCCGeomSequence("geom1", vcellDim);
model.geometrysequences.add(geom1);
VCCMeshSequence mesh1 = new VCCMeshSequence("mesh1", geom1);
model.meshes.add(mesh1);
VCCStudy std1 = new VCCStudy("std1");
model.study = std1;
TimeBounds timeBounds = vcellSimJob.getSimulation().getSolverTaskDescription().getTimeBounds();
TimeStep timeStep = vcellSimJob.getSimulation().getSolverTaskDescription().getTimeStep();
String beginTime = Double.toString(timeBounds.getStartingTime());
String endTime = Double.toString(timeBounds.getEndingTime());
String step = Double.toString(timeStep.getDefaultTimeStep());
VCCStudyFeature time = new VCCTransientStudyFeature("time", beginTime, step, endTime);
std1.features.add(time);
if (vcellGeometrySpec.getImage() != null) {
throw new RuntimeException("image-based geometries not yet supported by VCell's COMSOL model builder");
}
if (vcellGeometrySpec.getNumSubVolumes() == 0) {
throw new RuntimeException("no subvolumes defined in geometry");
}
if (vcellGeometrySpec.getNumAnalyticOrCSGSubVolumes() != vcellGeometrySpec.getNumSubVolumes()) {
throw new RuntimeException("only analytic and CSG subvolumes currently supported by VCell's COMSOL model builder");
}
//
// add geometry for all subvolumes
//
HashMap<String, VCCGeomFeature> subvolumeNameFeatureMap = new HashMap<String, VCCGeomFeature>();
SubVolume[] subVolumes = vcellGeometrySpec.getSubVolumes();
for (int i = 0; i < subVolumes.length; i++) {
SubVolume subvolume = subVolumes[i];
if (subvolume instanceof CSGObject) {
CSGObject vcellCSGObject = (CSGObject) subvolume;
CSGNode vcellCSGNode = vcellCSGObject.getRoot();
ArrayList<VCCGeomFeature> geomFeatureList = new ArrayList<VCCGeomFeature>();
VCCGeomFeature feature = csgVisitor(vcellCSGNode, geomFeatureList, subvolume.getName());
geom1.geomfeatures.addAll(geomFeatureList);
if (i == 0) {
// first subvolume (on top in ordinals) doesn't need any differencing
subvolumeNameFeatureMap.put(subvolume.getName(), feature);
} else {
// have to subtract union of prior subvolumes
ArrayList<VCCGeomFeature> priorFeatures = new ArrayList<VCCGeomFeature>();
for (int j = 0; j < i; j++) {
CSGObject priorCSGObject = (CSGObject) subVolumes[j];
CSGNode priorCSGNode = priorCSGObject.getRoot();
geomFeatureList.clear();
VCCGeomFeature priorFeature = csgVisitor(priorCSGNode, geomFeatureList, subvolume.getName());
priorFeatures.add(priorFeature);
geom1.geomfeatures.addAll(geomFeatureList);
}
VCCDifference diff = new VCCDifference("diff" + subvolume.getName(), Keep.off);
diff.input.add(feature);
diff.input2.addAll(priorFeatures);
geom1.geomfeatures.add(diff);
subvolumeNameFeatureMap.put(subvolume.getName(), diff);
}
} else {
throw new RuntimeException("only CSG subvolumes currently supported by VCell's COMSOL model builder");
}
}
//
// add geometry for all surfaceClasses
//
HashMap<String, VCCGeomFeature> surfaceclassNameFeatureMap = new HashMap<String, VCCGeomFeature>();
SurfaceClass[] surfaceClasses = vcellGeometry.getGeometrySurfaceDescription().getSurfaceClasses();
for (int i = 0; i < surfaceClasses.length; i++) {
SurfaceClass surfaceClass = surfaceClasses[i];
Set<SubVolume> adjacentSubvolumes = surfaceClass.getAdjacentSubvolumes();
if (adjacentSubvolumes.size() != 2) {
throw new RuntimeException("expecting two adjacent subvolumes for surface " + surfaceClass.getName() + " in COMSOL model builder");
}
// find adjacent Geometry Features (for subvolumes)
Iterator<SubVolume> svIter = adjacentSubvolumes.iterator();
SubVolume subvolume0 = svIter.next();
SubVolume subvolume1 = svIter.next();
ArrayList<VCCGeomFeature> adjacentFeatures = new ArrayList<VCCGeomFeature>();
adjacentFeatures.add(subvolumeNameFeatureMap.get(subvolume0.getName()));
adjacentFeatures.add(subvolumeNameFeatureMap.get(subvolume1.getName()));
String name = "inter_" + subvolume0.getName() + "_" + subvolume1.getName();
// surfaces are dimension N-1
int entitydim = vcellDim - 1;
VCCIntersectionSelection intersect_subvolumes = new VCCIntersectionSelection(name, entitydim);
intersect_subvolumes.input.addAll(adjacentFeatures);
geom1.geomfeatures.add(intersect_subvolumes);
surfaceclassNameFeatureMap.put(surfaceClass.getName(), intersect_subvolumes);
}
SimulationSymbolTable symbolTable = new SimulationSymbolTable(vcellSimJob.getSimulation(), vcellSimJob.getJobIndex());
//
for (SubDomain subDomain : Collections.list(vcellMathDesc.getSubDomains())) {
for (Equation equ : subDomain.getEquationCollection()) {
if (equ instanceof PdeEquation || equ instanceof OdeEquation) {
VCCGeomFeature geomFeature = null;
final int dim;
if (subDomain instanceof CompartmentSubDomain) {
geomFeature = subvolumeNameFeatureMap.get(subDomain.getName());
dim = vcellDim;
} else if (subDomain instanceof MembraneSubDomain) {
geomFeature = surfaceclassNameFeatureMap.get(subDomain.getName());
dim = vcellDim - 1;
} else {
throw new RuntimeException("subdomains of type '" + subDomain.getClass().getSimpleName() + "' not yet supported in COMSOL model builder");
}
if (geomFeature == null) {
throw new RuntimeException("cannot find COMSOL geometry feature named " + subDomain.getName() + " in COMSOL model builder");
}
VCCConvectionDiffusionEquation cdeq = new VCCConvectionDiffusionEquation("cdeq_" + equ.getVariable().getName(), geom1, geomFeature, dim);
cdeq.fieldName = equ.getVariable().getName();
cdeq.initial = MathUtilities.substituteModelParameters(equ.getInitialExpression(), symbolTable).flatten().infix();
cdeq.sourceTerm_f = MathUtilities.substituteModelParameters(equ.getRateExpression(), symbolTable).flatten().infix();
if (equ instanceof PdeEquation) {
PdeEquation pde = (PdeEquation) equ;
cdeq.diffTerm_c = MathUtilities.substituteModelParameters(pde.getDiffusionExpression(), symbolTable).flatten().infix();
if (subDomain instanceof CompartmentSubDomain) {
CompartmentSubDomain compartmentSubdomain = (CompartmentSubDomain) subDomain;
ArrayList<String> be = new ArrayList<String>();
if (pde.getVelocityX() != null) {
be.add(MathUtilities.substituteModelParameters(pde.getVelocityX(), symbolTable).flatten().infix());
} else {
be.add("0");
}
if (vcellDim >= 2) {
if (pde.getVelocityY() != null) {
be.add(MathUtilities.substituteModelParameters(pde.getVelocityY(), symbolTable).flatten().infix());
} else {
be.add("0");
}
}
if (vcellDim == 3) {
if (pde.getVelocityY() != null) {
be.add(MathUtilities.substituteModelParameters(pde.getVelocityZ(), symbolTable).flatten().infix());
} else {
be.add("0");
}
}
cdeq.advection_be = be.toArray(new String[vcellDim]);
//
// look for membrane boundary conditions for this variable
//
MembraneSubDomain[] membraneSubdomains = vcellMathDesc.getMembraneSubDomains(compartmentSubdomain);
for (MembraneSubDomain membraneSubdomain : membraneSubdomains) {
JumpCondition jumpCondition = membraneSubdomain.getJumpCondition((VolVariable) pde.getVariable());
if (jumpCondition != null) {
Expression fluxExpr = null;
if (membraneSubdomain.getInsideCompartment() == compartmentSubdomain) {
fluxExpr = jumpCondition.getInFluxExpression();
} else if (membraneSubdomain.getOutsideCompartment() == compartmentSubdomain) {
fluxExpr = jumpCondition.getOutFluxExpression();
}
String name = equ.getVariable().getName() + "_flux_" + membraneSubdomain.getName();
VCCGeomFeature selection = surfaceclassNameFeatureMap.get(membraneSubdomain.getName());
VCCFluxBoundary fluxBoundary = new VCCFluxBoundary(name, selection, vcellDim - 1);
fluxBoundary.flux_g = MathUtilities.substituteModelParameters(fluxExpr, symbolTable).flatten().infix();
cdeq.features.add(fluxBoundary);
}
}
}
}
model.physics.add(cdeq);
}
}
}
//
return model;
}
use of cbit.vcell.geometry.SubVolume 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();
}
}
}
}
use of cbit.vcell.geometry.SubVolume in project vcell by virtualcell.
the class BioModelTest method getExampleWithImage.
/**
* Insert the method's description here.
* Creation date: (11/14/00 5:56:41 PM)
* @return cbit.vcell.biomodel.BioModel
*/
public static BioModel getExampleWithImage() throws Exception {
BioModel bioModel = new BioModel(null);
bioModel.setName("bioModel_" + Integer.toHexString(((new Random()).nextInt())));
//
// add SimulationContexts
//
SimulationContext sc1 = cbit.vcell.mapping.SimulationContextTest.getExample(2);
sc1.setName("simContext1_" + Integer.toHexString(((new Random()).nextInt())));
bioModel.setModel(sc1.getModel());
Model model = bioModel.getModel();
model.setName("physiology_" + Integer.toHexString(((new Random()).nextInt())));
Geometry geo = GeometryTest.getImageExample2D();
geo.setName("Image_Geometry_" + Integer.toHexString(((new Random()).nextInt())));
geo.precomputeAll(new GeometryThumbnailImageFactoryAWT(), true, false);
SimulationContext sc2 = new SimulationContext(model, geo);
GeometryContext geoContext = sc2.getGeometryContext();
Structure structure_ec = model.getStructure("extracellular");
SubVolume subVolume_cytosol = geo.getGeometrySpec().getSubVolume("cytosol");
geoContext.assignStructure(structure_ec, subVolume_cytosol);
geoContext.getStructureMapping(structure_ec).getUnitSizeParameter().setExpression(new Expression(1.0));
Structure structure_cyt = model.getStructure("cytosol");
SubVolume subVolume_er = geo.getGeometrySpec().getSubVolume("er");
geoContext.assignStructure(structure_cyt, subVolume_er);
geoContext.getStructureMapping(structure_cyt).getUnitSizeParameter().setExpression(new Expression(0.5));
Structure structure_er = model.getStructure("er");
geoContext.assignStructure(structure_er, subVolume_er);
geoContext.getStructureMapping(structure_er).getUnitSizeParameter().setExpression(new Expression(0.5));
Structure structure_pm = model.getStructure("plasmaMembrane");
SurfaceClass surfaceClass_erMem = geoContext.getGeometry().getGeometrySurfaceDescription().getSurfaceClass(subVolume_cytosol, subVolume_er);
geoContext.assignStructure(structure_pm, surfaceClass_erMem);
geoContext.getStructureMapping(structure_pm).getUnitSizeParameter().setExpression(new Expression(1.0));
Structure structure_erMem = model.getStructure("erMembrane");
geoContext.assignStructure(structure_erMem, subVolume_er);
geoContext.getStructureMapping(structure_erMem).getUnitSizeParameter().setExpression(new Expression(2.4));
bioModel.setSimulationContexts(new SimulationContext[] { /*sc1,*/
sc2 });
sc2.setName("simContext2_" + Integer.toHexString(((new Random()).nextInt())));
// sc1.setMathDescription(sc1.createNewMathMapping().getMathDescription());
sc2.setMathDescription(sc2.createNewMathMapping().getMathDescription());
//
// add simulations (must be after
//
Simulation sim1 = new Simulation(sc2.getMathDescription());
sim1.setName("sim1_" + Integer.toHexString(((new Random()).nextInt())));
Simulation sim2 = new Simulation(sc2.getMathDescription());
sim2.setName("sim2_" + Integer.toHexString(((new Random()).nextInt())));
bioModel.setSimulations(new Simulation[] { sim1, sim2 });
return bioModel;
}
use of cbit.vcell.geometry.SubVolume in project vcell by virtualcell.
the class GeomDbDriver method insertSubVolumesSQL.
/**
* This method was created in VisualAge.
* @param vcimage cbit.image.VCImage
* @param userid java.lang.String
* @exception java.rmi.RemoteException The exception description.
*/
private void insertSubVolumesSQL(InsertHashtable hash, Connection con, Geometry geom, KeyValue geomKey) throws SQLException, cbit.image.ImageException, DataAccessException, ObjectNotFoundException {
String sql;
SubVolume[] subVolumes = geom.getGeometrySpec().getSubVolumes();
int ordinal = 0;
for (int i = 0; i < subVolumes.length; i++) {
SubVolume sv = (SubVolume) subVolumes[i];
if (hash.getDatabaseKey(sv) == null) {
KeyValue newSVKey = keyFactory.getNewKey(con);
sql = "INSERT INTO " + subVolumeTable.getTableName() + " " + subVolumeTable.getSQLColumnList() + " VALUES " + subVolumeTable.getSQLValueList(hash, newSVKey, geom, sv, geomKey, ordinal);
// System.out.println(sql);
updateCleanSQL(con, sql);
hash.put(sv, newSVKey);
}
ordinal++;
}
}
use of cbit.vcell.geometry.SubVolume in project vcell by virtualcell.
the class StructureMappingTable method getSQLValueList.
/**
* This method was created in VisualAge.
* @return java.lang.String
* @param key KeyValue
* @param modelName java.lang.String
*/
public String getSQLValueList(InsertHashtable hash, KeyValue Key, KeyValue simContextKey, StructureMapping structureMapping) throws DataAccessException {
GeometryClass geometryClass = structureMapping.getGeometryClass();
KeyValue geometryClassKey = (geometryClass == null ? null : hash.getDatabaseKey(geometryClass));
if (geometryClass != null && geometryClassKey == null) {
geometryClassKey = geometryClass.getKey();
if (geometryClassKey == null) {
throw new DataAccessException("no key for GeometryClass '" + geometryClass.getName() + "' " + geometryClass.getClass().getName());
}
}
KeyValue structureKey = hash.getDatabaseKey(structureMapping.getStructure());
if (structureKey == null) {
structureKey = structureMapping.getStructure().getKey();
if (structureKey == null) {
throw new DataAccessException("no key for structure " + structureMapping.getStructure());
}
}
StringBuffer buffer = new StringBuffer();
buffer.append("(");
buffer.append(Key + ",");
buffer.append((geometryClass instanceof SubVolume ? geometryClassKey : null) + ",");
buffer.append(structureKey + ",");
buffer.append(simContextKey + ",");
buffer.append((/*isResolved*/
false ? 1 : 0) + ",");
if (structureMapping instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) structureMapping;
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("'" + fm.getBoundaryConditionTypeXm().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeXp().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeYm().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeYp().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeZm().boundaryTypeStringValue() + "',");
buffer.append("'" + fm.getBoundaryConditionTypeZp().boundaryTypeStringValue() + "',");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
} else if (structureMapping instanceof MembraneMapping) {
MembraneMapping mm = (MembraneMapping) structureMapping;
// amended Sept. 17th, 2007
if (mm.getSurfaceToVolumeParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getSurfaceToVolumeParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
if (mm.getVolumeFractionParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getVolumeFractionParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append("null" + ",");
buffer.append((mm.getCalculateVoltage() ? 1 : 0) + ",");
try {
buffer.append(mm.getSpecificCapacitanceParameter().getExpression().evaluateConstant() + ",");
} catch (cbit.vcell.parser.ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("specific capacitance for " + mm.getMembrane().getName() + " not constant: (" + e.getMessage() + ")");
}
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getInitialVoltageParameter().getExpression().infix()) + "',");
}
if (structureMapping.getSizeParameter().getExpression() != null)
buffer.append("'" + TokenMangler.getSQLEscapedString(structureMapping.getSizeParameter().getExpression().infix()) + "',");
else
buffer.append("'',");
if (structureMapping instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) structureMapping;
if (fm.getVolumePerUnitAreaParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(fm.getVolumePerUnitAreaParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
if (fm.getVolumePerUnitVolumeParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(fm.getVolumePerUnitVolumeParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
// if structureMapping is a featureMapping, 'areaPerUnitArea' and 'areaPerUnitVol' params are null, so fill those in here
buffer.append("null,null");
} else if (structureMapping instanceof MembraneMapping) {
// if structureMapping is a featureMapping, 'volPerUnitArea' and 'volPerUnitVol' params are null, so fill those in here; then memMapping params
buffer.append("null,null,");
MembraneMapping mm = (MembraneMapping) structureMapping;
if (mm.getAreaPerUnitAreaParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getAreaPerUnitAreaParameter().getExpression().infix()) + "',");
} else {
buffer.append("null" + ",");
}
if (mm.getAreaPerUnitVolumeParameter().getExpression() != null) {
buffer.append("'" + TokenMangler.getSQLEscapedString(mm.getAreaPerUnitVolumeParameter().getExpression().infix()) + "'");
} else {
buffer.append("null");
}
}
buffer.append("," + (geometryClass instanceof SurfaceClass ? geometryClassKey : null));
buffer.append(")");
return buffer.toString();
}
Aggregations