use of cbit.vcell.solvers.CartesianMeshChombo in project vcell by virtualcell.
the class PDEDataContextPanel method findChomboSinglePointSelectionInfoForPoint.
public CurveSelectionInfo findChomboSinglePointSelectionInfoForPoint(Coordinate wc) {
if (getPdeDataContext().getCartesianMesh().isChomboMesh()) {
CartesianMeshChombo chomboMesh = (CartesianMeshChombo) getPdeDataContext().getCartesianMesh();
int memIndex = chomboMesh.findMembraneIndexFromVolumeCoordinate(wc);
if (memIndex >= 0) {
Coordinate coord = chomboMesh.getMembraneElements()[memIndex].getCentroid();
return new CurveSelectionInfo(new SinglePoint(coord));
}
}
return null;
}
use of cbit.vcell.solvers.CartesianMeshChombo in project vcell by virtualcell.
the class PDEDataContextPanel method getCurveValue.
/**
* Insert the method's description here.
* Creation date: (3/13/2001 12:53:10 PM)
* @return java.lang.String
* @param csi cbit.vcell.geometry.CurveSelectionInfo
*/
public String getCurveValue(CurveSelectionInfo csi) {
String infoS = null;
if (csi.getType() == CurveSelectionInfo.TYPE_SEGMENT) {
if (membranesAndIndexes != null) {
java.util.Enumeration<SampledCurve> keysEnum = membranesAndIndexes.keys();
while (keysEnum.hasMoreElements()) {
Curve curve = (Curve) keysEnum.nextElement();
if (csi.getCurve() == curve) {
int[] membraneIndexes = (int[]) membranesAndIndexes.get(curve);
if (meshDisplayAdapter != null) {
double[] membraneValues = meshDisplayAdapter.getDataValuesForMembraneIndexes(membraneIndexes, getPdeDataContext().getDataValues(), getPdeDataContext().getDataIdentifier().getVariableType());
if (membraneValues != null) {
Coordinate segmentWC = getPdeDataContext().getCartesianMesh().getCoordinateFromMembraneIndex(membraneIndexes[csi.getSegment()]);
String xCoordString = NumberUtils.formatNumber(segmentWC.getX());
String yCoordString = NumberUtils.formatNumber(segmentWC.getY());
String zCoordString = NumberUtils.formatNumber(segmentWC.getZ());
boolean bDefined = getDataInfoProvider() == null || getDataInfoProvider().isDefined(membraneIndexes[csi.getSegment()]);
infoS = "(" + xCoordString + "," + yCoordString + "," + zCoordString + ") [" + membraneIndexes[csi.getSegment()] + "] Value = " + (bDefined ? membraneValues[csi.getSegment()] : "Undefined");
if (getPdeDataContext().getCartesianMesh() != null && getPdeDataContext().getCartesianMesh().isChomboMesh()) {
if (bDefined && getDataInfoProvider() != null) {
StructureMetricsEntry structure = ((CartesianMeshChombo) getDataInfoProvider().getPDEDataContext().getCartesianMesh()).getStructureInfo(getDataInfoProvider().getPDEDataContext().getDataIdentifier());
if (structure != null) {
infoS += " || " + structure.getDisplayLabel();
}
}
} else {
if (getDataInfoProvider() != null) {
MembraneDataInfo membraneDataInfo = getDataInfoProvider().getMembraneDataInfo(membraneIndexes[csi.getSegment()]);
infoS += " ";
infoS += " \"" + membraneDataInfo.membraneName + "\"";
infoS += " mrID=" + membraneDataInfo.membraneRegionID;
}
String curveDescr = CurveRenderer.getROIDescriptions(segmentWC, getImagePlaneManagerPanel().getCurveRenderer());
if (curveDescr != null) {
infoS += " " + curveDescr;
}
}
break;
}
}
}
}
}
}
return infoS;
}
use of cbit.vcell.solvers.CartesianMeshChombo in project vcell by virtualcell.
the class PDEDataContextPanel method findChomboCurveSelectionInfoForPoint.
@Override
public CurveSelectionInfo findChomboCurveSelectionInfoForPoint(CoordinateIndex ci) {
if (getPdeDataContext().getCartesianMesh().isChomboMesh()) {
CartesianMeshChombo chomboMesh = (CartesianMeshChombo) getPdeDataContext().getCartesianMesh();
int memIndex = chomboMesh.findMembraneIndexFromVolumeIndex(ci);
if (memIndex >= 0) {
for (Entry<SampledCurve, int[]> entry : membranesAndIndexes.entrySet()) {
SampledCurve sc = entry.getKey();
int[] memIndexes = entry.getValue();
for (int idx = 0; idx < memIndexes.length; ++idx) {
if (memIndexes[idx] == memIndex) {
return new CurveSelectionInfo(sc, CurveSelectionInfo.TYPE_SEGMENT, idx);
}
}
}
}
}
return null;
}
use of cbit.vcell.solvers.CartesianMeshChombo in project vcell by virtualcell.
the class SimulationData method getChomboFiles.
@Override
public ChomboFiles getChomboFiles() throws IOException, XmlParseException, ExpressionException {
if (chomboFileIterationIndices == null) {
throw new RuntimeException("SimulationData.chomboFileIterationIndices is null, can't process Chombo HDF5 files");
}
if (!(getVcDataId() instanceof VCSimulationDataIdentifier)) {
throw new RuntimeException("SimulationData.getVcDataId() is not a VCSimulationDataIdentifier (type is " + getVcDataId().getClass().getName() + "), can't process chombo HDF5 files");
}
VCSimulationDataIdentifier vcDataID = (VCSimulationDataIdentifier) getVcDataId();
String expectedMeshfile = vcDataID.getID() + ".mesh.hdf5";
File meshFile = amplistorHelper.getFile(expectedMeshfile);
ChomboFiles chomboFiles = new ChomboFiles(vcDataID.getSimulationKey(), vcDataID.getJobIndex(), meshFile);
String simtaskFilePath = vcDataID.getID() + "_0.simtask.xml";
File simtaskFile = amplistorHelper.getFile(simtaskFilePath);
if (!simtaskFile.exists()) {
throw new RuntimeException("Chombo dataset mission .simtask.xml file, please rerun");
}
String xmlString = FileUtils.readFileToString(simtaskFile);
SimulationTask simTask = XmlHelper.XMLToSimTask(xmlString);
if (!simTask.getSimulation().getSolverTaskDescription().getChomboSolverSpec().isSaveChomboOutput() && !simTask.getSimulation().getSolverTaskDescription().isParallel()) {
throw new RuntimeException("Export of Chombo simulations to VTK requires chombo data, select 'Chombo' data format in simulation solver options and rerun simulation.");
}
CartesianMeshChombo chomboMesh = (CartesianMeshChombo) mesh;
FeaturePhaseVol[] featurePhaseVols = chomboMesh.getFeaturePhaseVols();
for (int timeIndex : chomboFileIterationIndices) {
if (featurePhaseVols == null) {
// for old format which doesn't have featurephasevols, we need to try ivol up to 20 for each feature
Enumeration<SubDomain> subdomainEnum = simTask.getSimulation().getMathDescription().getSubDomains();
while (subdomainEnum.hasMoreElements()) {
SubDomain subDomain = subdomainEnum.nextElement();
if (subDomain instanceof CompartmentSubDomain) {
for (int ivol = 0; ivol < 20; ++ivol) {
// can be many vol, let us try 20
findChomboFeatureVolFile(chomboFiles, vcDataID, subDomain.getName(), ivol, timeIndex);
}
}
}
} else {
// note: some feature + ivol doesn't have a file if there are no variables defined in that feature
for (FeaturePhaseVol pfv : featurePhaseVols) {
findChomboFeatureVolFile(chomboFiles, vcDataID, pfv.feature, pfv.ivol, timeIndex);
}
}
}
return chomboFiles;
}
use of cbit.vcell.solvers.CartesianMeshChombo in project vcell by virtualcell.
the class ChomboFileReader method readMesh.
private static ChomboMeshData readMesh(String meshFileName, String vol0FileName) throws Exception {
ChomboMesh chomboMesh = new ChomboMesh();
if (H5.H5open() < 0) {
throw new Exception("H5.H5open() failed");
}
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
if (fileFormat == null) {
throw new Exception("FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5) failed, returned null.");
}
FileFormat meshFile = fileFormat.createInstance(new File(meshFileName).getAbsolutePath(), FileFormat.READ);
try {
meshFile.open();
DefaultMutableTreeNode meshRootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
Group meshRootGroup = (Group) meshRootNode.getUserObject();
Group meshGroup = Hdf5Reader.getChildGroup(meshRootGroup, "mesh");
chomboMesh.setDimension(Hdf5Reader.getIntAttribute(meshGroup, MESH_ATTR_DIMENSION));
chomboMesh.setExtent(Hdf5Reader.getVect3DAttribute(meshGroup, MESH_ATTR_EXTENT, 1.0));
chomboMesh.setOrigin(Hdf5Reader.getVect3DAttribute(meshGroup, MESH_ATTR_ORIGIN, 0.0));
// it's very wasteful here, but what can I do?
CartesianMeshChombo cartesianMeshChombo = CartesianMeshChombo.readMeshFile(new File(meshFileName));
for (FeaturePhaseVol fpv : cartesianMeshChombo.getFeaturePhaseVols()) {
chomboMesh.addFeaturePhase(fpv.feature, fpv.iphase);
}
// Hdf5Reader.DataColumn[] metricsColumns = Hdf5Reader.getDataTable(meshGroup,METRICS_DATASET);
if (chomboMesh.getDimension() == 2) {
Hdf5Reader.DataColumn[] segmentColumns = Hdf5Reader.getDataTable(meshGroup, "segments");
Hdf5Reader.DataColumn[] verticesColumns = Hdf5Reader.getDataTable(meshGroup, "vertices");
ChomboBoundaries boundaries = chomboMesh.getBoundaries();
int numVertices = verticesColumns[0].getNumRows();
int numSegments = segmentColumns[0].getNumRows();
for (int i = 0; i < numVertices; i++) {
double x = verticesColumns[0].getValue(i);
double y = verticesColumns[1].getValue(i);
double z = 0.0;
boundaries.addPoint(new ChomboBoundaries.Point(x, y, z));
}
for (int i = 0; i < numSegments; i++) {
int v1 = (int) segmentColumns[1].getValue(i);
int v2 = (int) segmentColumns[2].getValue(i);
// THIS COULD BE WRONG - is the chomboIndex one-to-one with the line segments? ... if not should be in the HDF5 file.
int chomboIndex = i;
boundaries.addSegment(new ChomboBoundaries.Segment(chomboIndex, v1, v2));
}
} else if (chomboMesh.getDimension() == 3) {
Hdf5Reader.DataColumn[] surfaceTriangleColumns = Hdf5Reader.getDataTable(meshGroup, "surface triangles");
ChomboBoundaries boundaries = chomboMesh.getBoundaries();
int numTriangles = surfaceTriangleColumns[0].getNumRows();
for (int row = 0; row < numTriangles; row++) {
int index = (int) surfaceTriangleColumns[0].getValue(row);
int faceNumber = (int) surfaceTriangleColumns[1].getValue(row);
// not used currently
int neighborIndex = (int) surfaceTriangleColumns[2].getValue(row);
double x0 = surfaceTriangleColumns[3].getValue(row);
double y0 = surfaceTriangleColumns[4].getValue(row);
double z0 = surfaceTriangleColumns[5].getValue(row);
int p0_index = boundaries.getOrCreatePoint(x0, y0, z0);
double x1 = surfaceTriangleColumns[6].getValue(row);
double y1 = surfaceTriangleColumns[7].getValue(row);
double z1 = surfaceTriangleColumns[8].getValue(row);
int p1_index = boundaries.getOrCreatePoint(x1, y1, z1);
double x2 = surfaceTriangleColumns[9].getValue(row);
double y2 = surfaceTriangleColumns[10].getValue(row);
double z2 = surfaceTriangleColumns[11].getValue(row);
int p2_index = boundaries.getOrCreatePoint(x2, y2, z2);
Face face = Face.fromInteger(faceNumber);
SurfaceTriangle surfaceTriangle = new SurfaceTriangle(index, face, p0_index, p1_index, p2_index);
boundaries.addSurfaceTriangle(surfaceTriangle);
}
Hdf5Reader.DataColumn[] metricsColumns = Hdf5Reader.getDataTable(meshGroup, "membrane elements");
MeshMetrics meshMetrics = boundaries.getMeshMetrics();
int numMeshMetrics = metricsColumns[0].getNumRows();
for (int row = 0; row < numMeshMetrics; row++) {
int index = (int) metricsColumns[0].getValue(row);
int level = (int) metricsColumns[1].getValue(row);
// not used currently
int i = (int) metricsColumns[2].getValue(row);
// not used currently
int j = (int) metricsColumns[3].getValue(row);
// not used currently
int k = (int) metricsColumns[4].getValue(row);
double x = metricsColumns[5].getValue(row);
double y = metricsColumns[6].getValue(row);
double z = metricsColumns[7].getValue(row);
Vect3D center = new Vect3D(x, y, z);
double normalX = metricsColumns[8].getValue(row);
double normalY = metricsColumns[9].getValue(row);
double normalZ = metricsColumns[10].getValue(row);
Vect3D normal = new Vect3D(normalX, normalY, normalZ);
double volumeFraction = metricsColumns[11].getValue(row);
double areaFraction = metricsColumns[12].getValue(row);
int membraneId = (int) metricsColumns[13].getValue(row);
int cornerPhaseMask = (int) metricsColumns[14].getValue(row);
BorderCellInfo borderCellInfo = new BorderCellInfo(index, level, i, j, k, center, normal, volumeFraction, areaFraction, membraneId, cornerPhaseMask);
meshMetrics.addBorderCellInfo(borderCellInfo);
}
} else {
throw new Exception("failed to read chombo file, unexpected mesh dimension " + chomboMesh.getDimension());
}
} finally {
meshFile.close();
}
FileFormat vol0File = fileFormat.createInstance(new File(vol0FileName).getAbsolutePath(), FileFormat.READ);
try {
vol0File.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) vol0File.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
Group level0Group = Hdf5Reader.getChildGroup(rootGroup, "level_0");
double time = Hdf5Reader.getDoubleAttribute(level0Group, "time");
ChomboMeshData chomboMeshData = new ChomboMeshData(chomboMesh, time);
int numComponents = Hdf5Reader.getIntAttribute(rootGroup, "num_components");
int numLevels = Hdf5Reader.getIntAttribute(rootGroup, "num_levels");
int fractionComponentIndex = -1;
for (int i = 0; i < numComponents; i++) {
String compName = Hdf5Reader.getStringAttribute(rootGroup, "component_" + i);
chomboMeshData.addComponentName(compName);
if (compName.equals("fraction-0")) {
fractionComponentIndex = i;
chomboMeshData.setFraction0ComponentIndex(fractionComponentIndex);
}
}
for (int i = 0; i < numLevels; i++) {
Group levelGroup = Hdf5Reader.getChildGroup(rootGroup, "level_" + i);
int refinement = 2;
if (i == 0) {
refinement = 1;
}
ChomboLevel chomboLevel = new ChomboLevel(chomboMesh, i, refinement);
Hdf5Reader.DataColumn[] boxColumns = Hdf5Reader.getDataTable(levelGroup, "boxes");
int[] lo_i, lo_j, lo_k, hi_i, hi_j, hi_k;
if (chomboMesh.getDimension() == 2) {
lo_i = ((Hdf5Reader.IntColumn) boxColumns[0]).data;
lo_j = ((Hdf5Reader.IntColumn) boxColumns[1]).data;
hi_i = ((Hdf5Reader.IntColumn) boxColumns[2]).data;
hi_j = ((Hdf5Reader.IntColumn) boxColumns[3]).data;
lo_k = new int[boxColumns[0].getNumRows()];
hi_k = new int[boxColumns[0].getNumRows()];
} else {
lo_i = ((Hdf5Reader.IntColumn) boxColumns[0]).data;
lo_j = ((Hdf5Reader.IntColumn) boxColumns[1]).data;
lo_k = ((Hdf5Reader.IntColumn) boxColumns[2]).data;
hi_i = ((Hdf5Reader.IntColumn) boxColumns[3]).data;
hi_j = ((Hdf5Reader.IntColumn) boxColumns[4]).data;
hi_k = ((Hdf5Reader.IntColumn) boxColumns[5]).data;
}
for (int b = 0; b < boxColumns[0].getNumRows(); b++) {
ChomboBox chomboBox = new ChomboBox(chomboLevel, lo_i[b], hi_i[b], lo_j[b], hi_j[b], lo_k[b], hi_k[b], chomboMesh.getDimension());
chomboLevel.addBox(chomboBox);
}
chomboMesh.addLevel(chomboLevel);
//
// read the variables
//
Hdf5Reader.DataColumn[] data = Hdf5Reader.getDataTable(levelGroup, "data:datatype=0");
Hdf5Reader.DataColumn[] offsets = Hdf5Reader.getDataTable(levelGroup, "data:offsets=0");
ChomboLevelData chomboLevelData = new ChomboLevelData(i, fractionComponentIndex, ((Hdf5Reader.DoubleColumn) data[0]).data, ((Hdf5Reader.LongColumn) offsets[0]).data);
chomboMeshData.addLevelData(chomboLevelData);
}
readMembraneVarData(chomboMeshData, rootGroup);
return chomboMeshData;
} finally {
vol0File.close();
}
}
Aggregations