Search in sources :

Example 16 with CompartmentSubDomain

use of cbit.vcell.math.CompartmentSubDomain in project vcell by virtualcell.

the class MathTestingUtilities method comparePDEResultsWithExact.

/**
 * Insert the method's description here.
 * Creation date: (8/20/2003 12:58:10 PM)
 */
public static SimulationComparisonSummary comparePDEResultsWithExact(SimulationSymbolTable simSymbolTable, PDEDataManager dataManager, String type, double absErrorThreshold, double relErrorThreshold) throws DataAccessException, ExpressionException {
    java.util.Hashtable<String, DataErrorSummary> tempVarHash = new java.util.Hashtable<String, DataErrorSummary>();
    double[] timeArray = dataManager.getDataSetTimes();
    Variable[] vars = simSymbolTable.getVariables();
    CartesianMesh mesh = dataManager.getMesh();
    MathDescription mathDesc = simSymbolTable.getSimulation().getMathDescription();
    // Get volumeSubdomains from mathDesc/mesh and store in lookupTable
    int numVol = mesh.getSizeX() * mesh.getSizeY() * mesh.getSizeZ();
    CompartmentSubDomain[] volSubDomainLookup = new CompartmentSubDomain[numVol];
    for (int i = 0; i < numVol; i++) {
        int subVolumeIndex = mesh.getSubVolumeFromVolumeIndex(i);
        SubVolume subVolume = mathDesc.getGeometry().getGeometrySpec().getSubVolume(subVolumeIndex);
        CompartmentSubDomain compSubDomain = mathDesc.getCompartmentSubDomain(subVolume.getName());
        volSubDomainLookup[i] = compSubDomain;
    }
    // Get membraneSubdomains from mathDesc/mesh and store in lookupTable
    int numMem = mesh.getMembraneElements().length;
    MembraneSubDomain[] memSubDomainLookup = new MembraneSubDomain[numMem];
    for (int i = 0; i < numMem; i++) {
        int insideVolIndex = mesh.getMembraneElements()[i].getInsideVolumeIndex();
        int outsideVolIndex = mesh.getMembraneElements()[i].getOutsideVolumeIndex();
        MembraneSubDomain memSubDomain = mathDesc.getMembraneSubDomain(volSubDomainLookup[insideVolIndex], volSubDomainLookup[outsideVolIndex]);
        memSubDomainLookup[i] = memSubDomain;
    }
    double[] valueArray = new double[4];
    SimpleSymbolTable symbolTable = new SimpleSymbolTable(new String[] { "t", "x", "y", "z" });
    int tIndex = symbolTable.getEntry("t").getIndex();
    int xIndex = symbolTable.getEntry("x").getIndex();
    int yIndex = symbolTable.getEntry("y").getIndex();
    int zIndex = symbolTable.getEntry("z").getIndex();
    SimulationComparisonSummary simComparisonSummary = new SimulationComparisonSummary();
    String hashKey = new String("");
    long dataLength = 0;
    // for each var, do the following :
    for (int i = 0; i < vars.length; i++) {
        if (vars[i] instanceof VolVariable || vars[i] instanceof MemVariable || vars[i] instanceof FilamentVariable || vars[i] instanceof VolumeRegionVariable || vars[i] instanceof MembraneRegionVariable || vars[i] instanceof FilamentRegionVariable) {
            // for each time in timeArray,
            for (int j = 0; j < timeArray.length; j++) {
                if (type.equals(TestCaseNew.EXACT_STEADY)) {
                    if (j != (timeArray.length - 1)) {
                        continue;
                    }
                }
                // get data block from varName, data from datablock
                SimDataBlock simDataBlock = dataManager.getSimDataBlock(vars[i].getName(), timeArray[j]);
                double[] data = simDataBlock.getData();
                dataLength = data.length;
                SubDomain subDomain = null;
                Coordinate subDomainCoord = null;
                // for each point in data block ...
                for (int k = 0; k < dataLength; k++) {
                    // Get subdomain from mesh (from the lookupTable), get coordinates (x,y,z) from mesh, evaluate EXACT SOLN at that coord
                    if (vars[i] instanceof VolVariable) {
                        subDomain = volSubDomainLookup[k];
                        subDomainCoord = mesh.getCoordinateFromVolumeIndex(k);
                    } else if (vars[i] instanceof MemVariable) {
                        subDomain = memSubDomainLookup[k];
                        subDomainCoord = mesh.getCoordinateFromMembraneIndex(k);
                    } else {
                        throw new RuntimeException("Var " + vars[i].getName() + " not supported yet!");
                    }
                    hashKey = vars[i].getName() + ":" + subDomain.getName();
                    DataErrorSummary tempVar = (DataErrorSummary) tempVarHash.get(hashKey);
                    if (tempVar == null) {
                        Expression exp = new Expression(subDomain.getEquation(vars[i]).getExactSolution());
                        exp.bindExpression(simSymbolTable);
                        exp = MathUtilities.substituteFunctions(exp, simSymbolTable);
                        exp = exp.flatten();
                        exp.bindExpression(symbolTable);
                        tempVar = new DataErrorSummary(exp);
                        tempVarHash.put(hashKey, tempVar);
                    }
                    // time
                    valueArray[tIndex] = timeArray[j];
                    // x
                    valueArray[xIndex] = subDomainCoord.getX();
                    // y
                    valueArray[yIndex] = subDomainCoord.getY();
                    // z
                    valueArray[zIndex] = subDomainCoord.getZ();
                    // EXACT soln at coord subDomainCoord
                    double value = tempVar.getExactExp().evaluateVector(valueArray);
                    tempVar.addDataValues(value, data[k], timeArray[j], k, absErrorThreshold, relErrorThreshold);
                }
            // end for (k)
            }
        // end for (j)
        }
    // end - if (var)
    }
    // end for (i)
    Enumeration<String> enumKeys = tempVarHash.keys();
    while (enumKeys.hasMoreElements()) {
        String key = enumKeys.nextElement();
        DataErrorSummary tempVarSummary = tempVarHash.get(key);
        simComparisonSummary.addVariableComparisonSummary(new VariableComparisonSummary(key, tempVarSummary.getMinRef(), tempVarSummary.getMaxRef(), tempVarSummary.getMaxAbsoluteError(), tempVarSummary.getMaxRelativeError(), tempVarSummary.getL2Norm(), tempVarSummary.getTimeAtMaxAbsoluteError(), tempVarSummary.getIndexAtMaxAbsoluteError(), tempVarSummary.getTimeAtMaxRelativeError(), tempVarSummary.getIndexAtMaxRelativeError()));
    }
    return simComparisonSummary;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) SensVariable(cbit.vcell.solver.ode.SensVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) MathDescription(cbit.vcell.math.MathDescription) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) MemVariable(cbit.vcell.math.MemVariable) SimDataBlock(cbit.vcell.simdata.SimDataBlock) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) VolVariable(cbit.vcell.math.VolVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Coordinate(org.vcell.util.Coordinate) Expression(cbit.vcell.parser.Expression) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentVariable(cbit.vcell.math.FilamentVariable)

Example 17 with CompartmentSubDomain

use of cbit.vcell.math.CompartmentSubDomain in project vcell by virtualcell.

the class FiniteVolumeFileWriter method writeChomboSpec.

private void writeChomboSpec() throws ExpressionException, SolverException, PropertyVetoException, ClassNotFoundException, IOException, GeometryException, ImageException {
    if (!bChomboSolver) {
        return;
    }
    GeometrySpec geometrySpec = resampledGeometry.getGeometrySpec();
    int dimension = geometrySpec.getDimension();
    if (dimension == 1) {
        throw new SolverException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " is only supported for simulations with 2D or 3D geometry.");
    }
    Simulation simulation = getSimulationTask().getSimulation();
    SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
    ChomboSolverSpec chomboSolverSpec = solverTaskDescription.getChomboSolverSpec();
    printWriter.println(FVInputFileKeyword.CHOMBO_SPEC_BEGIN);
    printWriter.println(FVInputFileKeyword.DIMENSION + " " + geometrySpec.getDimension());
    Extent extent = geometrySpec.getExtent();
    Origin origin = geometrySpec.getOrigin();
    ISize isize = simulation.getMeshSpecification().getSamplingSize();
    switch(geometrySpec.getDimension()) {
        case 2:
            printWriter.println(FVInputFileKeyword.MESH_SIZE + " " + isize.getX() + " " + isize.getY());
            printWriter.println(FVInputFileKeyword.DOMAIN_SIZE + " " + extent.getX() + " " + extent.getY());
            printWriter.println(FVInputFileKeyword.DOMAIN_ORIGIN + " " + origin.getX() + " " + origin.getY());
            break;
        case 3:
            printWriter.println(FVInputFileKeyword.MESH_SIZE + " " + isize.getX() + " " + isize.getY() + " " + isize.getZ());
            printWriter.println(FVInputFileKeyword.DOMAIN_SIZE + " " + extent.getX() + " " + extent.getY() + " " + extent.getZ());
            printWriter.println(FVInputFileKeyword.DOMAIN_ORIGIN + " " + origin.getX() + " " + origin.getY() + " " + origin.getZ());
            break;
    }
    List<CompartmentSubDomain> featureList = new ArrayList<CompartmentSubDomain>();
    Enumeration<SubDomain> enum1 = simulation.getMathDescription().getSubDomains();
    while (enum1.hasMoreElements()) {
        SubDomain sd = enum1.nextElement();
        if (sd instanceof CompartmentSubDomain) {
            featureList.add((CompartmentSubDomain) sd);
        }
    }
    int numFeatures = featureList.size();
    CompartmentSubDomain[] features = featureList.toArray(new CompartmentSubDomain[0]);
    int[] phases = new int[numFeatures];
    Arrays.fill(phases, -1);
    phases[numFeatures - 1] = 0;
    int[] numAssigned = new int[] { 1 };
    assignPhases(features, numFeatures - 1, phases, numAssigned);
    Map<String, Integer> subDomainPhaseMap = new HashMap<String, Integer>();
    for (int i = 0; i < phases.length; ++i) {
        if (phases[i] == -1) {
            throw new SolverException("Failed to assign a phase to CompartmentSubdomain '" + features[i].getName() + "'. It might be caused by too coarsh a mesh.");
        }
        subDomainPhaseMap.put(features[i].getName(), phases[i]);
    }
    SubVolume[] subVolumes = geometrySpec.getSubVolumes();
    if (geometrySpec.hasImage()) {
        Geometry geometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
        Geometry simGeometry = geometry;
        VCImage img = geometry.getGeometrySpec().getImage();
        int factor = Math.max(Math.max(img.getNumX(), img.getNumY()), img.getNumZ()) < 512 ? 2 : 1;
        ISize distanceMapMeshSize = new ISize(img.getNumX() * factor, img.getNumY() * factor, img.getNumZ() * factor);
        Vect3d deltaX = null;
        boolean bCellCentered = false;
        double dx = 0.5;
        double dy = 0.5;
        double dz = 0.5;
        int Nx = distanceMapMeshSize.getX();
        int Ny = distanceMapMeshSize.getY();
        int Nz = distanceMapMeshSize.getZ();
        if (dimension == 2) {
            // pad the 2D image with itself in order to obtain a 3D image used to compute the distance map
            // because the distance map algorithm is 3D only (using distance to triangles)
            byte[] oldPixels = img.getPixels();
            byte[] newPixels = new byte[oldPixels.length * 3];
            System.arraycopy(oldPixels, 0, newPixels, 0, oldPixels.length);
            System.arraycopy(oldPixels, 0, newPixels, oldPixels.length, oldPixels.length);
            System.arraycopy(oldPixels, 0, newPixels, oldPixels.length * 2, oldPixels.length);
            double distX = geometry.getExtent().getX() / img.getNumX();
            double distY = geometry.getExtent().getY() / img.getNumY();
            // we set the distance on the z axis to something that makes sense
            double distZ = Math.max(distX, distY);
            Extent newExtent = new Extent(geometry.getExtent().getX(), geometry.getExtent().getY(), distZ * 3);
            VCImage newImage = new VCImageUncompressed(null, newPixels, newExtent, img.getNumX(), img.getNumY(), 3);
            // copy the pixel classes too
            ArrayList<VCPixelClass> newPixelClasses = new ArrayList<VCPixelClass>();
            for (VCPixelClass origPixelClass : geometry.getGeometrySpec().getImage().getPixelClasses()) {
                SubVolume origSubvolume = geometry.getGeometrySpec().getImageSubVolumeFromPixelValue(origPixelClass.getPixel());
                newPixelClasses.add(new VCPixelClass(null, origSubvolume.getName(), origPixelClass.getPixel()));
            }
            newImage.setPixelClasses(newPixelClasses.toArray(new VCPixelClass[newPixelClasses.size()]));
            simGeometry = new Geometry(geometry, newImage);
            Nz = 3;
        }
        GeometrySpec simGeometrySpec = simGeometry.getGeometrySpec();
        Extent simExtent = simGeometrySpec.getExtent();
        dx = simExtent.getX() / (Nx - 1);
        dy = simExtent.getY() / (Ny - 1);
        dz = simExtent.getZ() / (Nz - 1);
        if (Math.abs(dx - dy) > 0.1 * Math.max(dx, dy)) {
            dx = Math.min(dx, dy);
            dy = dx;
            Nx = (int) (simExtent.getX() / dx + 1);
            Ny = (int) (simExtent.getY() / dx + 1);
            if (dimension == 3) {
                dz = dx;
                Nz = (int) (simExtent.getZ() / dx + 1);
            }
        }
        deltaX = new Vect3d(dx, dy, dz);
        // one more point in each direction
        distanceMapMeshSize = new ISize(Nx + 1, Ny + 1, Nz + 1);
        Extent distanceMapExtent = new Extent(simExtent.getX() + dx, simExtent.getY() + dy, simExtent.getZ() + dz);
        simGeometrySpec.setExtent(distanceMapExtent);
        GeometrySurfaceDescription geoSurfaceDesc = simGeometry.getGeometrySurfaceDescription();
        geoSurfaceDesc.setVolumeSampleSize(distanceMapMeshSize);
        geoSurfaceDesc.updateAll();
        VCImage vcImage = RayCaster.sampleGeometry(simGeometry, distanceMapMeshSize, bCellCentered);
        SubvolumeSignedDistanceMap[] distanceMaps = DistanceMapGenerator.computeDistanceMaps(simGeometry, vcImage, bCellCentered);
        if (dimension == 2) {
            distanceMaps = DistanceMapGenerator.extractMiddleSlice(distanceMaps);
        }
        printWriter.println(FVInputFileKeyword.SUBDOMAINS + " " + simGeometrySpec.getNumSubVolumes() + " " + FVInputFileKeyword.DISTANCE_MAP);
        for (int i = 0; i < subVolumes.length; i++) {
            File distanceMapFile = new File(workingDirectory, getSimulationTask().getSimulationJobID() + "_" + subVolumes[i].getName() + DISTANCE_MAP_FILE_EXTENSION);
            writeDistanceMapFile(deltaX, distanceMaps[i], distanceMapFile);
            int phase = subDomainPhaseMap.get(subVolumes[i].getName());
            printWriter.println(subVolumes[i].getName() + " " + phase + " " + distanceMapFile.getAbsolutePath());
        }
    } else {
        printWriter.println(FVInputFileKeyword.SUBDOMAINS + " " + geometrySpec.getNumSubVolumes());
        Expression[] rvachevExps = convertAnalyticGeometryToRvachevFunction(geometrySpec);
        for (int i = 0; i < subVolumes.length; i++) {
            if (subVolumes[i] instanceof AnalyticSubVolume) {
                String name = subVolumes[i].getName();
                int phase = subDomainPhaseMap.get(name);
                printWriter.println(name + " " + phase + " ");
                printWriter.println(FVInputFileKeyword.IF + " " + rvachevExps[i].infix() + ";");
                printWriter.println(FVInputFileKeyword.USER + " " + ((AnalyticSubVolume) subVolumes[i]).getExpression().infix() + ";");
            }
        }
    }
    printWriter.println(FVInputFileKeyword.MAX_BOX_SIZE + " " + chomboSolverSpec.getMaxBoxSize());
    printWriter.println(FVInputFileKeyword.FILL_RATIO + " " + chomboSolverSpec.getFillRatio());
    printWriter.println(FVInputFileKeyword.RELATIVE_TOLERANCE + " " + simulation.getSolverTaskDescription().getErrorTolerance().getRelativeErrorTolerance());
    printWriter.println(FVInputFileKeyword.SAVE_VCELL_OUTPUT + " " + chomboSolverSpec.isSaveVCellOutput());
    printWriter.println(FVInputFileKeyword.SAVE_CHOMBO_OUTPUT + " " + chomboSolverSpec.isSaveChomboOutput());
    printWriter.println(FVInputFileKeyword.ACTIVATE_FEATURE_UNDER_DEVELOPMENT + " " + chomboSolverSpec.isActivateFeatureUnderDevelopment());
    printWriter.println(FVInputFileKeyword.SMALL_VOLFRAC_THRESHOLD + " " + chomboSolverSpec.getSmallVolfracThreshold());
    printWriter.println(FVInputFileKeyword.BLOCK_FACTOR + " " + chomboSolverSpec.getBlockFactor());
    printWriter.println(FVInputFileKeyword.TAGS_GROW + " " + chomboSolverSpec.getTagsGrow());
    // Refinement
    int numLevels = chomboSolverSpec.getNumRefinementLevels();
    // Refinements #Levels ratio 1, ratio 2, etc
    printWriter.print(FVInputFileKeyword.REFINEMENTS + " " + (numLevels + 1));
    List<Integer> ratios = chomboSolverSpec.getRefineRatioList();
    for (int i : ratios) {
        printWriter.print(" " + i);
    }
    // write last refinement ratio, fake
    printWriter.println(" 2");
    // membrane rois
    List<RefinementRoi> memRios = chomboSolverSpec.getMembraneRefinementRois();
    printWriter.println(FVInputFileKeyword.REFINEMENT_ROIS + " " + RoiType.Membrane + " " + memRios.size());
    for (RefinementRoi roi : memRios) {
        if (roi.getRoiExpression() == null) {
            throw new SolverException("ROI expression cannot be null");
        }
        // level tagsGrow ROIexpression
        printWriter.println(roi.getLevel() + " " + roi.getRoiExpression().infix() + ";");
    }
    List<RefinementRoi> volRios = chomboSolverSpec.getVolumeRefinementRois();
    printWriter.println(FVInputFileKeyword.REFINEMENT_ROIS + " " + RoiType.Volume + " " + volRios.size());
    for (RefinementRoi roi : volRios) {
        if (roi.getRoiExpression() == null) {
            throw new SolverException("ROI expression cannot be null");
        }
        printWriter.println(roi.getLevel() + " " + roi.getRoiExpression().infix() + ";");
    }
    printWriter.println(FVInputFileKeyword.VIEW_LEVEL + " " + chomboSolverSpec.getViewLevel());
    printWriter.println(FVInputFileKeyword.CHOMBO_SPEC_END);
    printWriter.println();
}
Also used : Origin(org.vcell.util.Origin) VCPixelClass(cbit.image.VCPixelClass) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) Extent(org.vcell.util.Extent) HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) VCImage(cbit.image.VCImage) SubvolumeSignedDistanceMap(cbit.vcell.geometry.surface.SubvolumeSignedDistanceMap) GeometrySpec(cbit.vcell.geometry.GeometrySpec) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) RefinementRoi(org.vcell.chombo.RefinementRoi) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) VCImageUncompressed(cbit.image.VCImageUncompressed) ChomboSolverSpec(org.vcell.chombo.ChomboSolverSpec) Vect3d(cbit.vcell.render.Vect3d) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume)

