Search in sources :

Example 11 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class SmoldynSurfaceTessellator method writeSurfaces.

protected void writeSurfaces() throws SolverException, ImageException, PropertyVetoException, GeometryException, ExpressionException {
    GeometrySurfaceDescription geometrySurfaceDescription = resampledGeometry.getGeometrySurfaceDescription();
    SurfaceClass[] surfaceClasses = geometrySurfaceDescription.getSurfaceClasses();
    GeometrySpec geometrySpec = resampledGeometry.getGeometrySpec();
    SubVolume[] surfaceGeometrySubVolumes = geometrySpec.getSubVolumes();
    GeometricRegion[] AllGeometricRegions = resampledGeometry.getGeometrySurfaceDescription().getGeometricRegions();
    ArrayList<SurfaceGeometricRegion> surfaceRegionList = new ArrayList<SurfaceGeometricRegion>();
    ArrayList<VolumeGeometricRegion> volumeRegionList = new ArrayList<VolumeGeometricRegion>();
    for (GeometricRegion geometricRegion : AllGeometricRegions) {
        if (geometricRegion instanceof SurfaceGeometricRegion) {
            surfaceRegionList.add((SurfaceGeometricRegion) geometricRegion);
        } else if (geometricRegion instanceof VolumeGeometricRegion) {
            volumeRegionList.add((VolumeGeometricRegion) geometricRegion);
        } else {
            throw new SolverException("unsupported geometric region type " + geometricRegion.getClass());
        }
    }
    printWriter.println("# geometry");
    printWriter.println(SmoldynVCellMapper.SmoldynKeyword.dim + " " + dimension);
    if (bHasNoSurface) {
        printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_compartment + " " + surfaceGeometrySubVolumes.length);
    } else {
        printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_compartment + " " + (surfaceGeometrySubVolumes.length + 1));
        // plus the surface which are bounding walls
        printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_surface + " " + (surfaceClasses.length + dimension));
    }
    printWriter.println();
    // write boundaries and wall surfaces
    writeWallSurfaces();
    // for 3D ... smoldyn normal convension is triangle right-hand-rule normal points to the outside compartment subdomain.
    if (!bHasNoSurface) {
        membraneSubdomainTriangleMap = new HashMap<MembraneSubDomain, ArrayList<TrianglePanel>>();
        // write surfaces
        printWriter.println("# surfaces");
        int triangleGlobalCount = 0;
        int membraneIndex = -1;
        SurfaceCollection surfaceCollection = geometrySurfaceDescription.getSurfaceCollection();
        // pre-allocate collections used repeatedly in following loops; clear before reusing
        HashMap<Node, Set<String>> nodeTriMap = new HashMap<>();
        ArrayList<TrianglePanel> triList = new ArrayList<TrianglePanel>();
        // use a sorted set to ensure neighbors written out is same order for reproducibility
        SortedSet<String> neighborsForCurrentNode = new TreeSet<String>();
        for (int sci = 0; sci < surfaceClasses.length; sci++) {
            nodeTriMap.clear();
            triList.clear();
            int triLocalCount = 0;
            SurfaceClass surfaceClass = surfaceClasses[sci];
            GeometricRegion[] geometricRegions = geometrySurfaceDescription.getGeometricRegions(surfaceClass);
            for (GeometricRegion gr : geometricRegions) {
                SurfaceGeometricRegion sgr = (SurfaceGeometricRegion) gr;
                VolumeGeometricRegion volRegion0 = (VolumeGeometricRegion) sgr.getAdjacentGeometricRegions()[0];
                VolumeGeometricRegion volRegion1 = (VolumeGeometricRegion) sgr.getAdjacentGeometricRegions()[1];
                SubVolume subVolume0 = volRegion0.getSubVolume();
                SubVolume subVolume1 = volRegion1.getSubVolume();
                CompartmentSubDomain compart0 = mathDesc.getCompartmentSubDomain(subVolume0.getName());
                CompartmentSubDomain compart1 = mathDesc.getCompartmentSubDomain(subVolume1.getName());
                MembraneSubDomain membraneSubDomain = mathDesc.getMembraneSubDomain(compart0, compart1);
                if (membraneSubDomain == null) {
                    throw new SolverException(VCellErrorMessages.getSmoldynUnexpectedSurface(compart0, compart1));
                }
                int exteriorRegionID = volRegion0.getRegionID();
                int interiorRegionID = volRegion1.getRegionID();
                if (membraneSubDomain.getInsideCompartment() == compart0) {
                    exteriorRegionID = volRegion1.getRegionID();
                    interiorRegionID = volRegion0.getRegionID();
                }
                for (int j = 0; j < surfaceCollection.getSurfaceCount(); j++) {
                    Surface surface = surfaceCollection.getSurfaces(j);
                    if ((surface.getInteriorRegionIndex() == exteriorRegionID && surface.getExteriorRegionIndex() == interiorRegionID) || (surface.getInteriorRegionIndex() == interiorRegionID && surface.getExteriorRegionIndex() == exteriorRegionID)) {
                        // Polygon polygon = surface.getPolygons(k);
                        for (Polygon polygon : surface) {
                            if (polygonMembaneElementMap != null) {
                                membraneIndex = polygonMembaneElementMap.get(polygon).getMembraneIndex();
                            }
                            Node[] nodes = polygon.getNodes();
                            if (dimension == 2) {
                                // ignore z
                                Vect3d unitNormal = new Vect3d();
                                polygon.getUnitNormal(unitNormal);
                                unitNormal.set(unitNormal.getX(), unitNormal.getY(), 0);
                                int point0 = 0;
                                Vect3d v0 = new Vect3d(nodes[point0].getX(), nodes[point0].getY(), 0);
                                int point1 = 1;
                                Vect3d v1 = null;
                                for (point1 = 1; point1 < nodes.length; point1++) {
                                    if (v0.getX() != nodes[point1].getX() || v0.getY() != nodes[point1].getY()) {
                                        v1 = new Vect3d(nodes[point1].getX(), nodes[point1].getY(), 0);
                                        break;
                                    }
                                }
                                if (v1 == null) {
                                    throw new RuntimeException("failed to generate surface");
                                }
                                Vect3d v01 = Vect3d.sub(v1, v0);
                                Vect3d unit01n = v01.cross(unitNormal);
                                unit01n.unit();
                                if (Math.abs(unit01n.getZ() - 1.0) < 1e-6) {
                                    // v0 to v1 opposes vcell surface normal. it's already flipped.
                                    Triangle triangle;
                                    if (surface.getInteriorRegionIndex() == interiorRegionID) {
                                        // we have to flipped it back
                                        triangle = new Triangle(nodes[point1], nodes[point0], null);
                                    } else {
                                        triangle = new Triangle(nodes[point0], nodes[point1], null);
                                    }
                                    triList.add(new TrianglePanel(triLocalCount++, triangleGlobalCount++, membraneIndex, triangle));
                                } else if (Math.abs(unit01n.getZ() + 1.0) < 1e-6) {
                                    // v0 to v1 is in direction of vcell surface normal.
                                    Triangle triangle;
                                    if (surface.getInteriorRegionIndex() == interiorRegionID) {
                                        triangle = new Triangle(nodes[point0], nodes[point1], null);
                                    } else {
                                        triangle = new Triangle(nodes[point1], nodes[point0], null);
                                    }
                                    triList.add(new TrianglePanel(triLocalCount++, triangleGlobalCount++, membraneIndex, triangle));
                                } else {
                                    throw new RuntimeException("failed to generate surface");
                                }
                            } else if (dimension == 3) {
                                Triangle triangle1;
                                Triangle triangle2;
                                if (surface.getInteriorRegionIndex() == interiorRegionID) {
                                    // interior
                                    triangle1 = new Triangle(nodes[0], nodes[1], nodes[2]);
                                    triangle2 = new Triangle(nodes[0], nodes[2], nodes[3]);
                                } else {
                                    triangle1 = new Triangle(nodes[2], nodes[1], nodes[0]);
                                    triangle2 = new Triangle(nodes[3], nodes[2], nodes[0]);
                                }
                                triList.add(new TrianglePanel(triLocalCount++, triangleGlobalCount++, membraneIndex, triangle1));
                                triList.add(new TrianglePanel(triLocalCount++, triangleGlobalCount++, membraneIndex, triangle2));
                            }
                        }
                    }
                }
            }
            // add triangles to node hash
            for (TrianglePanel triPanel : triList) {
                for (Node node : triPanel.triangle.getNodes()) {
                    if (node == null) {
                        continue;
                    }
                    Set<String> triNameSet = nodeTriMap.get(node);
                    if (triNameSet == null) {
                        triNameSet = new HashSet<String>();
                        nodeTriMap.put(node, triNameSet);
                    }
                    triNameSet.add(triPanel.name);
                }
            }
            SubVolume[] adjacentSubvolums = surfaceClass.getAdjacentSubvolumes().toArray(new SubVolume[0]);
            CompartmentSubDomain csd0 = simulation.getMathDescription().getCompartmentSubDomain(adjacentSubvolums[0].getName());
            CompartmentSubDomain csd1 = simulation.getMathDescription().getCompartmentSubDomain(adjacentSubvolums[1].getName());
            MembraneSubDomain membraneSubDomain = simulation.getMathDescription().getMembraneSubDomain(csd0, csd1);
            membraneSubdomainTriangleMap.put(membraneSubDomain, triList);
            final boolean initialMoleculesOnMembrane = (closestTriangles != null);
            if (initialMoleculesOnMembrane) {
                findClosestTriangles(membraneSubDomain, triList);
            }
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.start_surface + " " + surfaceClass.getName());
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.action + " " + SmoldynVCellMapper.SmoldynKeyword.all + "(" + SmoldynVCellMapper.SmoldynKeyword.all + ") " + SmoldynVCellMapper.SmoldynKeyword.both + " " + SmoldynVCellMapper.SmoldynKeyword.reflect);
            // printWriter.println(SmoldynKeyword.action + " " + SmoldynKeyword.all + "(" + SmoldynKeyword.up + ") " + SmoldynKeyword.both + " " + SmoldynKeyword.reflect);
            Color c = colorForSurface(sci);
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.color + " " + SmoldynVCellMapper.SmoldynKeyword.both + " " + c.getRed() / 255.0 + " " + c.getGreen() / 255.0 + " " + c.getBlue() / 255.0 + " 0.1");
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.polygon + " " + SmoldynVCellMapper.SmoldynKeyword.front + " " + SmoldynVCellMapper.SmoldynKeyword.edge);
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.polygon + " " + SmoldynVCellMapper.SmoldynKeyword.back + " " + SmoldynVCellMapper.SmoldynKeyword.edge);
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_panels + " " + SmoldynVCellMapper.SmoldynKeyword.tri + " " + triList.size());
            for (TrianglePanel trianglePanel : triList) {
                Triangle triangle = trianglePanel.triangle;
                printWriter.print(SmoldynVCellMapper.SmoldynKeyword.panel + " " + SmoldynVCellMapper.SmoldynKeyword.tri);
                switch(dimension) {
                    case 1:
                        printWriter.print(" " + triangle.getNodes(0).getX());
                        break;
                    case 2:
                        printWriter.print(" " + triangle.getNodes(0).getX() + " " + triangle.getNodes(0).getY());
                        printWriter.print(" " + triangle.getNodes(1).getX() + " " + triangle.getNodes(1).getY());
                        break;
                    case 3:
                        for (Node node : triangle.getNodes()) {
                            printWriter.print(" " + node.getX() + " " + node.getY() + " " + node.getZ());
                        }
                        break;
                }
                printWriter.println(" " + trianglePanel.name);
            }
            for (TrianglePanel triPanel : triList) {
                neighborsForCurrentNode.clear();
                for (Node node : triPanel.triangle.getNodes()) {
                    if (node == null) {
                        continue;
                    }
                    neighborsForCurrentNode.addAll(nodeTriMap.get(node));
                }
                neighborsForCurrentNode.remove(triPanel.name);
                // printWriter.print(SmoldynKeyword.neighbors + " " +triPanel.name);
                // to allow smoldyn read line length as 256, chop the neighbors to multiple lines
                int maxNeighborCount = 4;
                // 
                int count = 0;
                for (String neigh : neighborsForCurrentNode) {
                    if (count % maxNeighborCount == 0) {
                        printWriter.println();
                        printWriter.print(SmoldynVCellMapper.SmoldynKeyword.neighbors + " " + triPanel.name);
                    }
                    printWriter.print(" " + neigh);
                    count++;
                }
            }
            printWriter.println();
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.end_surface);
            printWriter.println();
        }
    }
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) HashMap(java.util.HashMap) Node(cbit.vcell.geometry.surface.Node) ArrayList(java.util.ArrayList) Triangle(cbit.vcell.geometry.surface.Triangle) Surface(cbit.vcell.geometry.surface.Surface) GeometrySpec(cbit.vcell.geometry.GeometrySpec) SubVolume(cbit.vcell.geometry.SubVolume) TreeSet(java.util.TreeSet) Polygon(cbit.vcell.geometry.surface.Polygon) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) SurfaceCollection(cbit.vcell.geometry.surface.SurfaceCollection) Color(java.awt.Color) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) Vect3d(cbit.vcell.render.Vect3d) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SolverException(cbit.vcell.solver.SolverException)

