use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class ComsolSolver method initialize.
@Override
protected void initialize() throws SolverException {
try {
this.vccModel = ComsolModelBuilder.getVCCModel(getSimulationJob());
// write mesh file
File meshFile = new File(getSaveDirectory(), simTask.getSimulationJob().getSimulationJobID() + SimDataConstants.MESHFILE_EXTENSION);
try (FileOutputStream fos = new FileOutputStream(meshFile)) {
simTask.getSimulation().getMathDescription().getGeometry().getGeometrySurfaceDescription().updateAll();
CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(simTask.getSimulation().getMathDescription().getGeometry());
mesh.write(new PrintStream(new BufferedOutputStream(fos)));
} catch (Exception e) {
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
}
ComsolServiceFactory factory = ComsolServiceFactory.instance;
if (factory == null) {
throw new RuntimeException("no Comsol Service available");
}
this.comsolService = factory.newComsolService();
} catch (ExpressionException e) {
e.printStackTrace();
throw new SolverException("failed to generate VCell Comsol Model in ComsolSolver: " + e.getMessage(), e);
}
}
use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class SimulationServiceImpl method mesh.
private CartesianMesh mesh(SimulationInfo simInfo) {
SimulationServiceContext simServiceContext = sims.get(simInfo.id);
try {
DataSetControllerImpl datasetController = getDataSetController(simServiceContext);
CartesianMesh mesh = datasetController.getMesh(simServiceContext.vcDataIdentifier);
return mesh;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class ROIDataGenerator method getROIDataGeneratorDescription.
public String getROIDataGeneratorDescription(File userDirectory, SimulationJob simulationJob) throws Exception {
// DataAccessException, FileNotFoundException, MathException, IOException, DivideByZeroException, ExpressionException
Simulation simulation = simulationJob.getSimulation();
StringBuffer sb = new StringBuffer();
sb.append(ROI_GENERATOR_BEGIN + " " + name + "\n");
sb.append("VolumePoints " + volumePoints.length + "\n");
for (int i = 0; i < volumePoints.length; i++) {
sb.append(volumePoints[i] + " ");
if ((i + 1) % 20 == 0) {
sb.append("\n");
}
}
sb.append("\n");
if (membranePoints != null && membranePoints.length > 0) {
sb.append("MembranePoints " + membranePoints.length + "\n");
for (int i = 0; i < membranePoints.length; i++) {
sb.append(membranePoints[i] + " ");
if ((i + 1) % 20 == 0) {
sb.append("\n");
}
}
sb.append("\n");
}
sb.append("SampleImage " + numImgRegions + " " + zSlice + " " + fieldDataKey + " " + fieldFuncArguments.infix() + "\n");
sb.append("StoreEnabled " + bStoreEnabled + "\n");
// sample image field data file
FieldDataIdentifierSpec fdis = getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in ROI data generator.");
}
String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
DataSetControllerImpl dsci = new DataSetControllerImpl(null, userDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fdis.getFieldFuncArgs().getVariableType();
VariableType dataVarType = simDataBlock.getVariableType();
if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
}
double[] origData = simDataBlock.getData();
String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simulationJob.getJobIndex()) + SimulationData.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
File fdatFile = new File(userDirectory, filename);
DataSet.writeNew(fdatFile, new String[] { fdis.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(origMesh.getSizeX(), origMesh.getSizeY(), origMesh.getSizeZ()), new double[][] { origData });
sb.append("SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile + "\n");
sb.append(ROI_GENERATOR_END);
return sb.toString();
}
use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class RunRefSimulationFastOp method getROIDataGenerator.
private ROIDataGenerator getROIDataGenerator(LocalContext localWorkspace, ROI[] rois) throws ImageException, IOException {
// create ROI image
short[] roiFieldData = null;
if (rois.length > 0) {
Origin origin = new Origin(0, 0, 0);
Extent extent = rois[0].getRoiImages()[0].getExtent();
ISize isize = rois[0].getISize();
int numROIX = rois[0].getISize().getX();
int numROIY = rois[0].getISize().getY();
roiFieldData = new short[numROIX * numROIY];
short regionCounter = 1;
for (int roiIdx = 0; roiIdx < rois.length; roiIdx++) {
short[] roiImg = rois[roiIdx].getPixelsXYZ();
for (int pixelIdx = 0; pixelIdx < (numROIX * numROIY); pixelIdx++) {
if (roiImg[pixelIdx] > 0) {
roiFieldData[pixelIdx] = regionCounter;
}
}
regionCounter++;
}
// create field data
int NumTimePoints = 1;
// 8 rois integrated into 1 image
int NumChannels = 1;
short[][][] pixData = new short[NumTimePoints][NumChannels][];
pixData[0][0] = roiFieldData;
// get extental data id
VCImage vcImage = new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ());
RegionImage regionImage = new RegionImage(vcImage, 0, null, null, RegionImage.NO_SMOOTHING);
CartesianMesh simpleCartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
ExternalDataIdentifier newROIExtDataID = createNewExternalDataInfo(localWorkspace, ROI_SUMDATA_NAME).getExternalDataIdentifier();
try {
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = simpleCartesianMesh;
fdos.shortSpecData = pixData;
fdos.specEDI = newROIExtDataID;
fdos.varNames = new String[] { "roiSumDataVar" };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = new double[] { 0.0 };
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new ROIDataGenerator(ROI_EXTDATA_NAME, /*name*/
new int[] { 0 }, /* volumePoints*/
new int[0], /* membranePoints*/
regionCounter, /*numRegions*/
0, /*zSlice*/
newROIExtDataID.getKey(), /* fieldDataKey, sample image*/
new FieldFunctionArguments(ROI_SUMDATA_NAME, ROI_SUMDATA_VARNAME, new Expression(0), VariableType.VOLUME), /*FieldFunctionArguments, sample image*/
false);
}
return null;
}
use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.
the class RunRefSimulationFastOp method saveExternalData.
private void saveExternalData(Image image, String varName, ExternalDataIdentifier newROIExtDataID, LocalWorkspace localWorkspace) throws ObjectNotFoundException, ImageException, IOException {
Extent extent = image.getExtent();
Origin origin = image.getOrigin();
ISize isize = image.getISize();
VCImage vcImage = new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ());
RegionImage regionImage = new RegionImage(vcImage, 0, null, null, RegionImage.NO_SMOOTHING);
CartesianMesh simpleCartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
int NumTimePoints = 1;
int NumChannels = 1;
// dimensions: time points, channels, whole image ordered by z slices.
double[][][] pixData = new double[NumTimePoints][NumChannels][];
pixData[0][0] = image.getDoublePixels();
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = simpleCartesianMesh;
fdos.doubleSpecData = pixData;
fdos.specEDI = newROIExtDataID;
fdos.varNames = new String[] { varName };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = new double[] { 0.0 };
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
Aggregations