Example 18 with CompartmentSubDomain

use of cbit.vcell.math.CompartmentSubDomain in project vcell by virtualcell.

the class FiniteVolumeFileWriter method writeCompartments.

/**
 *COMPARTMENT_BEGIN nucleus
 *
 *BOUNDARY_CONDITIONS value value value value
 *
 *EQUATION_BEGIN rfB
 *INITIAL _VCell_FieldData_0;
 *RATE ( - (50.0 * rfB * ((x > -5.0) && (x < 5.0) && (y > -5.0) && (y < 5.0))) + (0.02 * ( - rB - rfB + (20.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0))) + _VCell_FieldData_0) * rf) - (0.1 * rfB));
 *EQUATION_END
 *
 *EQUATION_BEGIN r
 *INITIAL 5.0;
 *RATE ( - ((0.02 * r * ( - rB - rfB + (20.0 * ((x > -3.0) && (x < 3.0) && (y > -5.0) && (y < 5.0))) + _VCell_FieldData_0)) - (0.1 * rB)) + (50.0 * rf * ((x > -5.0) && (x < 5.0) && (y > -5.0) && (y < 5.0))));
 *DIFFUSION 10.0;
 *BOUNDARY_XM 5.0;
 *BOUNDARY_XP 5.0;
 *BOUNDARY_YM 5.0;
 *BOUNDARY_YP 5.0;
 *EQUATION_END
 *
 *COMPARTMENT_END
 * @throws ExpressionException
 * @throws MathException
 */
