Search in sources :

Example 6 with DefaultOutputTimeSpec

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

the class SimulationSummaryPanel method displayTask.

/**
 * Comment
 */
private void displayTask() {
    SolverTaskDescription solverTaskDescription = getSimulation().getSolverTaskDescription();
    try {
        NonspatialStochSimOptions stochOpt = solverTaskDescription.getStochOpt();
        if (stochOpt != null && stochOpt.getNumOfTrials() > 1) {
            getJLabelOutput().setText("Histogram with " + stochOpt.getNumOfTrials() + " Trials(@last time point)");
        } else {
            // gcwtodo
            String text = solverTaskDescription.getOutputTimeSpec().getShortDescription();
            if (solverTaskDescription.getSolverDescription().isChomboSolver()) {
                text = "Variable";
                if (solverTaskDescription.getChomboSolverSpec().getTimeIntervalList().size() == 1) {
                    text = "Every " + solverTaskDescription.getChomboSolverSpec().getLastTimeInterval().getOutputTimeStep() + "s";
                }
            } else if (solverTaskDescription.getOutputTimeSpec().isDefault() && !solverTaskDescription.getSolverDescription().isSemiImplicitPdeSolver() && !solverTaskDescription.getSolverDescription().equals(SolverDescription.StochGibson)) {
                text += ", at most " + ((DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec()).getKeepAtMost();
            }
            getJLabelOutput().setText(text);
        }
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        getJLabelOutput().setText("");
    }
    SolverDescription solverDescription = solverTaskDescription.getSolverDescription();
    try {
        ErrorTolerance errorTolerance = solverTaskDescription.getErrorTolerance();
        TimeStep timeStep = solverTaskDescription.getTimeStep();
        getJLabelRelTol().setText("Rel tol");
        getJLabelAbsTol().setText("Abs tol");
        getJLabel12().setText("Timestep");
        getJLabelRelTol().setEnabled(false);
        getJLabelAbsTol().setEnabled(false);
        getJLabel12().setEnabled(false);
        getJLabel10().setText("Sensitivity Analysis");
        getJLabel10().setEnabled(true);
        if (solverDescription.equals(SolverDescription.StochGibson)) {
            getJLabel12().setEnabled(false);
            getJLabelTimestep().setText("");
        } else if (solverDescription.equals(SolverDescription.NFSim)) {
            TimeBounds tb = solverTaskDescription.getTimeBounds();
            double dtime = tb.getEndingTime() - tb.getStartingTime();
            if (solverTaskDescription.getOutputTimeSpec() instanceof UniformOutputTimeSpec) {
                UniformOutputTimeSpec uots = (UniformOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
                double interval = uots.getOutputTimeStep();
                int steps = (int) Math.round(dtime / interval);
                getJLabel12().setEnabled(true);
                getJLabel12().setText("Timepoints");
                getJLabelTimestep().setText(steps + "");
            } else if (solverTaskDescription.getOutputTimeSpec() instanceof DefaultOutputTimeSpec) {
                DefaultOutputTimeSpec uots = (DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
                getJLabel12().setEnabled(true);
                getJLabel12().setText("End Time");
                getJLabelTimestep().setText(solverTaskDescription.getTimeBounds().getEndingTime() + "");
            } else {
                getJLabel12().setEnabled(false);
                getJLabel12().setText("End Time");
                getJLabelTimestep().setText("na");
            }
            NFsimSimulationOptions nfsso = solverTaskDescription.getNFSimSimulationOptions();
            String utl = "default";
            Integer moleculeDistance = nfsso.getMoleculeDistance();
            if (moleculeDistance != null) {
                utl = moleculeDistance + "";
            }
            getJLabelRelTol().setEnabled(true);
            getJLabelRelTol().setText("Universal Transversal Limit");
            getJLabelRelTolValue().setText(utl);
            String gml = "default";
            Integer maxMoleculesPerType = nfsso.getMaxMoleculesPerType();
            if (maxMoleculesPerType != null) {
                gml = maxMoleculesPerType + "";
            }
            getJLabelAbsTol().setEnabled(true);
            getJLabelAbsTol().setText("Max # of each " + MolecularType.typeName);
            getJLabelAbsTolValue().setText(gml);
        } else if (solverDescription.isNonSpatialStochasticSolver()) {
            getJLabel12().setEnabled(true);
            getJLabel12().setText("Timestep");
            getJLabelTimestep().setText(timeStep.getDefaultTimeStep() + "s");
        } else if (solverDescription.hasVariableTimestep()) {
            getJLabel12().setEnabled(true);
            getJLabel12().setText("Max timestep");
            getJLabelTimestep().setText(timeStep.getMaximumTimeStep() + "s");
            getJLabelRelTol().setEnabled(true);
            getJLabelRelTolValue().setText("" + errorTolerance.getRelativeErrorTolerance());
            getJLabelAbsTol().setEnabled(true);
            getJLabelAbsTolValue().setText("" + errorTolerance.getAbsoluteErrorTolerance());
        } else {
            getJLabel12().setEnabled(true);
            getJLabel12().setText("Timestep");
            if (solverDescription.isChomboSolver()) {
                String text = "Variable";
                if (solverTaskDescription.getChomboSolverSpec().getTimeIntervalList().size() == 1) {
                    text = solverTaskDescription.getChomboSolverSpec().getLastTimeInterval().getTimeStep() + "s";
                }
                getJLabelTimestep().setText(text);
            } else {
                getJLabelTimestep().setText(timeStep.getDefaultTimeStep() + "s");
            }
            if (solverDescription.isSemiImplicitPdeSolver()) {
                getJLabelRelTol().setEnabled(true);
                getJLabelRelTolValue().setText("" + errorTolerance.getRelativeErrorTolerance());
            } else {
                getJLabelRelTol().setEnabled(false);
                getJLabelRelTolValue().setText("");
            }
            getJLabelAbsTol().setEnabled(false);
            getJLabelAbsTolValue().setText("");
        }
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        getJLabelTimestep().setText("");
        getJLabelRelTolValue().setText("");
        getJLabelAbsTolValue().setText("");
    }
    try {
        boolean bChomboSolver = solverDescription.isChomboSolver();
        getJLabelTitleNumProcessors().setVisible(bChomboSolver);
        getJLabelNumProcessors().setVisible(bChomboSolver);
        if (bChomboSolver) {
            getJLabelNumProcessors().setText(String.valueOf(solverTaskDescription.getNumProcessors()));
        }
        if (getSimulation().isSpatial() || solverDescription.isNonSpatialStochasticSolver()) {
            getJLabelSensitivity().setVisible(false);
            getJLabel10().setVisible(false);
        } else if (solverDescription.equals(SolverDescription.NFSim)) {
            getJLabel10().setText("On-the-fly observ comp.");
            NFsimSimulationOptions nfsso = solverTaskDescription.getNFSimSimulationOptions();
            boolean goc = nfsso.getObservableComputationOff();
            getJLabelSensitivity().setText(goc + "");
        } else {
            getJLabelSensitivity().setVisible(true);
            getJLabel10().setVisible(true);
            Constant param = solverTaskDescription.getSensitivityParameter();
            if (param == null) {
                getJLabelSensitivity().setText("no");
            } else {
                getJLabelSensitivity().setText(param.getName());
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        getJLabelSensitivity().setText("");
    }
    if (solverDescription.isNonSpatialStochasticSolver()) {
        getJLabelRelTol().setVisible(false);
        getJLabelAbsTol().setVisible(false);
        getJLabelRelTolValue().setVisible(false);
        getJLabelAbsTolValue().setVisible(false);
    } else {
        getJLabelRelTol().setVisible(true);
        getJLabelAbsTol().setVisible(true);
    }
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) SolverDescription(cbit.vcell.solver.SolverDescription) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Constant(cbit.vcell.math.Constant) NonspatialStochSimOptions(cbit.vcell.solver.NonspatialStochSimOptions) PropertyVetoException(java.beans.PropertyVetoException) TimeStep(cbit.vcell.solver.TimeStep) TimeBounds(cbit.vcell.solver.TimeBounds) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 7 with DefaultOutputTimeSpec

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

the class FiniteVolumeFileWriter method writeSimulationParamters.

/**
 * @param timeFunction
 * @param startTime
 * @param endTime
 * @param rootFinder
 * @param uniqueRootTimes
 * @param bPrintIterations
 * @throws ExpressionException
 *
 * for testing within scrapbook, see below:
 *
 * try {
 *	edu.northwestern.at.utils.math.rootfinders.MonadicFunctionRootFinder rootFinder =
 *//			new edu.northwestern.at.utils.math.rootfinders.Brent();
 *			new edu.northwestern.at.utils.math.rootfinders.Bisection();
 *//			new edu.northwestern.at.utils.math.rootfinders.NewtonRaphson();
 *//			new edu.northwestern.at.utils.math.rootfinders.Secant();
 *	cbit.vcell.parser.SimpleSymbolTable simpleSymbolTable = new cbit.vcell.parser.SimpleSymbolTable(new String[] { "t" });
 *
 *	cbit.vcell.parser.Expression exp = new cbit.vcell.parser.Expression("t-0.56");
 *
 *	exp.bindExpression(simpleSymbolTable);
 *	java.util.TreeSet<Double> rootTimes = new java.util.TreeSet<Double>();
 *	double startTime = 0.0;
 *	double endTime = 100.0;
 *	System.out.print("exp = '"+ exp.infix() + "'");
 *	long currentTimeMS = System.currentTimeMillis();
 *	cbit.vcell.solvers.FiniteVolumeFileWriter.findAllRoots(exp,startTime,endTime,rootFinder,rootTimes,false);
 *	long finalTimeMS = System.currentTimeMillis();
 *	for (double root : rootTimes){
 *		System.out.println("root = "+root);
 *	}
 *	System.out.println("elapsedTime of computation = "+(finalTimeMS-currentTimeMS)+" ms, found " + rootTimes.size() + " roots (not unique)");
 *
 *}catch (Exception e){
 *	e.printStackTrace(System.out);
 *}
 */
/*public static void findAllRoots(Expression timeFunction, double startTime, double endTime, MonadicFunctionRootFinder rootFinder, TreeSet<Double> uniqueRootTimes, boolean bPrintIterations) throws ExpressionException{
	TreeSet<Double> allRootTimes = new TreeSet<Double>();
	final Expression function_exp = new Expression(timeFunction);
	MonadicFunction valueFunction = new MonadicFunction() {
		double[] values = new double[1];
		public double f(double t) {
			values[0] = t;
			try {
				return function_exp.evaluateVector(values);
			} catch (ExpressionException e) {
				e.printStackTrace();
				throw new RuntimeException("expression exception "+e.getMessage());
			}
		}
	};
	
	final Expression derivative_exp = new Expression(timeFunction.differentiate(ReservedVariable.TIME.getName()));
	MonadicFunction derivativeFunction = new MonadicFunction() {
		double[] values = new double[1];
		public double f(double t) {
			values[0] = t;
			try {
				return derivative_exp.evaluateVector(values);
			} catch (ExpressionException e) {
				e.printStackTrace();
				throw new RuntimeException("expression exception "+e.getMessage());
			}
		}
	};
	
	RootFinderConvergenceTest convergenceTest = new StandardRootFinderConvergenceTest();
	RootFinderIterationInformation iterationInformation = null;
	if (bPrintIterations){
		iterationInformation = new RootFinderIterationInformation() {				
			public void iterationInformation(double x, double fx, double dfx, int currentIteration) {
				System.out.println(currentIteration+") x="+x+", fx="+fx+", dfx="+dfx);
			}
		};
	}
	int NUM_BRACKETS = 1000;
	double simulationTime = endTime - startTime;
	double tolerance = simulationTime/1e10;
	int maxIter = 1000;
	
	for (int i=0;i<NUM_BRACKETS-1;i++){
		double bracketMin = startTime + simulationTime*i/NUM_BRACKETS;
		double bracketMax = startTime + simulationTime*(i+1)/NUM_BRACKETS;
	
		double root = rootFinder.findRoot(bracketMin, bracketMax, tolerance, maxIter, valueFunction, derivativeFunction, convergenceTest, iterationInformation);
		if (root>startTime && root<endTime && valueFunction.f(root)<=tolerance){
			allRootTimes.add(root);
		}
	}
	double uniqueTolerance = tolerance * 100;
	double lastUniqueRoot = Double.NEGATIVE_INFINITY;
	for (double root : allRootTimes){
		if (root-lastUniqueRoot > uniqueTolerance){
			uniqueRootTimes.add(root);
		}
		lastUniqueRoot = root;
	}

}  ---------------------------------JIM's CODE COMMENTTED FOR FUTURE DEVELOPMENT*/
/**
 *# Simulation Parameters
 *SIMULATION_PARAM_BEGIN
 *SOLVER SUNDIALS_PDE_SOLVER 1.0E-7 1.0E-9
 *DISCONTINUITY_TIMES 2 1.0E-4 3.0000000000000003E-4
 *BASE_FILE_NAME c:/Vcell/users/fgao/SimID_31746636_0_
 *ENDING_TIME 4.0E-4
 *KEEP_EVERY ONE_STEP 3
 *KEEP_AT_MOST 1000
 *SIMULATION_PARAM_END
 * @throws MathException
 * @throws ExpressionException
 */
private void writeSimulationParamters() throws ExpressionException, MathException {
    Simulation simulation = simTask.getSimulation();
    SolverTaskDescription solverTaskDesc = simulation.getSolverTaskDescription();
    printWriter.println("# Simulation Parameters");
    printWriter.println(FVInputFileKeyword.SIMULATION_PARAM_BEGIN);
    if (solverTaskDesc.getSolverDescription().equals(SolverDescription.SundialsPDE)) {
        printWriter.print(FVInputFileKeyword.SOLVER + " " + FVInputFileKeyword.SUNDIALS_PDE_SOLVER + " " + solverTaskDesc.getErrorTolerance().getRelativeErrorTolerance() + " " + solverTaskDesc.getErrorTolerance().getAbsoluteErrorTolerance() + " " + solverTaskDesc.getTimeStep().getMaximumTimeStep());
        if (simulation.getMathDescription().hasVelocity()) {
            printWriter.print(" " + solverTaskDesc.getSundialsPdeSolverOptions().getMaxOrderAdvection());
        }
        printWriter.println();
        Vector<Discontinuity> discontinuities = new Vector<Discontinuity>();
        TreeSet<Double> discontinuityTimes = new TreeSet<Double>();
        MathDescription mathDesc = simulation.getMathDescription();
        Enumeration<SubDomain> enum1 = mathDesc.getSubDomains();
        while (enum1.hasMoreElements()) {
            SubDomain sd = enum1.nextElement();
            Enumeration<Equation> enum_equ = sd.getEquations();
            while (enum_equ.hasMoreElements()) {
                Equation equation = enum_equ.nextElement();
                equation.getDiscontinuities(simTask.getSimulationJob().getSimulationSymbolTable(), discontinuities);
            }
        }
        getDiscontinuityTimes(discontinuities, discontinuityTimes);
        if (discontinuityTimes.size() > 0) {
            printWriter.print(FVInputFileKeyword.DISCONTINUITY_TIMES + " " + discontinuityTimes.size());
            for (double d : discontinuityTimes) {
                printWriter.print(" " + d);
            }
            printWriter.println();
        }
    } else if (solverTaskDesc.getSolverDescription().equals(SolverDescription.Chombo)) {
        printWriter.println(FVInputFileKeyword.SOLVER + " " + FVInputFileKeyword.CHOMBO_SEMIIMPLICIT_SOLVER);
    } else if (solverTaskDesc.getSolverDescription().equals(SolverDescription.VCellPetsc)) {
        printWriter.println(FVInputFileKeyword.SOLVER + " " + FVInputFileKeyword.VCELL_PETSC_SOLVER);
    } else {
        printWriter.println(FVInputFileKeyword.SOLVER + " " + FVInputFileKeyword.FV_SOLVER + " " + solverTaskDesc.getErrorTolerance().getRelativeErrorTolerance());
    }
    printWriter.println(FVInputFileKeyword.BASE_FILE_NAME + " " + new File(workingDirectory, simTask.getSimulationJob().getSimulationJobID()).getAbsolutePath());
    if (solverTaskDesc.isParallel() && destinationDirectory != null && !destinationDirectory.equals(workingDirectory)) {
        printWriter.println(FVInputFileKeyword.PRIMARY_DATA_DIR + " " + destinationDirectory.getAbsolutePath());
    }
    printWriter.println(FVInputFileKeyword.ENDING_TIME + " " + solverTaskDesc.getTimeBounds().getEndingTime());
    OutputTimeSpec outputTimeSpec = solverTaskDesc.getOutputTimeSpec();
    if (solverTaskDesc.getSolverDescription().isChomboSolver()) {
        List<TimeInterval> timeIntervalList = solverTaskDesc.getChomboSolverSpec().getTimeIntervalList();
        printWriter.println(FVInputFileKeyword.TIME_INTERVALS + " " + timeIntervalList.size());
        for (TimeInterval ti : timeIntervalList) {
            printWriter.println(ti.getEndingTime() + " " + ti.getTimeStep() + " " + ti.getKeepEvery());
        }
    } else if (solverTaskDesc.getSolverDescription().equals(SolverDescription.SundialsPDE)) {
        if (outputTimeSpec.isDefault()) {
            DefaultOutputTimeSpec defaultOutputTimeSpec = (DefaultOutputTimeSpec) outputTimeSpec;
            printWriter.println(FVInputFileKeyword.KEEP_EVERY + " " + FVInputFileKeyword.ONE_STEP + " " + defaultOutputTimeSpec.getKeepEvery());
            printWriter.println(FVInputFileKeyword.KEEP_AT_MOST + " " + defaultOutputTimeSpec.getKeepAtMost());
        } else {
            printWriter.println(FVInputFileKeyword.TIME_STEP + " " + ((UniformOutputTimeSpec) outputTimeSpec).getOutputTimeStep());
            printWriter.println(FVInputFileKeyword.KEEP_EVERY + " 1");
        }
    } else {
        double defaultTimeStep = solverTaskDesc.getTimeStep().getDefaultTimeStep();
        printWriter.println(FVInputFileKeyword.TIME_STEP + " " + defaultTimeStep);
        int keepEvery = 1;
        if (outputTimeSpec.isDefault()) {
            keepEvery = ((DefaultOutputTimeSpec) outputTimeSpec).getKeepEvery();
        } else if (outputTimeSpec.isUniform()) {
            UniformOutputTimeSpec uots = (UniformOutputTimeSpec) outputTimeSpec;
            double ots = uots.getOutputTimeStep();
            keepEvery = (int) Math.round(ots / defaultTimeStep);
        } else {
            throw new RuntimeException("unexpected OutputTime specification type :" + outputTimeSpec.getClass().getName());
        }
        if (keepEvery <= 0) {
            throw new RuntimeException("Output KeepEvery must be a positive integer. Try to change the output option.");
        }
        printWriter.println(FVInputFileKeyword.KEEP_EVERY + " " + keepEvery);
    }
    ErrorTolerance stopAtSpatiallyUniformErrorTolerance = solverTaskDesc.getStopAtSpatiallyUniformErrorTolerance();
    if (stopAtSpatiallyUniformErrorTolerance != null) {
        printWriter.println(FVInputFileKeyword.CHECK_SPATIALLY_UNIFORM + " " + stopAtSpatiallyUniformErrorTolerance.getAbsoluteErrorTolerance() + " " + stopAtSpatiallyUniformErrorTolerance.getRelativeErrorTolerance());
    }
    printWriter.println(FVInputFileKeyword.SIMULATION_PARAM_END);
    printWriter.println();
}
Also used : Discontinuity(cbit.vcell.parser.Discontinuity) TimeInterval(org.vcell.chombo.TimeInterval) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) MathDescription(cbit.vcell.math.MathDescription) MeasureEquation(cbit.vcell.math.MeasureEquation) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Simulation(cbit.vcell.solver.Simulation) TreeSet(java.util.TreeSet) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) Vector(java.util.Vector) File(java.io.File) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 8 with DefaultOutputTimeSpec

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

the class ITextWriter method writeSimulation.

// container can be a chapter or a section of a chapter.
protected void writeSimulation(Section container, Simulation sim) throws DocumentException {
    if (sim == null) {
        return;
    }
    Section simSection = container.addSection(sim.getName(), container.numberDepth() + 1);
    writeMetadata(simSection, sim.getName(), sim.getDescription(), null, "Simulation ");
    // add overriden params
    Table overParamTable = null;
    MathOverrides mo = sim.getMathOverrides();
    if (mo != null) {
        String[] constants = mo.getOverridenConstantNames();
        for (int i = 0; i < constants.length; i++) {
            String actualStr = "", defStr = "";
            Expression tempExp = mo.getDefaultExpression(constants[i]);
            if (tempExp != null) {
                defStr = tempExp.infix();
            }
            if (mo.isScan(constants[i])) {
                actualStr = mo.getConstantArraySpec(constants[i]).toString();
            } else {
                tempExp = mo.getActualExpression(constants[i], 0);
                if (tempExp != null) {
                    actualStr = tempExp.infix();
                }
            }
            if (overParamTable == null) {
                overParamTable = getTable(3, 75, 1, 3, 3);
                overParamTable.setAlignment(Table.ALIGN_LEFT);
                overParamTable.addCell(createCell("Overriden Parameters", getBold(DEF_HEADER_FONT_SIZE), 3, 1, Element.ALIGN_CENTER, true));
                overParamTable.addCell(createHeaderCell("Name", getBold(), 1));
                overParamTable.addCell(createHeaderCell("Actual Value", getBold(), 1));
                overParamTable.addCell(createHeaderCell("Default Value", getBold(), 1));
            }
            overParamTable.addCell(createCell(constants[i], getFont()));
            overParamTable.addCell(createCell(actualStr, getFont()));
            overParamTable.addCell(createCell(defStr, getFont()));
        }
    }
    if (overParamTable != null) {
        simSection.add(overParamTable);
    }
    // add spatial details
    // sim.isSpatial();
    Table meshTable = null;
    MeshSpecification mesh = sim.getMeshSpecification();
    if (mesh != null) {
        Geometry geom = mesh.getGeometry();
        Extent extent = geom.getExtent();
        String extentStr = "(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")";
        ISize meshSize = mesh.getSamplingSize();
        String meshSizeStr = "(" + meshSize.getX() + ", " + meshSize.getY() + ", " + meshSize.getZ() + ")";
        meshTable = getTable(2, 75, 1, 3, 3);
        meshTable.setAlignment(Table.ALIGN_LEFT);
        meshTable.addCell(createCell("Geometry Setting", getBold(DEF_HEADER_FONT_SIZE), 2, 1, Element.ALIGN_CENTER, true));
        meshTable.addCell(createCell("Geometry Size (um)", getFont()));
        meshTable.addCell(createCell(extentStr, getFont()));
        meshTable.addCell(createCell("Mesh Size (elements)", getFont()));
        meshTable.addCell(createCell(meshSizeStr, getFont()));
    }
    if (meshTable != null) {
        simSection.add(meshTable);
    }
    // write advanced sim settings
    Table simAdvTable = null;
    SolverTaskDescription solverDesc = sim.getSolverTaskDescription();
    if (solverDesc != null) {
        String solverName = solverDesc.getSolverDescription().getDisplayLabel();
        simAdvTable = getTable(2, 75, 1, 3, 3);
        simAdvTable.setAlignment(Table.ALIGN_LEFT);
        simAdvTable.addCell(createCell("Advanced Settings", getBold(DEF_HEADER_FONT_SIZE), 2, 1, Element.ALIGN_CENTER, true));
        simAdvTable.addCell(createCell("Solver Name", getFont()));
        simAdvTable.addCell(createCell(solverName, getFont()));
        simAdvTable.addCell(createCell("Time Bounds - Starting", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeBounds().getStartingTime(), getFont()));
        simAdvTable.addCell(createCell("Time Bounds - Ending", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeBounds().getEndingTime(), getFont()));
        simAdvTable.addCell(createCell("Time Step - Min", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getMinimumTimeStep(), getFont()));
        simAdvTable.addCell(createCell("Time Step - Default", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getDefaultTimeStep(), getFont()));
        simAdvTable.addCell(createCell("Time Step - Max", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getMaximumTimeStep(), getFont()));
        ErrorTolerance et = solverDesc.getErrorTolerance();
        if (et != null) {
            simAdvTable.addCell(createCell("Error Tolerance - Absolute", getFont()));
            simAdvTable.addCell(createCell("" + et.getAbsoluteErrorTolerance(), getFont()));
            simAdvTable.addCell(createCell("Error Tolerance - Relative", getFont()));
            simAdvTable.addCell(createCell("" + et.getRelativeErrorTolerance(), getFont()));
        }
        OutputTimeSpec ots = solverDesc.getOutputTimeSpec();
        if (ots.isDefault()) {
            simAdvTable.addCell(createCell("Keep Every", getFont()));
            simAdvTable.addCell(createCell("" + ((DefaultOutputTimeSpec) ots).getKeepEvery(), getFont()));
            simAdvTable.addCell(createCell("Keep At Most", getFont()));
            simAdvTable.addCell(createCell("" + ((DefaultOutputTimeSpec) ots).getKeepAtMost(), getFont()));
        } else if (ots.isUniform()) {
            simAdvTable.addCell(createCell("Output Time Step", getFont()));
            simAdvTable.addCell(createCell("" + ((UniformOutputTimeSpec) ots).getOutputTimeStep(), getFont()));
        } else if (ots.isExplicit()) {
            simAdvTable.addCell(createCell("Output Time Points", getFont()));
            simAdvTable.addCell(createCell("" + ((ExplicitOutputTimeSpec) ots).toCommaSeperatedOneLineOfString(), getFont()));
        }
        simAdvTable.addCell(createCell("Use Symbolic Jacobian (T/F)", getFont()));
        simAdvTable.addCell(createCell((solverDesc.getUseSymbolicJacobian() ? " T " : " F "), getFont()));
        Constant sp = solverDesc.getSensitivityParameter();
        if (sp != null) {
            simAdvTable.addCell(createCell("Sensitivity Analysis Param", getFont()));
            simAdvTable.addCell(createCell(sp.getName(), getFont()));
        }
    }
    if (simAdvTable != null) {
        simSection.add(simAdvTable);
    }
}
Also used : Table(com.lowagie.text.Table) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) Constant(cbit.vcell.math.Constant) Section(com.lowagie.text.Section) MeshSpecification(cbit.vcell.solver.MeshSpecification) Geometry(cbit.vcell.geometry.Geometry) MathOverrides(cbit.vcell.solver.MathOverrides) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Expression(cbit.vcell.parser.Expression) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription)

