use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class SurfaceEditor method setgeometrySurfaceDescription1.
/**
* Set the geometrySurfaceDescription1 to a new value.
* @param newValue cbit.vcell.geometry.surface.GeometrySurfaceDescription
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void setgeometrySurfaceDescription1(GeometrySurfaceDescription newValue) {
if (ivjgeometrySurfaceDescription1 != newValue) {
try {
GeometrySurfaceDescription oldValue = getgeometrySurfaceDescription1();
/* Stop listening for events from the current object */
if (ivjgeometrySurfaceDescription1 != null) {
ivjgeometrySurfaceDescription1.removePropertyChangeListener(ivjEventHandler);
}
ivjgeometrySurfaceDescription1 = newValue;
/* Listen for events from the new object */
if (ivjgeometrySurfaceDescription1 != null) {
ivjgeometrySurfaceDescription1.addPropertyChangeListener(ivjEventHandler);
}
connPtoP1SetSource();
connEtoM1(ivjgeometrySurfaceDescription1);
connEtoM6(ivjgeometrySurfaceDescription1);
connEtoC2(ivjgeometrySurfaceDescription1);
firePropertyChange("geometrySurfaceDescription", oldValue, newValue);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
;
// user code begin {3}
// user code end
}
use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class SurfaceEditor method setGeometrySurfaceDescription.
/**
* Sets the geometrySurfaceDescription property (cbit.vcell.geometry.surface.GeometrySurfaceDescription) value.
* @param geometrySurfaceDescription The new value for the property.
* @see #getGeometrySurfaceDescription
*/
public void setGeometrySurfaceDescription(GeometrySurfaceDescription geometrySurfaceDescription) {
GeometrySurfaceDescription oldValue = fieldGeometrySurfaceDescription;
fieldGeometrySurfaceDescription = geometrySurfaceDescription;
firePropertyChange("geometrySurfaceDescription", oldValue, geometrySurfaceDescription);
}
use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class XmlReader method getGeometrySurfaceDescription.
private GeometrySurfaceDescription getGeometrySurfaceDescription(Element param, Geometry geom) throws XmlParseException {
GeometrySurfaceDescription gsd = geom.getGeometrySurfaceDescription();
String cutoffStr = param.getAttributeValue(XMLTags.CutoffFrequencyAttrTag);
String xDim = param.getAttributeValue(XMLTags.NumSamplesXAttrTag);
String yDim = param.getAttributeValue(XMLTags.NumSamplesYAttrTag);
String zDim = param.getAttributeValue(XMLTags.NumSamplesZAttrTag);
if (cutoffStr == null || xDim == null || yDim == null || zDim == null) {
throw new XmlParseException("Attributes for element Surface Description not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
}
try {
ISize isize = new ISize(Integer.parseInt(xDim), Integer.parseInt(yDim), Integer.parseInt(zDim));
gsd.setVolumeSampleSize(isize);
gsd.setFilterCutoffFrequency(new Double(cutoffStr));
// these lists are allowed to be empty.
ArrayList<Element> memRegions = new ArrayList<Element>(param.getChildren(XMLTags.MembraneRegionTag, vcNamespace));
ArrayList<Element> volRegions = new ArrayList<Element>(param.getChildren(XMLTags.VolumeRegionTag, vcNamespace));
ArrayList<GeometricRegion> regions = new ArrayList<GeometricRegion>();
GeometryUnitSystem geometryUnitSystem = geom.getUnitSystem();
for (Element temp : volRegions) {
String regionID = temp.getAttributeValue(XMLTags.RegionIDAttrTag);
String name = temp.getAttributeValue(XMLTags.NameAttrTag);
String subvolumeRef = temp.getAttributeValue(XMLTags.SubVolumeAttrTag);
if (regionID == null || name == null || subvolumeRef == null) {
throw new XmlParseException("Attributes for element Volume Region not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
}
SubVolume subvolume = geom.getGeometrySpec().getSubVolume(subvolumeRef);
if (subvolume == null) {
throw new XmlParseException("The subvolume " + subvolumeRef + " could not be resolved.");
}
double size = -1;
VCUnitDefinition unit = null;
String sizeStr = temp.getAttributeValue(XMLTags.SizeAttrTag);
if (sizeStr != null) {
size = Double.parseDouble(sizeStr);
String unitSymbol = temp.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
if (unitSymbol != null) {
unit = geometryUnitSystem.getInstance(unitSymbol);
}
}
VolumeGeometricRegion vgr = new VolumeGeometricRegion(name, size, unit, subvolume, Integer.parseInt(regionID));
regions.add(vgr);
}
for (Element temp : memRegions) {
String volRegion_1 = temp.getAttributeValue(XMLTags.VolumeRegion_1AttrTag);
String volRegion_2 = temp.getAttributeValue(XMLTags.VolumeRegion_2AttrTag);
String name = temp.getAttributeValue(XMLTags.NameAttrTag);
if (volRegion_1 == null || volRegion_2 == null || name == null) {
throw new XmlParseException("Attributes for element Membrane Region not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
}
VolumeGeometricRegion region1 = getAdjacentVolumeRegion(regions, volRegion_1);
VolumeGeometricRegion region2 = getAdjacentVolumeRegion(regions, volRegion_2);
if (region1 == null || region2 == null) {
throw new XmlParseException("Element Membrane Region refernces invalid volume regions, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
}
double size = -1;
VCUnitDefinition unit = null;
String sizeStr = temp.getAttributeValue(XMLTags.SizeAttrTag);
if (sizeStr != null) {
size = Double.parseDouble(sizeStr);
String unitSymbol = temp.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
if (unitSymbol != null) {
unit = geometryUnitSystem.getInstance(unitSymbol);
}
}
SurfaceGeometricRegion rsl = new SurfaceGeometricRegion(name, size, unit);
rsl.addAdjacentGeometricRegion(region1);
region1.addAdjacentGeometricRegion(rsl);
rsl.addAdjacentGeometricRegion(region2);
region2.addAdjacentGeometricRegion(rsl);
regions.add(rsl);
}
if (regions.size() > 0) {
gsd.setGeometricRegions((GeometricRegion[]) regions.toArray(new GeometricRegion[regions.size()]));
}
} catch (Exception e) {
System.err.println("Unable to read geometry surface description from XML, for geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
e.printStackTrace();
}
return gsd;
}
use of cbit.vcell.geometry.surface.GeometrySurfaceDescription in project vcell by virtualcell.
the class GeometryFileWriter method write.
/**
* Insert the method's description here.
* Creation date: (7/19/2004 10:54:30 AM)
* @param geometrySurfaceDescription cbit.vcell.geometry.surface.GeometrySurfaceDescription
* @throws IOException
*/
public static void write(Writer writer, Geometry resampledGeometry) throws IOException {
//
// "name" name
// "dimension" dimension
// "extent" extentx extenty extentz
// "origin" originx originy originz
// "volumeRegions" num
// name totalVolume featureHandle
// "membraneRegions" num
// name totalArea volumeRegionIndex1 volumeRegionIndex2
// "volumeSamples" numX, numY, numZ
// uncompressed regionIndexs for each volume element
// compressed regionIndexs for each volume element
// "nodes" num
// nodeIndex x y z
// "cells" num
// cellIndex patchIndex node1 node2 node3 node4
// "celldata"
// insideVolumeIndex outsideVolumeIndex area normalx normaly normalz
//
//
// When we are writing volume regions, we sort regions so that ID is equal to index
//
writer.write("name " + resampledGeometry.getName() + "\n");
writer.write("dimension " + resampledGeometry.getDimension() + "\n");
org.vcell.util.Extent extent = resampledGeometry.getExtent();
org.vcell.util.Origin origin = resampledGeometry.getOrigin();
switch(resampledGeometry.getDimension()) {
case 1:
writer.write("size " + extent.getX() + "\n");
writer.write("origin " + origin.getX() + "\n");
break;
case 2:
writer.write("size " + extent.getX() + " " + extent.getY() + "\n");
writer.write("origin " + origin.getX() + " " + origin.getY() + "\n");
break;
case 3:
writer.write("size " + extent.getX() + " " + extent.getY() + " " + extent.getZ() + "\n");
writer.write("origin " + origin.getX() + " " + origin.getY() + " " + origin.getZ() + "\n");
break;
}
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
RegionImage regionImage = geoSurfaceDesc.getRegionImage();
SurfaceCollection surfaceCollection = geoSurfaceDesc.getSurfaceCollection();
GeometricRegion[] geometricRegions = geoSurfaceDesc.getGeometricRegions();
int numVolumeRegions = 0;
int numMembraneRegions = 0;
Vector<VolumeGeometricRegion> volRegionList = new Vector<VolumeGeometricRegion>();
if (geometricRegions != null) {
for (int i = 0; i < geometricRegions.length; i++) {
if (geometricRegions[i] instanceof VolumeGeometricRegion) {
numVolumeRegions++;
volRegionList.add((VolumeGeometricRegion) geometricRegions[i]);
} else if (geometricRegions[i] instanceof SurfaceGeometricRegion) {
numMembraneRegions++;
}
}
}
//
// get ordered array of volume regions (where "id" == index into array)... fail if impossible
//
java.util.Collections.sort(volRegionList, new Comparator<VolumeGeometricRegion>() {
public int compare(VolumeGeometricRegion reg1, VolumeGeometricRegion reg2) {
if (reg1.getRegionID() < reg2.getRegionID()) {
return -1;
} else if (reg1.getRegionID() > reg2.getRegionID()) {
return 1;
} else {
return 0;
}
}
public boolean equals(Object obj) {
return this == obj;
}
});
VolumeGeometricRegion[] volRegions = (VolumeGeometricRegion[]) org.vcell.util.BeanUtils.getArray(volRegionList, VolumeGeometricRegion.class);
writer.write("volumeRegions " + numVolumeRegions + "\n");
for (int i = 0; i < volRegions.length; i++) {
if (volRegions[i].getRegionID() != i) {
throw new RuntimeException("Region ID != Region Index, they must be the same!");
}
writer.write(volRegions[i].getName() + " " + volRegions[i].getSize() + " " + volRegions[i].getSubVolume().getHandle() + "\n");
}
writer.write("membraneRegions " + numMembraneRegions + "\n");
if (geometricRegions != null) {
for (int i = 0; i < geometricRegions.length; i++) {
if (geometricRegions[i] instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion surfaceRegion = (SurfaceGeometricRegion) geometricRegions[i];
GeometricRegion[] neighbors = surfaceRegion.getAdjacentGeometricRegions();
VolumeGeometricRegion insideRegion = (VolumeGeometricRegion) neighbors[0];
VolumeGeometricRegion outsideRegion = (VolumeGeometricRegion) neighbors[1];
writer.write(surfaceRegion.getName() + " " + surfaceRegion.getSize() + " " + insideRegion.getRegionID() + " " + outsideRegion.getRegionID() + "\n");
}
}
}
//
// write volume samples
//
ISize volumeSampleSize = geoSurfaceDesc.getVolumeSampleSize();
switch(resampledGeometry.getDimension()) {
case 1:
writer.write("volumeSamples " + volumeSampleSize.getX() + "\n");
break;
case 2:
writer.write("volumeSamples " + volumeSampleSize.getX() + " " + volumeSampleSize.getY() + "\n");
break;
case 3:
writer.write("volumeSamples " + volumeSampleSize.getX() + " " + volumeSampleSize.getY() + " " + volumeSampleSize.getZ() + "\n");
break;
}
// regionImage
if (regionImage != null) {
if (regionImage.getNumRegions() > 65536) {
throw new RuntimeException("cannot process a geometry with more than 65536 volume regions");
}
byte[] uncompressedRegionIDs = new byte[2 * regionImage.getNumX() * regionImage.getNumY() * regionImage.getNumZ()];
for (int i = 0, j = 0; i < uncompressedRegionIDs.length; i += 2, j++) {
int regindex = regionImage.getRegionInfoFromOffset(j).getRegionIndex();
uncompressedRegionIDs[i] = (byte) (regindex & 0x000000ff);
uncompressedRegionIDs[i + 1] = (byte) ((regindex & 0x0000ff00) >> 8);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(uncompressedRegionIDs, 0, uncompressedRegionIDs.length);
dos.close();
byte[] compressedRegionIDs = bos.toByteArray();
writer.write(org.vcell.util.Hex.toString(compressedRegionIDs) + "\n");
} else {
writer.write("\n");
}
//
if (surfaceCollection == null) {
throw new RuntimeException("geometry is not updated");
}
int numCells = surfaceCollection.getTotalPolygonCount();
writer.write("cells " + numCells + "\n");
// "celldata"
// insideVolumeIndex outsideVolumeIndex area normalx normaly normalz
//
int cellID = 0;
int dimension = resampledGeometry.getDimension();
double correctCoeff = 1;
if (dimension == 1) {
correctCoeff = extent.getY() * extent.getZ();
} else if (dimension == 2) {
correctCoeff = extent.getZ();
}
if (surfaceCollection != null) {
for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
Surface surface = surfaceCollection.getSurfaces(i);
int region1Outside = 0;
int region1Inside = 0;
for (int j = 0; j < surface.getPolygonCount(); j++) {
Quadrilateral polygon = (Quadrilateral) surface.getPolygons(j);
Node[] node = polygon.getNodes();
cbit.vcell.render.Vect3d elementCoord = new cbit.vcell.render.Vect3d();
int nodesOnBoundary = 0;
for (int k = 0; k < node.length; k++) {
if (!node[k].getMoveX() || (dimension > 1 && !node[k].getMoveY()) || (dimension == 3 && !node[k].getMoveZ())) {
nodesOnBoundary++;
}
}
if (nodesOnBoundary == 0) {
for (int k = 0; k < node.length; k++) {
elementCoord.add(new cbit.vcell.render.Vect3d(node[k].getX(), node[k].getY(), node[k].getZ()));
}
elementCoord.scale(0.25);
} else if (nodesOnBoundary == 2) {
for (int k = 0; k < node.length; k++) {
if (!node[k].getMoveX() || !node[k].getMoveY() || !node[k].getMoveZ()) {
elementCoord.add(new cbit.vcell.render.Vect3d(node[k].getX(), node[k].getY(), node[k].getZ()));
}
}
elementCoord.scale(0.5);
} else if (nodesOnBoundary == 3) {
for (int k = 0; k < node.length; k++) {
if (!node[k].getMoveX() && !node[k].getMoveY() || !node[k].getMoveY() && !node[k].getMoveZ() || !node[k].getMoveX() && !node[k].getMoveZ()) {
elementCoord.set(node[k].getX(), node[k].getY(), node[k].getZ());
}
}
} else {
throw new RuntimeException("Unexcepted number of nodes on boundary for a polygon: " + nodesOnBoundary);
}
cbit.vcell.render.Vect3d unitNormal = new cbit.vcell.render.Vect3d();
polygon.getUnitNormal(unitNormal);
int volNeighbor1Region = regionImage.getRegionInfoFromOffset(polygon.getVolIndexNeighbor1()).getRegionIndex();
int volNeighbor2Region = regionImage.getRegionInfoFromOffset(polygon.getVolIndexNeighbor2()).getRegionIndex();
if (surface.getExteriorRegionIndex() == volNeighbor1Region && surface.getInteriorRegionIndex() == volNeighbor2Region) {
region1Outside++;
}
if (surface.getExteriorRegionIndex() == volNeighbor2Region && surface.getInteriorRegionIndex() == volNeighbor1Region) {
region1Inside++;
}
writer.write(cellID + " " + polygon.getVolIndexNeighbor1() + " " + polygon.getVolIndexNeighbor2() + " " + polygon.getArea() / correctCoeff + " " + elementCoord.getX() + " " + elementCoord.getY() + " " + elementCoord.getZ() + " " + unitNormal.getX() + " " + unitNormal.getY() + " " + unitNormal.getZ() + "\n");
cellID++;
}
if (region1Inside != surface.getPolygonCount() && region1Outside != surface.getPolygonCount()) {
throw new RuntimeException("Volume neighbor regions not consistent: [total, inside, outside]=" + surface.getPolygonCount() + "," + region1Inside + "," + region1Outside + "]");
}
}
}
}
use of cbit.vcell.geometry.surface.GeometrySurfaceDescription 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