private void writeCompartments() throws ExpressionException, MathException {
    Simulation simulation = simTask.getSimulation();
    MathDescription mathDesc = simulation.getMathDescription();
    Enumeration<SubDomain> enum1 = mathDesc.getSubDomains();
    while (enum1.hasMoreElements()) {
        SubDomain sd = enum1.nextElement();
        if (sd instanceof CompartmentSubDomain) {
            CompartmentSubDomain csd = (CompartmentSubDomain) sd;
            printWriter.println("COMPARTMENT_BEGIN " + csd.getName());
            printWriter.println();
            writeCompartment_VarContext(csd);
            writeFastSystem(csd);
            printWriter.println("COMPARTMENT_END");
            printWriter.println();
        }
    }
    printWriter.println();
}
Also used : CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Simulation(cbit.vcell.solver.Simulation) MathDescription(cbit.vcell.math.MathDescription) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain)

Example 19 with CompartmentSubDomain

use of cbit.vcell.math.CompartmentSubDomain in project vcell by virtualcell.

the class ITextWriter method writeSubDomainsEquationsAsImages.

// currently not used.
protected void writeSubDomainsEquationsAsImages(Section mathDescSection, MathDescription mathDesc) {
    Enumeration<SubDomain> subDomains = mathDesc.getSubDomains();
    Expression[] expArray;
    Section volDomains = mathDescSection.addSection("Volume Domains", mathDescSection.depth() + 1);
    Section memDomains = mathDescSection.addSection("Membrane Domains", mathDescSection.depth() + 1);
    // arbitrary
    int scale = 1, height = 200;
    int viewableWidth = (int) (document.getPageSize().width() - document.leftMargin() - document.rightMargin());
    BufferedImage dummy = new BufferedImage(viewableWidth, height, BufferedImage.TYPE_3BYTE_BGR);
    while (subDomains.hasMoreElements()) {
        SubDomain subDomain = subDomains.nextElement();
        Enumeration<Equation> equationsList = subDomain.getEquations();
        ArrayList<Expression> expList = new ArrayList<Expression>();
        while (equationsList.hasMoreElements()) {
            Equation equ = equationsList.nextElement();
            try {
                Enumeration<Expression> enum_equ = equ.getTotalExpressions();
                while (enum_equ.hasMoreElements()) {
                    Expression exp = new Expression(enum_equ.nextElement());
                    expList.add(exp.flatten());
                }
            } catch (ExpressionException ee) {
                System.err.println("Unable to process the equation for subdomain: " + subDomain.getName());
                ee.printStackTrace();
                continue;
            }
        }
        expArray = (Expression[]) expList.toArray(new Expression[expList.size()]);
        Section tempSection = null;
        if (subDomain instanceof CompartmentSubDomain) {
            tempSection = volDomains.addSection(subDomain.getName(), volDomains.depth() + 1);
        } else if (subDomain instanceof MembraneSubDomain) {
            tempSection = memDomains.addSection(subDomain.getName(), memDomains.depth() + 1);
        }
        try {
            Dimension dim = ExpressionCanvas.getExpressionImageSize(expArray, (Graphics2D) dummy.getGraphics());
            System.out.println("Image dim: " + dim.width + " " + dim.height);
            BufferedImage bufferedImage = new BufferedImage((int) dim.getWidth() * scale, (int) dim.getHeight() * scale, BufferedImage.TYPE_3BYTE_BGR);
            ExpressionCanvas.getExpressionAsImage(expArray, bufferedImage, scale);
            // Table imageTable = null;;
            com.lowagie.text.Image expImage = com.lowagie.text.Image.getInstance(bufferedImage, null);
            expImage.setAlignment(com.lowagie.text.Image.LEFT);
            if (viewableWidth < expImage.scaledWidth()) {
                expImage.scaleToFit(viewableWidth, expImage.height());
                System.out.println("SubDomain expresions After scaling: " + expImage.scaledWidth());
            }
            /*Cell imageCell = new Cell();
				imageCell.add(expImage);
				if (imageTable == null) {
					imageTable = getTable(1, 100, 1, 1, 0);
				}
				imageTable.setTableFitsPage(false);
 				imageTable.setCellsFitPage(false);
				imageTable.addCell(imageCell);
				imageTable.setWidth(100);
				tempSection.add(imageTable);*/
            tempSection.add(expImage);
        } catch (Exception e) {
            System.err.println("Unable to add subdomain equation image to report.");
            e.printStackTrace();
        }
    }
    if (volDomains.isEmpty()) {
        mathDescSection.remove(volDomains);
    }
    if (memDomains.isEmpty()) {
        mathDescSection.remove(memDomains);
    }
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ArrayList(java.util.ArrayList) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) OdeEquation(cbit.vcell.math.OdeEquation) FilamentRegionEquation(cbit.vcell.math.FilamentRegionEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) Dimension(java.awt.Dimension) Section(com.lowagie.text.Section) BufferedImage(java.awt.image.BufferedImage) ExpressionException(cbit.vcell.parser.ExpressionException) DocumentException(com.lowagie.text.DocumentException) ExpressionException(cbit.vcell.parser.ExpressionException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Expression(cbit.vcell.parser.Expression) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SimulationContext(cbit.vcell.mapping.SimulationContext) GeometryContext(cbit.vcell.mapping.GeometryContext) ReactionContext(cbit.vcell.mapping.ReactionContext)

Example 20 with CompartmentSubDomain

use of cbit.vcell.math.CompartmentSubDomain in project vcell by virtualcell.

the class ITextWriter method writeSubDomainsEquationsAsText.

protected void writeSubDomainsEquationsAsText(Section mathDescSection, MathDescription mathDesc) throws DocumentException {
    Enumeration<SubDomain> subDomains = mathDesc.getSubDomains();
    Section volDomains = mathDescSection.addSection("Volume Domains", mathDescSection.depth() + 1);
    Section memDomains = mathDescSection.addSection("Membrane Domains", mathDescSection.depth() + 1);
    Section filDomains = mathDescSection.addSection("Filament Domains", mathDescSection.depth() + 1);
    while (subDomains.hasMoreElements()) {
        Section tempSection = null;
        SubDomain subDomain = subDomains.nextElement();
        if (subDomain instanceof CompartmentSubDomain) {
            tempSection = volDomains.addSection(subDomain.getName(), volDomains.depth() + 1);
        } else if (subDomain instanceof MembraneSubDomain) {
            tempSection = memDomains.addSection(subDomain.getName(), memDomains.depth() + 1);
        } else if (subDomain instanceof FilamentSubDomain) {
            tempSection = filDomains.addSection(subDomain.getName(), filDomains.depth() + 1);
        }
        Enumeration<Equation> equationsList = subDomain.getEquations();
        while (equationsList.hasMoreElements()) {
            Equation equ = equationsList.nextElement();
            writeEquation(tempSection, equ);
        }
        if (subDomain.getFastSystem() != null) {
            writeFastSystem(tempSection, subDomain.getFastSystem());
        }
        if (subDomain instanceof MembraneSubDomain) {
            Enumeration<JumpCondition> jcList = ((MembraneSubDomain) subDomain).getJumpConditions();
            while (jcList.hasMoreElements()) {
                JumpCondition jc = jcList.nextElement();
                writeJumpCondition(tempSection, jc);
            }
        }
    }
    if (volDomains.isEmpty()) {
        mathDescSection.remove(volDomains);
    }
    if (memDomains.isEmpty()) {
        mathDescSection.remove(memDomains);
    }
    if (filDomains.isEmpty()) {
        mathDescSection.remove(filDomains);
    }
}
Also used : CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) JumpCondition(cbit.vcell.math.JumpCondition) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) OdeEquation(cbit.vcell.math.OdeEquation) FilamentRegionEquation(cbit.vcell.math.FilamentRegionEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) Section(com.lowagie.text.Section) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain)

Aggregations

CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)45 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)29 SubDomain (cbit.vcell.math.SubDomain)24 Expression (cbit.vcell.parser.Expression)21 MathDescription (cbit.vcell.math.MathDescription)19 ExpressionException (cbit.vcell.parser.ExpressionException)17 SubVolume (cbit.vcell.geometry.SubVolume)16 MathException (cbit.vcell.math.MathException)16 Variable (cbit.vcell.math.Variable)16 ArrayList (java.util.ArrayList)15 Equation (cbit.vcell.math.Equation)12 VolVariable (cbit.vcell.math.VolVariable)11 Constant (cbit.vcell.math.Constant)10 SurfaceClass (cbit.vcell.geometry.SurfaceClass)9 OdeEquation (cbit.vcell.math.OdeEquation)9 PdeEquation (cbit.vcell.math.PdeEquation)9 SolverException (cbit.vcell.solver.SolverException)9 Function (cbit.vcell.math.Function)8 MemVariable (cbit.vcell.math.MemVariable)8 PropertyVetoException (java.beans.PropertyVetoException)8