use of org.vcell.vis.vismesh.thrift.VisMesh in project vcell by virtualcell.
the class ComsolMeshReader method main.
public static void main(String[] args) {
try {
System.getProperties().setProperty(PropertyLoader.installationRoot, "d:\\developer\\eclipse\\workspace_refactor\\VCell_6.1_userdata");
File comsolFile = new File("simoutput_multitime.txt");
VisMesh visMesh = new VisMesh();
read(visMesh, comsolFile);
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.vcell.vis.vismesh.thrift.VisMesh in project vcell by virtualcell.
the class ComsolSolver method startSolver.
@Override
public void startSolver() {
try {
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_STARTING, SimulationMessage.MESSAGE_SOLVER_STARTING_INIT));
initialize();
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING);
String filePrefix = simTask.getSimulationJob().getSimulationJobID();
try {
comsolService.connectComsol();
File reportFile = new File(getSaveDirectory(), filePrefix + ".comsoldat");
File javaFile = new File(getSaveDirectory(), filePrefix + ".java");
File mphFile = new File(getSaveDirectory(), filePrefix + ".mph");
comsolService.solve(this.vccModel, reportFile, javaFile, mphFile);
} finally {
comsolService.disconnectComsol();
}
File logFile = new File(getSaveDirectory(), filePrefix + ".log");
FileUtils.writeStringToFile(logFile, createLogFileContents(simTask.getSimulation().getSolverTaskDescription()));
VisMesh visMesh = new VisMesh();
File reportFile = new File(getSaveDirectory(), filePrefix + ".comsoldat");
ComsolMeshReader.read(visMesh, reportFile);
time = simTask.getSimulation().getSolverTaskDescription().getTimeBounds().getEndingTime();
progress = 1.0;
fireSolverPrinted(time);
fireSolverProgress(progress);
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_FINISHED, SimulationMessage.MESSAGE_SOLVER_FINISHED));
fireSolverFinished();
} catch (Exception e) {
e.printStackTrace(System.out);
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted(e.getMessage())));
fireSolverAborted(SimulationMessage.solverAborted(e.getMessage()));
}
}
use of org.vcell.vis.vismesh.thrift.VisMesh in project vcell by virtualcell.
the class MovingBoundaryVtkFileWriter method writeEmptyMeshFiles.
public File[] writeEmptyMeshFiles(MovingBoundarySimFiles movingBoundaryFiles, int timeIndex, File destinationDirectory, ProgressListener progressListener) throws IOException, MathException, DataAccessException {
HashMap<String, VisMesh> domainMeshMap = new HashMap<String, VisMesh>();
ArrayList<String> allDomainNames = new ArrayList<String>();
File hdf5OutputFile = movingBoundaryFiles.hdf5OutputFile;
MovingBoundaryReader reader = new MovingBoundaryReader(hdf5OutputFile.getAbsolutePath());
//
// for inside volume domain in mesh, extract the associated VisMesh
//
{
String insideDomainName = reader.getFakeInsideDomainName();
MovingBoundaryMeshMapping insideMeshMapping = new MovingBoundaryMeshMapping();
VisMesh insideVisMesh = insideMeshMapping.fromReader(reader, DomainType.INSIDE, timeIndex);
domainMeshMap.put(insideDomainName, insideVisMesh);
allDomainNames.add(insideDomainName);
}
// {
// String outsideDomainName = reader.getFakeOutsideDomainName();
// MovingBoundaryMeshMapping outsideMeshMapping = new MovingBoundaryMeshMapping();
// VisMesh outsideVisMesh = outsideMeshMapping.fromReader(reader, DomainType.OUTSIDE, timeIndex);
// domainMeshMap.put(outsideDomainName, outsideVisMesh);
// allDomainNames.add(outsideDomainName);
// }
// {
// String membraneDomainName = reader.getFakeMembraneDomainName();
// MovingBoundaryMeshMapping membraneMeshMapping = new MovingBoundaryMeshMapping();
// VisMesh membraneVisMesh = membraneMeshMapping.fromReader(reader, DomainType.MEMBRANE, timeIndex);
// domainMeshMap.put(membraneDomainName, membraneVisMesh);
// allDomainNames.add(membraneDomainName);
// }
int numFiles = allDomainNames.size();
ArrayList<File> files = new ArrayList<File>();
int filesProcessed = 0;
for (final String domainName : allDomainNames) {
//
// find the globalIndexes for each domain element - use this to extract the domain-only data.
//
VisMesh visMesh = domainMeshMap.get(domainName);
File vtuFile = getVtuMeshFileName(destinationDirectory, movingBoundaryFiles, domainName, timeIndex);
File mbIndexDataFileName = getMovingBoundaryIndexDataFileName(movingBoundaryFiles, domainName, timeIndex);
VtkService.getInstance().writeMovingBoundaryVtkGridAndIndexData(visMesh, domainName, vtuFile, mbIndexDataFileName);
files.add(vtuFile);
filesProcessed++;
if (progressListener != null) {
progressListener.progress(((double) filesProcessed) / numFiles);
}
}
return files.toArray(new File[0]);
}
use of org.vcell.vis.vismesh.thrift.VisMesh in project vcell by virtualcell.
the class CartesianMeshMapping method fromMesh3DMembrane.
private VisMesh fromMesh3DMembrane(CartesianMesh cartesianMesh, String domainName) {
ISize size = cartesianMesh.getSize();
int numX = size.getX();
int numY = size.getY();
int dimension = 3;
Vect3D origin = new Vect3D(cartesianMesh.getOrigin().x, cartesianMesh.getOrigin().y, cartesianMesh.getOrigin().z);
Vect3D extent = new Vect3D(cartesianMesh.getExtent().x, cartesianMesh.getExtent().y, cartesianMesh.getExtent().z);
// invoke VisMesh() constructor
VisMesh visMesh = new VisMesh(dimension, origin, extent);
int currPointIndex = 0;
HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
List<MembraneElement> membraneElements = cartesianMesh.getMembraneElements(domainName);
for (MembraneElement membraneElement : membraneElements) {
// inside
int insideVolumeIndex = membraneElement.getInsideVolumeIndex();
int insideI = insideVolumeIndex % numX;
int insideJ = (insideVolumeIndex % (numX * numY)) / numX;
int insideK = insideVolumeIndex / (numX * numY);
Box3D insideBox = cartesianMesh.getVolumeElementBox(insideI, insideJ, insideK);
// outside
int outsideVolumeIndex = membraneElement.getOutsideVolumeIndex();
int outsideI = outsideVolumeIndex % numX;
int outsideJ = (outsideVolumeIndex % (numX * numY)) / numX;
int outsideK = outsideVolumeIndex / (numX * numY);
VisPoint p1Coord;
VisPoint p2Coord;
VisPoint p3Coord;
VisPoint p4Coord;
if (insideI == outsideI + 1) {
// x- z cross y
double x = insideBox.x_lo;
p1Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_lo);
p2Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_hi);
p3Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_hi);
p4Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_lo);
} else if (outsideI == insideI + 1) {
// x+ y cross z
double x = insideBox.x_hi;
p1Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_lo);
p2Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_lo);
p3Coord = new VisPoint(x, insideBox.y_hi, insideBox.z_hi);
p4Coord = new VisPoint(x, insideBox.y_lo, insideBox.z_hi);
} else if (insideJ == outsideJ + 1) {
// y- x cross z
double y = insideBox.y_lo;
p1Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_lo);
p2Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_lo);
p3Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_hi);
p4Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_hi);
} else if (outsideJ == insideJ + 1) {
// y+ z cross x
double y = insideBox.y_hi;
p1Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_lo);
p2Coord = new VisPoint(insideBox.x_lo, y, insideBox.z_hi);
p3Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_hi);
p4Coord = new VisPoint(insideBox.x_hi, y, insideBox.z_lo);
} else if (insideK == outsideK + 1) {
// z- y cross x
double z = insideBox.z_lo;
p1Coord = new VisPoint(insideBox.x_lo, insideBox.y_lo, z);
p2Coord = new VisPoint(insideBox.x_lo, insideBox.y_hi, z);
p3Coord = new VisPoint(insideBox.x_hi, insideBox.y_hi, z);
p4Coord = new VisPoint(insideBox.x_hi, insideBox.y_lo, z);
} else if (outsideK == insideK + 1) {
// z+ x cross y
double z = insideBox.z_hi;
p1Coord = new VisPoint(insideBox.x_lo, insideBox.y_lo, z);
p2Coord = new VisPoint(insideBox.x_hi, insideBox.y_lo, z);
p3Coord = new VisPoint(insideBox.x_hi, insideBox.y_hi, z);
p4Coord = new VisPoint(insideBox.x_lo, insideBox.y_hi, z);
} else {
throw new RuntimeException("inside/outside volume indices not reconciled in membraneElement " + membraneElement.getMembraneIndex() + " in domain " + domainName);
}
//
// make sure vertices are added to model without duplicates and get the assigned identifier.
//
String p1Key = toStringKey(p1Coord);
Integer i1 = pointDict.get(p1Key);
if (i1 == null) {
pointDict.put(p1Key, currPointIndex);
i1 = currPointIndex;
visMesh.addToPoints(p1Coord);
currPointIndex++;
}
String p2Key = toStringKey(p2Coord);
Integer i2 = pointDict.get(p2Key);
if (i2 == null) {
pointDict.put(p2Key, currPointIndex);
i2 = currPointIndex;
visMesh.addToPoints(p2Coord);
currPointIndex++;
}
String p3Key = toStringKey(p3Coord);
Integer i3 = pointDict.get(p3Key);
if (i3 == null) {
pointDict.put(p3Key, currPointIndex);
i3 = currPointIndex;
visMesh.addToPoints(p3Coord);
currPointIndex++;
}
String p4Key = toStringKey(p4Coord);
Integer i4 = pointDict.get(p4Key);
if (i4 == null) {
pointDict.put(p4Key, currPointIndex);
i4 = currPointIndex;
visMesh.addToPoints(p4Coord);
currPointIndex++;
}
VisPolygon quad = new VisPolygon(Arrays.asList(new Integer[] { i1, i2, i3, i4 }));
quad.setFiniteVolumeIndex(new FiniteVolumeIndex(membraneElement.getMembraneIndex(), cartesianMesh.getMembraneRegionIndex(membraneElement.getMembraneIndex())));
// print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
visMesh.addToPolygons(quad);
}
return visMesh;
}
use of org.vcell.vis.vismesh.thrift.VisMesh in project vcell by virtualcell.
the class ChomboMeshMapping method fromMeshData2D.
private VisMesh fromMeshData2D(ChomboMeshData chomboMeshData) {
ChomboMesh chomboMesh = chomboMeshData.getMesh();
ChomboLevel finestLevel = chomboMesh.getLevel(chomboMesh.getNumLevels() - 1);
int finestAbsRefinement = finestLevel.getAbsoluteRefinement();
ISize size = finestLevel.getSize();
int numX = size.getX();
int numY = size.getY();
int numZ = size.getZ();
int dimension = chomboMeshData.getMesh().getDimension();
int z = 0;
// invoke VisMesh() constructor
VisMesh visMesh = new VisMesh(chomboMesh.getDimension(), toThrift(chomboMesh.getOrigin()), toThrift(chomboMesh.getExtent()));
int currPointIndex = 0;
HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
double originX = chomboMesh.getOrigin().x;
double originY = chomboMesh.getOrigin().y;
double originZ = chomboMesh.getOrigin().z;
double extentX = chomboMesh.getExtent().x;
double extentY = chomboMesh.getExtent().y;
double extentZ = chomboMesh.getExtent().z;
ChomboBoundaries chomboBoundaries = chomboMesh.getBoundaries();
for (ChomboBoundaries.Point chomboPoint : chomboBoundaries.getPoints()) {
double px = chomboPoint.x;
double py = chomboPoint.y;
double pz = z;
px = (px - originX) * (numX) / extentX * 2 - 1;
py = (py - originY) * (numY) / extentY * 2 - 1;
pz = (pz - originZ) * (numZ) / extentZ * 2 - 1;
if (dimension == 2) {
pz = z;
}
VisPoint newVisPoint = new VisPoint(px, py, pz);
String coordKey = toStringKey(newVisPoint);
pointDict.put(coordKey, currPointIndex);
visMesh.addToPoints(newVisPoint);
visMesh.addToSurfacePoints(newVisPoint);
currPointIndex += 1;
}
for (ChomboBoundaries.Segment segment : chomboBoundaries.getSegments()) {
VisLine newVisLine = new VisLine(segment.getP1(), segment.getP2());
newVisLine.setChomboSurfaceIndex(new ChomboSurfaceIndex(segment.getChomboIndex()));
visMesh.addToVisLines(newVisLine);
}
for (int levelIndex = 0; levelIndex < chomboMesh.getNumLevels(); levelIndex++) {
ChomboLevelData chomboLevelData = chomboMeshData.getLevelData(levelIndex);
ChomboLevel currLevel = chomboMesh.getLevel(levelIndex);
int currAbsRefinement = currLevel.getAbsoluteRefinement();
Covering covering = currLevel.getCovering();
int[] levelMap = covering.getLevelMap();
int[] boxNumberMap = covering.getBoxNumberMap();
int[] boxIndexMap = covering.getBoxIndexMap();
int levelNumX = currLevel.getSize().getX();
int levelNumY = currLevel.getSize().getY();
for (int x = 0; x < levelNumX; x++) {
for (int y = 0; y < levelNumY; y++) {
int mapIndex = x + y * levelNumX;
if (levelMap[mapIndex] == levelIndex) {
//
// if fraction (volume fraction of element in box) is 0 ... then skip this element
//
int boxNumber = boxNumberMap[mapIndex];
int boxIndex = boxIndexMap[mapIndex];
double fraction = chomboLevelData.getCellFraction(currLevel, boxNumber, boxIndex);
if (fraction > 0) {
//
// add cell
//
ChomboBox chomboBox = new ChomboBox(currLevel, x, x, y, y, z, z, dimension).getProjectedBox(currAbsRefinement, finestAbsRefinement);
double minX = 2 * chomboBox.getMinX() - 1;
double maxX = 2 * chomboBox.getMaxX() + 1;
double minY = 2 * chomboBox.getMinY() - 1;
double maxY = 2 * chomboBox.getMaxY() + 1;
//
// counter clockwise points for a VisPolygon ... initially a quad ... then may be
//
// minX,minY
// minX,maxY
// maxX,maxY
// maxX,minY
//
VisPoint p1Coord = new VisPoint(minX, minY, z);
String p1Key = toStringKey(p1Coord);
Integer i1 = pointDict.get(p1Key);
if (i1 == null) {
pointDict.put(p1Key, currPointIndex);
i1 = currPointIndex;
visMesh.addToPoints(p1Coord);
currPointIndex++;
}
VisPoint p2Coord = new VisPoint(minX, maxY, z);
String p2Key = toStringKey(p2Coord);
Integer i2 = pointDict.get(p2Key);
if (i2 == null) {
pointDict.put(p2Key, currPointIndex);
i2 = currPointIndex;
visMesh.addToPoints(p2Coord);
currPointIndex++;
}
VisPoint p3Coord = new VisPoint(maxX, maxY, z);
String p3Key = toStringKey(p3Coord);
Integer i3 = pointDict.get(p3Key);
if (i3 == null) {
pointDict.put(p3Key, currPointIndex);
i3 = currPointIndex;
visMesh.addToPoints(p3Coord);
currPointIndex++;
}
VisPoint p4Coord = new VisPoint(maxX, minY, z);
String p4Key = toStringKey(p4Coord);
Integer i4 = pointDict.get(p4Key);
if (i4 == null) {
pointDict.put(p4Key, currPointIndex);
i4 = currPointIndex;
visMesh.addToPoints(p4Coord);
currPointIndex++;
}
VisPolygon quad = new VisPolygon(Arrays.asList(new Integer[] { i1, i2, i3, i4 }));
quad.setChomboVolumeIndex(new ChomboVolumeIndex(levelIndex, boxNumber, boxIndex, fraction));
// print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
visMesh.addToPolygons(quad);
}
}
}
}
}
cropQuads(visMesh);
return visMesh;
}
Aggregations