Search in sources :

Example 1 with ErrorTolerance

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

the class XmlReader method getErrorTolerance.

/**
 * This method returns a ErrorTolerance object from a XML Element.
 * Creation date: (5/22/2001 11:50:07 AM)
 * @return cbit.vcell.solver.ErrorTolerance
 * @param param org.jdom.Element
 */
private ErrorTolerance getErrorTolerance(Element param) {
    // getAttributes
    double absolut = Double.parseDouble(param.getAttributeValue(XMLTags.AbsolutErrorToleranceTag));
    double relative = Double.parseDouble(param.getAttributeValue(XMLTags.RelativeErrorToleranceTag));
    // *** create new ErrorTolerance object ****
    ErrorTolerance errorTol = new ErrorTolerance(absolut, relative);
    return errorTol;
}
Also used : ErrorTolerance(cbit.vcell.solver.ErrorTolerance)

Example 2 with ErrorTolerance

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

the class Xmlproducer method getXML.

/**
 * This method returns a XML representation of a SolverTaskDescription object.
 * Creation date: (3/2/2001 10:59:55 PM)
 * @return Element
 * @param param cbit.vcell.solver.SolverTaskDescription
 */
private Element getXML(SolverTaskDescription param) {
    Element solvertask = new Element(XMLTags.SolverTaskDescriptionTag);
    // Add Attributes
    if (param.getTaskType() == SolverTaskDescription.TASK_UNSTEADY) {
        solvertask.setAttribute(XMLTags.TaskTypeTag, XMLTags.UnsteadyTag);
    } else if (param.getTaskType() == SolverTaskDescription.TASK_STEADY) {
        solvertask.setAttribute(XMLTags.TaskTypeTag, XMLTags.SteadyTag);
    } else {
        throw new IllegalArgumentException("Unexpected task type:" + param.getTaskType());
    }
    // solvertask.setAttribute(XMLTags.KeepEveryTag, String.valueOf(param.getKeepEvery()));
    // solvertask.setAttribute(XMLTags.KeepAtMostTag, String.valueOf(param.getKeepAtMost()));
    solvertask.setAttribute(XMLTags.UseSymbolicJacobianAttrTag, String.valueOf(param.getUseSymbolicJacobian()));
    // Add timeBounds
    solvertask.addContent(getXML(param.getTimeBounds()));
    // Add timeStep
    solvertask.addContent(getXML(param.getTimeStep()));
    // Add ErrorTolerence
    solvertask.addContent(getXML(param.getErrorTolerance()));
    // Jan 8, 2016 (jim) let getXML(stochOpt) write out the correct stochastic options
    if (param.getStochOpt() != null) {
        solvertask.addContent(getXML(param.getStochOpt(), param.getStochHybridOpt()));
    }
    // Add OutputOptions
    solvertask.addContent(getXML(param.getOutputTimeSpec()));
    // Add sensitivityParameter
    if (param.getSensitivityParameter() != null) {
        solvertask.addContent(getXML(param.getSensitivityParameter()));
    }
    // Add solver name
    solvertask.setAttribute(XMLTags.SolverNameTag, param.getSolverDescription().getDatabaseName());
    // Stop At Spatially Uniform
    ErrorTolerance stopAtSpatiallyUniformErrorTolerance = param.getStopAtSpatiallyUniformErrorTolerance();
    if (stopAtSpatiallyUniformErrorTolerance != null) {
        Element element = new Element(XMLTags.StopAtSpatiallyUniform);
        element.addContent(getXML(stopAtSpatiallyUniformErrorTolerance));
        solvertask.addContent(element);
    }
    boolean bRunParameterScanSerially = param.isSerialParameterScan();
    if (bRunParameterScanSerially) {
        solvertask.setAttribute(XMLTags.RunParameterScanSerially, String.valueOf(bRunParameterScanSerially));
    }
    SmoldynSimulationOptions smoldynSimulationOptions = param.getSmoldynSimulationOptions();
    if (smoldynSimulationOptions != null) {
        solvertask.addContent(getXML(smoldynSimulationOptions));
    }
    NFsimSimulationOptions nfsimSimulationOptions = param.getNFSimSimulationOptions();
    if (nfsimSimulationOptions != null) {
        solvertask.addContent(getXML(nfsimSimulationOptions));
    }
    SundialsPdeSolverOptions sundialsPdeSolverOptions = param.getSundialsPdeSolverOptions();
    if (sundialsPdeSolverOptions != null) {
        solvertask.addContent(getXML(sundialsPdeSolverOptions));
    }
    ChomboSolverSpec chomboSolverSpec = param.getChomboSolverSpec();
    if (chomboSolverSpec != null) {
        Element chomboElement = getXML(chomboSolverSpec);
        solvertask.addContent(chomboElement);
    }
    MovingBoundarySolverOptions mb = param.getMovingBoundarySolverOptions();
    if (mb != null) {
        Element e = getXML(mb);
        solvertask.addContent(e);
    }
    Element numProcessors = new Element(XMLTags.NUM_PROCESSORS);
    numProcessors.setText(Integer.toString(param.getNumProcessors()));
    solvertask.addContent(numProcessors);
    return solvertask;
}
Also used : SmoldynSimulationOptions(cbit.vcell.solver.SmoldynSimulationOptions) NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) MovingBoundarySolverOptions(cbit.vcell.solvers.mb.MovingBoundarySolverOptions) SundialsPdeSolverOptions(cbit.vcell.solver.SundialsPdeSolverOptions) Element(org.jdom.Element) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) ChomboSolverSpec(org.vcell.chombo.ChomboSolverSpec)