Example 12 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class SmoldynSolver method initialize.

/**
 *  This method takes the place of the old runUnsteady()...
 */
protected void initialize() throws SolverException {
    if (lg.isTraceEnabled())
        lg.trace("SmoldynSolver.initialize()");
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
    writeFunctionsFile();
    // write subdomains file
    try {
        SubdomainInfo.write(new File(getBaseName() + SimDataConstants.SUBDOMAINS_FILE_SUFFIX), simTask.getSimulation().getMathDescription());
    } catch (IOException e1) {
        e1.printStackTrace();
        throw new SolverException(e1.getMessage());
    } catch (MathException e1) {
        e1.printStackTrace();
        throw new SolverException(e1.getMessage());
    }
    String inputFilename = getInputFilename();
    if (lg.isTraceEnabled())
        lg.trace("SmoldynSolver.initialize() baseName = " + getBaseName());
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INPUT_FILE);
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(inputFilename);
        if (SystemUtils.IS_OS_WINDOWS) {
            // 
            // the windows executable is compiled under cygwin (or mingw) and expect Unix style line termination characters.
            // so SmoldynInput file is written with platform default Java convention (different on windows) to a String.
            // Then the string is translated to Unix style before written to the file.
            // smoldyn is particularly sensitive to this issue, other compiled solvers are more tolerant.
            // 
            StringWriter stringWriter = new StringWriter();
            PrintWriter pw2 = new PrintWriter(stringWriter);
            SmoldynFileWriter stFileWriter = new SmoldynFileWriter(pw2, false, getBaseName(), simTask, bMessaging);
            stFileWriter.write();
            String fileContents = stringWriter.getBuffer().toString();
            fileContents = fileContents.replace("\r\n", "\n");
            pw.write(fileContents);
        } else {
            // 
            // for linux or macos, no translation is necessary.
            // 
            SmoldynFileWriter stFileWriter = new SmoldynFileWriter(pw, false, getBaseName(), simTask, bMessaging);
            stFileWriter.write();
        }
    } catch (Exception e) {
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not generate input file: " + e.getMessage())));
        e.printStackTrace(System.out);
        throw new SolverException(e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
    // get executable path+name.
    setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
// setMathExecutable(new cbit.vcell.solvers.MathExecutable(executableName + " gibson " + getBaseName() + ".stochInput" + " " + getBaseName() + ".stoch"));
}
Also used : StringWriter(java.io.StringWriter) MathException(cbit.vcell.math.MathException) IOException(java.io.IOException) SolverException(cbit.vcell.solver.SolverException) MathExecutable(cbit.vcell.solvers.MathExecutable) File(java.io.File) SolverStatus(cbit.vcell.solver.server.SolverStatus) IOException(java.io.IOException) SolverException(cbit.vcell.solver.SolverException) MathException(cbit.vcell.math.MathException) PrintWriter(java.io.PrintWriter)

Example 13 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class AbstractCompiledSolver method runSolver.

/**
 * Insert the method's description here.
 * Creation date: (6/26/2001 3:08:31 PM)
 */
public void runSolver() {
    try {
        setCurrentTime(simTask.getSimulationJob().getSimulation().getSolverTaskDescription().getTimeBounds().getStartingTime());
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_STARTING, SimulationMessage.MESSAGE_SOLVER_STARTING_INIT));
        // fireSolverStarting("initializing");
        // depends on solver; the initialize() method in actual solver will fire detailed messages
        initialize();
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
        fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING);
        if (OperatingSystemInfo.getInstance().isLinux()) {
            final String LD_LIB_PATH = "LD_LIBRARY_PATH";
            File solversDir = ResourceUtil.getLocalSolversDirectory();
            String existingLD_LIB_PATH = null;
            Map<String, String> envMap = System.getenv();
            Iterator<String> envIter = envMap.keySet().iterator();
            while (envIter.hasNext()) {
                String key = envIter.next();
                String val = envMap.get(key).toString();
                // System.out.println(key+"\n     "+val);
                if (key.equals(LD_LIB_PATH)) {
                    existingLD_LIB_PATH = val;
                    if (existingLD_LIB_PATH != null && existingLD_LIB_PATH.length() > 0 && !existingLD_LIB_PATH.endsWith(":")) {
                        existingLD_LIB_PATH += ":";
                    }
                    break;
                }
            }
            String newLD_LIB_PATH = (existingLD_LIB_PATH == null ? "" : existingLD_LIB_PATH) + solversDir.getAbsolutePath();
            System.out.println("-----Setting executable " + LD_LIB_PATH + " to " + newLD_LIB_PATH);
            getMathExecutable().addEnvironmentVariable(LD_LIB_PATH, newLD_LIB_PATH);
        }
        getMathExecutable().start();
        cleanup();
        // getMathExecutable().start() may end prematurely (error or user stop), so check status before firing...
        if (getMathExecutable().getStatus().equals(org.vcell.util.exe.ExecutableStatus.COMPLETE)) {
            setSolverStatus(new SolverStatus(SolverStatus.SOLVER_FINISHED, SimulationMessage.MESSAGE_SOLVER_FINISHED));
            fireSolverFinished();
        }
    } catch (SolverException integratorException) {
        lg.error(integratorException.getMessage(), integratorException);
        cleanup();
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted(integratorException.getMessage())));
        fireSolverAborted(SimulationMessage.solverAborted(integratorException.getMessage()));
    } catch (org.vcell.util.exe.ExecutableException executableException) {
        lg.error(executableException.getMessage(), executableException);
        cleanup();
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not execute code: " + executableException.getMessage())));
        fireSolverAborted(SimulationMessage.solverAborted(executableException.getMessage()));
    } catch (Exception exception) {
        if (lg.isWarnEnabled())
            lg.warn("AbstractODESolver.start() : Caught Throwable instead of SolverException -- THIS EXCEPTION SHOULD NOT HAPPEN!");
        lg.error(exception.getMessage(), exception);
        cleanup();
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted(exception.getMessage())));
        fireSolverAborted(SimulationMessage.solverAborted(exception.getMessage()));
    } finally {
        synchronized (this) {
            fieldThread = null;
        }
    }
}
Also used : SolverException(cbit.vcell.solver.SolverException) SolverStatus(cbit.vcell.solver.server.SolverStatus) File(java.io.File) SolverException(cbit.vcell.solver.SolverException)