Example 9 with DefaultOutputTimeSpec

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

the class AdamsMoultonFiveSolver method integrate.

/**
 * This method was created by a SmartGuide.
 *  THIS HAS NOT BEEN UPDATED LIKE ODEIntegrator.integrate () and
 *  RungeKuttaFehlbergIntegrator.integrate()...
 */
protected void integrate() throws SolverException, UserStopException, IOException {
    try {
        SolverTaskDescription taskDescription = simTask.getSimulation().getSolverTaskDescription();
        double timeStep = taskDescription.getTimeStep().getDefaultTimeStep();
        fieldCurrentTime = taskDescription.getTimeBounds().getStartingTime();
        // before computation begins, settle fast equilibrium
        if (getFastAlgebraicSystem() != null) {
            fieldValueVectors.copyValues(0, 1);
            getFastAlgebraicSystem().initVars(getValueVector(0), getValueVector(1));
            getFastAlgebraicSystem().solveSystem(getValueVector(0), getValueVector(1));
            fieldValueVectors.copyValues(1, 0);
        }
        // check for failure
        check(getValueVector(0));
        // Evaluate
        for (int i = 0; i < getStateVariableCount(); i++) {
            f[0][getVariableIndex(i)] = evaluate(getValueVector(0), i);
        }
        // check for failure
        check(getValueVector(0));
        updateResultSet();
        // 
        int iteration = 0;
        while (fieldCurrentTime < taskDescription.getTimeBounds().getEndingTime()) {
            checkForUserStop();
            if (iteration < 3) {
                // Take Runge-Kutta step...
                prep(fieldCurrentTime, timeStep);
            } else {
                // Take Adams-Moulton step...
                step(fieldCurrentTime, timeStep);
            }
            // update (old = new)
            fieldValueVectors.copyValuesDown();
            // compute fast system
            if (getFastAlgebraicSystem() != null) {
                fieldValueVectors.copyValues(0, 1);
                getFastAlgebraicSystem().initVars(getValueVector(0), getValueVector(1));
                getFastAlgebraicSystem().solveSystem(getValueVector(0), getValueVector(1));
                fieldValueVectors.copyValues(1, 0);
            }
            // check for failure
            check(getValueVector(0));
            if (iteration < 3) {
                for (int i = 0; i < getStateVariableCount(); i++) {
                    f[iteration + 1][getVariableIndex(i)] = evaluate(getValueVector(0), i);
                }
                // check for failure
                check(f[iteration + 1]);
            } else {
                // Evaluate
                for (int i = 0; i < getStateVariableCount(); i++) {
                    f[4][getVariableIndex(i)] = evaluate(getValueVector(0), i);
                }
                // check for failure
                check(f[4]);
                shiftWorkArrays();
            }
            // fieldCurrentTime += timeStep;
            iteration++;
            fieldCurrentTime = taskDescription.getTimeBounds().getStartingTime() + iteration * timeStep;
            // store results if it coincides with a save interval
            if (taskDescription.getOutputTimeSpec().isDefault()) {
                int keepEvery = ((DefaultOutputTimeSpec) taskDescription.getOutputTimeSpec()).getKeepEvery();
                if ((iteration % keepEvery) == 0)
                    updateResultSet();
            }
        }
        // store last time point
        if (taskDescription.getOutputTimeSpec().isDefault()) {
            int keepEvery = ((DefaultOutputTimeSpec) taskDescription.getOutputTimeSpec()).getKeepEvery();
            if ((iteration % keepEvery) == 0)
                updateResultSet();
        }
    } catch (ExpressionException expressionException) {
        throw new SolverException(expressionException.getMessage());
    } catch (MathException mathException) {
        throw new SolverException(mathException.getMessage());
    }
}
Also used : MathException(cbit.vcell.math.MathException) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) SolverException(cbit.vcell.solver.SolverException) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 10 with DefaultOutputTimeSpec

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

