Search in sources :

Example 41 with CartesianMesh

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);
    }
}
Also used : PrintStream(java.io.PrintStream) CartesianMesh(cbit.vcell.solvers.CartesianMesh) FileOutputStream(java.io.FileOutputStream) SolverException(cbit.vcell.solver.SolverException) ComsolServiceFactory(org.vcell.solver.comsol.service.ComsolServiceFactory) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 42 with CartesianMesh

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);
    }
}
Also used : CartesianMesh(cbit.vcell.solvers.CartesianMesh) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) XMLStreamException(javax.xml.stream.XMLStreamException) ThriftDataAccessException(org.vcell.vcellij.api.ThriftDataAccessException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) TException(org.apache.thrift.TException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException)

Example 43 with CartesianMesh

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();
}
Also used : VariableType(cbit.vcell.math.VariableType) ISize(org.vcell.util.ISize) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Simulation(cbit.vcell.solver.Simulation) SimDataBlock(cbit.vcell.simdata.SimDataBlock) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException)

Example 44 with CartesianMesh

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;
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed) ImageException(cbit.image.ImageException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) ROIDataGenerator(org.vcell.vmicro.workflow.data.ROIDataGenerator) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Expression(cbit.vcell.parser.Expression) RegionImage(cbit.vcell.geometry.RegionImage) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier)

Example 45 with CartesianMesh

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);
}
Also used : Origin(org.vcell.util.Origin) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) RegionImage(cbit.vcell.geometry.RegionImage) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed)

Aggregations

CartesianMesh (cbit.vcell.solvers.CartesianMesh)49 ISize (org.vcell.util.ISize)24 Extent (org.vcell.util.Extent)19 Origin (org.vcell.util.Origin)18 VariableType (cbit.vcell.math.VariableType)17 VCImageUncompressed (cbit.image.VCImageUncompressed)15 RegionImage (cbit.vcell.geometry.RegionImage)15 DataAccessException (org.vcell.util.DataAccessException)15 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)14 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)13 File (java.io.File)13 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)12 IOException (java.io.IOException)11 DataIdentifier (cbit.vcell.simdata.DataIdentifier)9 SimDataBlock (cbit.vcell.simdata.SimDataBlock)9 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)9 VCImage (cbit.image.VCImage)8 UserCancelException (org.vcell.util.UserCancelException)8 Expression (cbit.vcell.parser.Expression)7 Vector (java.util.Vector)7