Example 14 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class FVSolverStandalone method getResampledGeometry.

public Geometry getResampledGeometry() throws SolverException {
    if (resampledGeometry == null) {
        // clone and resample geometry
        try {
            resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simTask.getSimulation().getMathDescription().getGeometry());
            GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
            ISize newSize = simTask.getSimulation().getMeshSpecification().getSamplingSize();
            geoSurfaceDesc.setVolumeSampleSize(newSize);
            geoSurfaceDesc.updateAll();
        } catch (Exception e) {
            e.printStackTrace();
            throw new SolverException(e.getMessage());
        }
    }
    return resampledGeometry;
}
Also used : GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) SolverException(cbit.vcell.solver.SolverException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 15 with SolverException

use of cbit.vcell.solver.SolverException in project vcell by virtualcell.

the class FVSolverStandalone method writeVCGAndResampleFieldData.

protected void writeVCGAndResampleFieldData() throws SolverException {
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_PROC_GEOM);
    try {
        // write subdomains file
        SubdomainInfo.write(new File(getSaveDirectory(), baseName + SimDataConstants.SUBDOMAINS_FILE_SUFFIX), simTask.getSimulation().getMathDescription());
        PrintWriter pw = new PrintWriter(new FileWriter(new File(getSaveDirectory(), baseName + SimDataConstants.VCG_FILE_EXTENSION)));
        GeometryFileWriter.write(pw, getResampledGeometry());
        pw.close();
        FieldDataIdentifierSpec[] argFieldDataIDSpecs = simTask.getSimulationJob().getFieldDataIdentifierSpecs();
        if (argFieldDataIDSpecs != null && argFieldDataIDSpecs.length > 0) {
            fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_RESAMPLE_FD);
            FieldFunctionArguments psfFieldFunc = null;
            Variable var = simTask.getSimulationJob().getSimulationSymbolTable().getVariable(Simulation.PSF_FUNCTION_NAME);
            if (var != null) {
                FieldFunctionArguments[] ffas = FieldUtilities.getFieldFunctionArguments(var.getExpression());
                if (ffas == null || ffas.length == 0) {
                    throw new DataAccessException("Point Spread Function " + Simulation.PSF_FUNCTION_NAME + " can only be a single field function.");
                } else {
                    Expression newexp;
                    try {
                        newexp = new Expression(ffas[0].infix());
                        if (!var.getExpression().compareEqual(newexp)) {
                            throw new DataAccessException("Point Spread Function " + Simulation.PSF_FUNCTION_NAME + " can only be a single field function.");
                        }
                        psfFieldFunc = ffas[0];
                    } catch (ExpressionException e) {
                        e.printStackTrace();
                        throw new DataAccessException(e.getMessage());
                    }
                }
            }
            boolean[] bResample = new boolean[argFieldDataIDSpecs.length];
            Arrays.fill(bResample, true);
            for (int i = 0; i < argFieldDataIDSpecs.length; i++) {
                argFieldDataIDSpecs[i].getFieldFuncArgs().getTime().bindExpression(simTask.getSimulationJob().getSimulationSymbolTable());
                if (argFieldDataIDSpecs[i].getFieldFuncArgs().equals(psfFieldFunc)) {
                    bResample[i] = false;
                }
            }
            int numMembraneElements = getResampledGeometry().getGeometrySurfaceDescription().getSurfaceCollection().getTotalPolygonCount();
            CartesianMesh simpleMesh = CartesianMesh.createSimpleCartesianMesh(getResampledGeometry().getOrigin(), getResampledGeometry().getExtent(), simTask.getSimulation().getMeshSpecification().getSamplingSize(), getResampledGeometry().getGeometrySurfaceDescription().getRegionImage());
            String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
            DataSetControllerImpl dsci = new DataSetControllerImpl(null, getSaveDirectory().getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
            dsci.writeFieldFunctionData(null, argFieldDataIDSpecs, bResample, simpleMesh, simResampleInfoProvider, numMembraneElements, HESM_OVERWRITE_AND_CONTINUE);
        }
    } catch (Exception e) {
        throw new SolverException(e.getMessage());
    }
}
Also used : Variable(cbit.vcell.math.Variable) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) FileWriter(java.io.FileWriter) ExpressionException(cbit.vcell.parser.ExpressionException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) Expression(cbit.vcell.parser.Expression) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException) PrintWriter(java.io.PrintWriter)

Aggregations

SolverException (cbit.vcell.solver.SolverException)53 ExpressionException (cbit.vcell.parser.ExpressionException)28 IOException (java.io.IOException)23 MathException (cbit.vcell.math.MathException)20 PrintWriter (java.io.PrintWriter)16 File (java.io.File)15 Element (org.jdom.Element)13 SolverStatus (cbit.vcell.solver.server.SolverStatus)10 DataAccessException (org.vcell.util.DataAccessException)9 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)8 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)8 Variable (cbit.vcell.math.Variable)8 FileNotFoundException (java.io.FileNotFoundException)8 ISize (org.vcell.util.ISize)8 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)7 ImageException (cbit.image.ImageException)6 GeometryException (cbit.vcell.geometry.GeometryException)6 Expression (cbit.vcell.parser.Expression)5 SubVolume (cbit.vcell.geometry.SubVolume)4 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)4