Search in sources :

Example 26 with SolverException

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

the class MovingBoundarySolver method initialize.

/**
 * This method was created by a SmartGuide.
 */
protected void initialize() throws SolverException {
    writeFunctionsFile();
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INIT));
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
    setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
    try (PrintWriter pw = new PrintWriter(inputFilename)) {
        MovingBoundaryFileWriter mbfw = new MovingBoundaryFileWriter(pw, simTask, resampledGeometry, bMessaging, getBaseName());
        mbfw.write();
    } catch (Exception e) {
        throw new SolverException("Can't open input file " + inputFilename, e);
    }
    setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
}
Also used : SolverException(cbit.vcell.solver.SolverException) SolverStatus(cbit.vcell.solver.server.SolverStatus) IOException(java.io.IOException) SolverException(cbit.vcell.solver.SolverException) PrintWriter(java.io.PrintWriter)

Example 27 with SolverException

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

the class MovingBoundarySolver method getResampledGeometry.

/*
@Override
protected String[] getMathExecutableCommand() {
	String exeSuffix = System.getProperty(PropertyLoader.exesuffixProperty); // ".exe";
	String baseName = "MovingBoundary" ;
	File exeFile = new File(getSaveDirectory(), baseName + exeSuffix);
	return new String[] { exeFile.getAbsolutePath() };
}
*/
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) IOException(java.io.IOException) SolverException(cbit.vcell.solver.SolverException)

Example 28 with SolverException

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

the class GibsonSolver method initialize.

/**
 *  This method takes the place of the old runUnsteady()...
 */
protected void initialize() throws SolverException {
    if (lg.isTraceEnabled())
        lg.trace("StochSolver.initialize()");
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
    writeFunctionsFile();
    writeLogFile();
    String inputFilename = getInputFilename();
    if (lg.isTraceEnabled())
        lg.trace("StochSolver.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);
        StochFileWriter stFileWriter = new StochFileWriter(pw, 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("solver input file exception: " + 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 : SolverException(cbit.vcell.solver.SolverException) MathExecutable(cbit.vcell.solvers.MathExecutable) SolverStatus(cbit.vcell.solver.server.SolverStatus) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) FileNotFoundException(java.io.FileNotFoundException) SolverException(cbit.vcell.solver.SolverException) MathException(cbit.vcell.math.MathException) PrintWriter(java.io.PrintWriter)

Example 29 with SolverException

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

the class HybridSolver method writeLogFile.

private void writeLogFile() throws SolverException {
    String logFile = getBaseName() + LOGFILE_EXTENSION;
    String netCDFFileName = new File(getBaseName() + NETCDF_DATA_EXTENSION).getName();
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(logFile);
        pw.println(NETCDF_DATA_IDENTIFIER);
        pw.println(NETCDF_DATA_FORMAT_ID);
        pw.println(netCDFFileName);
        pw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new SolverException(e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 30 with SolverException

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

the class FVSolverStandalone method initialize.

// 
// 
// /**
// * Insert the method's description here.
// * Creation date: (6/27/2001 2:33:03 PM)
// */
// public void propertyChange(java.beans.PropertyChangeEvent event) {
// super.propertyChange(event);
// 
// if (event.getSource() == getMathExecutable() && event.getPropertyName().equals("applicationMessage")) {
// String messageString = (String)event.getNewValue();
// if (messageString==null || messageString.length()==0){
// return;
// }
// ApplicationMessage appMessage = getApplicationMessage(messageString);
// if (appMessage!=null && appMessage.getMessageType() == ApplicationMessage.DATA_MESSAGE) {
// fireSolverPrinted(appMessage.getTimepoint());
// }
// }
// }
/**
 * This method was created by a SmartGuide.
 */
protected void initialize() throws SolverException {
    try {
        Simulation sim = simTask.getSimulation();
        if (sim.isSerialParameterScan()) {
            // write functions file for all the simulations in the scan
            for (int scan = 0; scan < sim.getScanCount(); scan++) {
                SimulationJob simJob = new SimulationJob(sim, scan, simTask.getSimulationJob().getFieldDataIdentifierSpecs());
                // ** Dumping the functions of a simulation into a '.functions' file.
                String basename = new File(getSaveDirectory(), simJob.getSimulationJobID()).getPath();
                String functionFileName = basename + FUNCTIONFILE_EXTENSION;
                Vector<AnnotatedFunction> funcList = simJob.getSimulationSymbolTable().createAnnotatedFunctionsList(simTask.getSimulation().getMathDescription());
                // Try to save existing user defined functions
                try {
                    File existingFunctionFile = new File(functionFileName);
                    if (existingFunctionFile.exists()) {
                        Vector<AnnotatedFunction> oldFuncList = FunctionFileGenerator.readFunctionsFile(existingFunctionFile, simTask.getSimulationJobID());
                        for (AnnotatedFunction func : oldFuncList) {
                            if (func.isOldUserDefined()) {
                                funcList.add(func);
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                // ignore
                }
                // Try to save existing user defined functions
                FunctionFileGenerator functionFileGenerator = new FunctionFileGenerator(functionFileName, funcList);
                try {
                    functionFileGenerator.generateFunctionFile();
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    throw new RuntimeException("Error creating .function file for " + functionFileGenerator.getBasefileName() + e.getMessage());
                }
            }
        } else {
            writeFunctionsFile();
        }
        // not for Chombo solver
        if (!isChombo) {
            writeVCGAndResampleFieldData();
        }
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INIT));
        fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
        setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
        File fvinputFile = new File(getInputFilename());
        PrintWriter pw = null;
        try {
            pw = new PrintWriter(new FileWriter(fvinputFile));
            new FiniteVolumeFileWriter(pw, simTask, getResampledGeometry(), getSaveDirectory(), destinationDirectory, bMessaging).write();
        } finally {
            if (pw != null) {
                pw.close();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        throw new SolverException(ex.getMessage());
    }
}
Also used : FileWriter(java.io.FileWriter) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) Simulation(cbit.vcell.solver.Simulation) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) 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