the class AbstractJavaSolver method printToFile.

/**
 * Insert the method's description here.
 * Creation date: (6/27/2001 12:17:36 PM)
 */
protected final void printToFile(double progress) throws IOException {
    long currentTime = System.currentTimeMillis();
    // decide whether to fire progress event
    boolean shouldFire = false;
    if (progress <= 0 || progress >= 1) {
        // always fire at begin and end
        shouldFire = true;
    } else {
        // only fire at specified increment
        shouldFire = (progress - lastFiredProgress) * 100 > getProgressIncrement();
    }
    if (shouldFire) {
        lastFiredProgress = progress;
        fireSolverProgress(progress);
    }
    // decide whether to save to file
    boolean shouldSave = false;
    // only if enabled
    if (isSaveEnabled()) {
        // check to see whether we need to save
        if (progress <= 0) {
            // a new run just got initialized; save 0 datapoint
            shouldSave = true;
        } else if (progress >= 1) {
            // a run finished; save last datapoint
            shouldSave = true;
        } else {
            // in the middle of a run; only save at specified time interval
            shouldSave = currentTime - lastSavedMS > 1000 * getSaveToFileInterval();
        }
        if (shouldSave) {
            // write file and fire event
            if (this instanceof ODESolver) {
                ODESolverResultSet odeSolverResultSet = ((ODESolver) this).getODESolverResultSet();
                Simulation simulation = simTask.getSimulationJob().getSimulation();
                OutputTimeSpec outputTimeSpec = simulation.getSolverTaskDescription().getOutputTimeSpec();
                if (outputTimeSpec.isDefault()) {
                    odeSolverResultSet.trimRows(((DefaultOutputTimeSpec) outputTimeSpec).getKeepAtMost());
                }
                ODESimData odeSimData = new ODESimData(new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), getJobIndex()), odeSolverResultSet);
                String mathName = odeSimData.getMathName();
                if (lg.isTraceEnabled())
                    lg.trace("AbstractJavaSolver.printToFile(" + mathName + ")");
                File logFile = new File(getBaseName() + LOGFILE_EXTENSION);
                File dataFile = new File(getBaseName() + ODE_DATA_EXTENSION);
                ODESimData.writeODEDataFile(odeSimData, dataFile);
                odeSimData.writeODELogFile(logFile, dataFile);
            }
            lastSavedMS = System.currentTimeMillis();
            fireSolverPrinted(getCurrentTime());
        }
    }
}
Also used : DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) Simulation(cbit.vcell.solver.Simulation) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) File(java.io.File)

Aggregations

DefaultOutputTimeSpec (cbit.vcell.solver.DefaultOutputTimeSpec)24 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)15 OutputTimeSpec (cbit.vcell.solver.OutputTimeSpec)13 SolverTaskDescription (cbit.vcell.solver.SolverTaskDescription)13 ExplicitOutputTimeSpec (cbit.vcell.solver.ExplicitOutputTimeSpec)8 Simulation (cbit.vcell.solver.Simulation)7 TimeBounds (cbit.vcell.solver.TimeBounds)6 ExpressionException (cbit.vcell.parser.ExpressionException)5 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)5 SolverDescription (cbit.vcell.solver.SolverDescription)5 MathException (cbit.vcell.math.MathException)4 SolverException (cbit.vcell.solver.SolverException)4 Constant (cbit.vcell.math.Constant)3 SubDomain (cbit.vcell.math.SubDomain)3 Expression (cbit.vcell.parser.Expression)3 NonspatialStochSimOptions (cbit.vcell.solver.NonspatialStochSimOptions)3 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)3 File (java.io.File)3 Geometry (cbit.vcell.geometry.Geometry)2 JumpProcess (cbit.vcell.math.JumpProcess)2