Example 3 with ErrorTolerance

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

the class FRAPStudy method runFVSolverStandalone.

public static void runFVSolverStandalone(File simulationDataDir, Simulation sim, ExternalDataIdentifier imageDataExtDataID, ExternalDataIdentifier roiExtDataID, ClientTaskStatusSupport progressListener, boolean bCheckSteadyState) throws Exception {
    FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
    FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
    for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
        if (fieldFunctionArgs[i].getFieldName().equals(imageDataExtDataID.getName())) {
            fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], imageDataExtDataID);
        } else if (fieldFunctionArgs[i].getFieldName().equals(roiExtDataID.getName())) {
            fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], roiExtDataID);
        } else {
            throw new RuntimeException("failed to resolve field named " + fieldFunctionArgs[i].getFieldName());
        }
    }
    int jobIndex = 0;
    SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs), 0);
    // if we need to check steady state, do the following two lines
    if (bCheckSteadyState) {
        simTask.getSimulation().getSolverTaskDescription().setStopAtSpatiallyUniformErrorTolerance(ErrorTolerance.getDefaultSpatiallyUniformErrorTolerance());
        simTask.getSimulation().getSolverTaskDescription().setErrorTolerance(new ErrorTolerance(1e-6, 1e-2));
    }
    SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
    FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simulationDataDir, false);
    fvSolver.startSolver();
    SolverStatus status = fvSolver.getSolverStatus();
    while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
        if (progressListener != null) {
            progressListener.setProgress((int) (fvSolver.getProgress() * 100));
            if (progressListener.isInterrupted()) {
                fvSolver.stopSolver();
                throw UserCancelException.CANCEL_GENERIC;
            }
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace(System.out);
        // catch interrupted exception and ignore it, otherwise it will popup a dialog in user interface saying"sleep interrupted"
        }
        status = fvSolver.getSolverStatus();
    }
    if (status.getStatus() == SolverStatus.SOLVER_FINISHED) {
        String roiMeshFileName = SimulationData.createCanonicalMeshFileName(roiExtDataID.getKey(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, false);
        String imageDataMeshFileName = SimulationData.createCanonicalMeshFileName(imageDataExtDataID.getKey(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, false);
        String simulationMeshFileName = SimulationData.createCanonicalMeshFileName(sim.getVersion().getVersionKey(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, false);
        // delete old external data mesh files and copy simulation mesh file to them
        File roiMeshFile = new File(simulationDataDir, roiMeshFileName);
        File imgMeshFile = new File(simulationDataDir, imageDataMeshFileName);
        File simMeshFile = new File(simulationDataDir, simulationMeshFileName);
        if (!roiMeshFile.delete()) {
            throw new Exception("Couldn't delete ROI Mesh file " + roiMeshFile.getAbsolutePath());
        }
        if (!imgMeshFile.delete()) {
            throw new Exception("Couldn't delete ImageData Mesh file " + imgMeshFile.getAbsolutePath());
        }
        FileUtils.copyFile(simMeshFile, roiMeshFile);
        FileUtils.copyFile(simMeshFile, imgMeshFile);
    } else {
        throw new Exception("Sover did not finish normally." + status.toString());
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) FVSolverStandalone(cbit.vcell.solvers.FVSolverStandalone) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) SolverStatus(cbit.vcell.solver.server.SolverStatus) File(java.io.File) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 4 with ErrorTolerance

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

the class ErrorTolerancePanel method setNewErrorTolerance.

public void setNewErrorTolerance() {
    try {
        double absError = getAbsoluteErrorToleranceTextField().isEnabled() ? new Double(getAbsoluteErrorToleranceTextField().getText()).doubleValue() : 1e-9;
        double relError = getRelativeErrorToleranceTextField().isEnabled() ? new Double(getRelativeErrorToleranceTextField().getText()).doubleValue() : 1e-9;
        ErrorTolerance newErrTol = new ErrorTolerance(absError, relError);
        solverTaskDescription.setErrorTolerance(newErrTol);
    } catch (java.lang.Throwable ivjExc) {
        // user code begin {3}
        // user code end
        handleException(ivjExc);
    }
}
Also used : ErrorTolerance(cbit.vcell.solver.ErrorTolerance)

Example 5 with ErrorTolerance

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

the class ErrorTolerancePanel method refresh.

public void refresh() {
    if (solverTaskDescription == null) {
        return;
    }
    getErrorTolerancesLabel().setText("Error Tolerance");
    if (solverTaskDescription.getSolverDescription().isSemiImplicitPdeSolver() || solverTaskDescription.getSolverDescription().isChomboSolver()) {
        getAbsoluteErrorToleranceLabel().setEnabled(false);
        getAbsoluteErrorToleranceTextField().setEnabled(false);
        getAbsoluteErrorToleranceTextField().setText(null);
        getErrorTolerancesLabel().setText("Linear Solver Tolerance");
        getRelativeErrorToleranceTextField().setEnabled(true);
        ErrorTolerance errTol = solverTaskDescription.getErrorTolerance();
        getRelativeErrorToleranceTextField().setText(errTol.getRelativeErrorTolerance() + "");
    } else if (solverTaskDescription.getSolverDescription().hasErrorTolerance()) {
        setEnabled(true);
        ErrorTolerance errTol = solverTaskDescription.getErrorTolerance();
        getAbsoluteErrorToleranceTextField().setText(errTol.getAbsoluteErrorTolerance() + "");
        getRelativeErrorToleranceTextField().setText(errTol.getRelativeErrorTolerance() + "");
    } else {
        getAbsoluteErrorToleranceTextField().setText("");
        getRelativeErrorToleranceTextField().setText("");
        setEnabled(false);
    }
}
Also used : ErrorTolerance(cbit.vcell.solver.ErrorTolerance)

Aggregations

ErrorTolerance (cbit.vcell.solver.ErrorTolerance)14 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)7 Simulation (cbit.vcell.solver.Simulation)6 DefaultOutputTimeSpec (cbit.vcell.solver.DefaultOutputTimeSpec)5 File (java.io.File)5 MathDescription (cbit.vcell.math.MathDescription)4 SimulationJob (cbit.vcell.solver.SimulationJob)4 SolverTaskDescription (cbit.vcell.solver.SolverTaskDescription)4 VCLogger (cbit.util.xml.VCLogger)3 BioModel (cbit.vcell.biomodel.BioModel)3 SimulationContext (cbit.vcell.mapping.SimulationContext)3 SimulationTask (cbit.vcell.messaging.server.SimulationTask)3 OutputTimeSpec (cbit.vcell.solver.OutputTimeSpec)3 TimeBounds (cbit.vcell.solver.TimeBounds)3 TimeStep (cbit.vcell.solver.TimeStep)3 XMLSource (cbit.vcell.xml.XMLSource)3 IOException (java.io.IOException)3 KeyValue (org.vcell.util.document.KeyValue)3 MathMapping (cbit.vcell.mapping.MathMapping)2 Constant (cbit.vcell.math.Constant)2