Search in sources :

Example 1 with TimeStep

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

the class SmoldynFileWriter method writeSimulationTimes.

private void writeSimulationTimes() {
    // write simulation times
    TimeBounds timeBounds = simulation.getSolverTaskDescription().getTimeBounds();
    TimeStep timeStep = simulation.getSolverTaskDescription().getTimeStep();
    printWriter.println("# simulation times");
    printWriter.println(SmoldynVCellMapper.SmoldynKeyword.time_start + " " + timeBounds.getStartingTime());
    printWriter.println(SmoldynVCellMapper.SmoldynKeyword.time_stop + " " + timeBounds.getEndingTime());
    printWriter.println(SmoldynVCellMapper.SmoldynKeyword.time_step + " " + timeStep.getDefaultTimeStep());
    printWriter.println();
}
Also used : TimeBounds(cbit.vcell.solver.TimeBounds) TimeStep(cbit.vcell.solver.TimeStep)

Example 2 with TimeStep

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

the class MatcheableTest method nullSafe.

@Test
public void nullSafe() {
    TimeStep t = new TimeStep();
    TimeStep cp = new TimeStep(t);
    TimeStep nStep = null;
    TimeStep nStep2 = null;
    assertTrue(Matchable.areEqual(t, t));
    assertTrue(Matchable.areEqual(cp, t));
    assertTrue(Matchable.areEqual(t, cp));
    assertTrue(Matchable.areEqual(nStep, nStep2));
    assertFalse(Matchable.areEqual(t, nStep));
    assertFalse(Matchable.areEqual(nStep, t));
}
Also used : TimeStep(cbit.vcell.solver.TimeStep) Test(org.junit.Test)

Example 3 with TimeStep

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

the class XmlReader method getTimeStep.

/**
 * This method returns a TimeStep object from a XML Element.
 * Creation date: (5/22/2001 11:45:33 AM)
 * @return cbit.vcell.solver.TimeStep
 * @param param org.jdom.Element
 */
private TimeStep getTimeStep(Element param) {
    // get attributes
    double min = Double.parseDouble(param.getAttributeValue(XMLTags.MinTimeAttrTag));
    double def = Double.parseDouble(param.getAttributeValue(XMLTags.DefaultTimeAttrTag));
    double max = Double.parseDouble(param.getAttributeValue(XMLTags.MaxTimeAttrTag));
    // **** create new TimeStep object ****
    TimeStep timeStep = new TimeStep(min, def, max);
    return timeStep;
}
Also used : TimeStep(cbit.vcell.solver.TimeStep)

Example 4 with TimeStep

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

the class FRAPStudy method createNewRefBioModel.

public static BioModel createNewRefBioModel(FRAPStudy sourceFrapStudy, String baseDiffusionRate, TimeStep tStep, KeyValue simKey, User owner, FieldDataIdentifierSpec psfFDIS, int startingIndexForRecovery) throws Exception {
    if (owner == null) {
        throw new Exception("Owner is not defined");
    }
    ROI cellROI_2D = sourceFrapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
    Extent extent = sourceFrapStudy.getFrapData().getImageDataset().getExtent();
    TimeBounds timeBounds = FRAPOptData.getEstimatedRefTimeBound(sourceFrapStudy);
    double timeStepVal = FRAPOptData.REFERENCE_DIFF_DELTAT;
    int numX = cellROI_2D.getRoiImages()[0].getNumX();
    int numY = cellROI_2D.getRoiImages()[0].getNumY();
    int numZ = cellROI_2D.getRoiImages().length;
    short[] shortPixels = cellROI_2D.getRoiImages()[0].getPixels();
    byte[] bytePixels = new byte[numX * numY * numZ];
    final byte EXTRACELLULAR_PIXVAL = 0;
    final byte CYTOSOL_PIXVAL = 1;
    for (int i = 0; i < bytePixels.length; i++) {
        if (shortPixels[i] != 0) {
            bytePixels[i] = CYTOSOL_PIXVAL;
        }
    }
    VCImage maskImage;
    try {
        maskImage = new VCImageUncompressed(null, bytePixels, extent, numX, numY, numZ);
    } catch (ImageException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to create mask image for geometry");
    }
    Geometry geometry = new Geometry("geometry", maskImage);
    if (geometry.getGeometrySpec().getNumSubVolumes() != 2) {
        throw new Exception("Cell ROI has no ExtraCellular.");
    }
    int subVolume0PixVal = ((ImageSubVolume) geometry.getGeometrySpec().getSubVolume(0)).getPixelValue();
    geometry.getGeometrySpec().getSubVolume(0).setName((subVolume0PixVal == EXTRACELLULAR_PIXVAL ? EXTRACELLULAR_NAME : CYTOSOL_NAME));
    int subVolume1PixVal = ((ImageSubVolume) geometry.getGeometrySpec().getSubVolume(1)).getPixelValue();
    geometry.getGeometrySpec().getSubVolume(1).setName((subVolume1PixVal == CYTOSOL_PIXVAL ? CYTOSOL_NAME : EXTRACELLULAR_NAME));
    geometry.getGeometrySurfaceDescription().updateAll();
    BioModel bioModel = new BioModel(null);
    bioModel.setName("unnamed");
    Model model = new Model("model");
    bioModel.setModel(model);
    Feature extracellular = model.addFeature(EXTRACELLULAR_NAME);
    Feature cytosol = model.addFeature(CYTOSOL_NAME);
    Membrane plasmaMembrane = model.addMembrane(PLASMAMEMBRANE_NAME);
    String roiDataName = FRAPStudy.ROI_EXTDATA_NAME;
    final int ONE_DIFFUSION_SPECIES_COUNT = 1;
    final int MOBILE_SPECIES_INDEX = 0;
    Expression[] diffusionConstants = new Expression[ONE_DIFFUSION_SPECIES_COUNT];
    Species[] species = new Species[ONE_DIFFUSION_SPECIES_COUNT];
    SpeciesContext[] speciesContexts = new SpeciesContext[ONE_DIFFUSION_SPECIES_COUNT];
    Expression[] initialConditions = new Expression[ONE_DIFFUSION_SPECIES_COUNT];
    // Mobile Species
    diffusionConstants[MOBILE_SPECIES_INDEX] = new Expression(baseDiffusionRate);
    species[MOBILE_SPECIES_INDEX] = new Species(SPECIES_NAME_PREFIX_MOBILE, "Mobile bleachable species");
    speciesContexts[MOBILE_SPECIES_INDEX] = new SpeciesContext(null, species[MOBILE_SPECIES_INDEX].getCommonName(), species[MOBILE_SPECIES_INDEX], cytosol);
    FieldFunctionArguments postBleach_first = new FieldFunctionArguments(roiDataName, "postbleach_first", new Expression(0), VariableType.VOLUME);
    FieldFunctionArguments prebleach_avg = new FieldFunctionArguments(roiDataName, "prebleach_avg", new Expression(0), VariableType.VOLUME);
    Expression expPostBleach_first = new Expression(postBleach_first.infix());
    Expression expPreBleach_avg = new Expression(prebleach_avg.infix());
    initialConditions[MOBILE_SPECIES_INDEX] = Expression.div(expPostBleach_first, expPreBleach_avg);
    SimulationContext simContext = new SimulationContext(bioModel.getModel(), geometry);
    bioModel.addSimulationContext(simContext);
    FeatureMapping cytosolFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(cytosol);
    FeatureMapping extracellularFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(extracellular);
    MembraneMapping plasmaMembraneMapping = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(plasmaMembrane);
    SubVolume cytSubVolume = geometry.getGeometrySpec().getSubVolume(CYTOSOL_NAME);
    SubVolume exSubVolume = geometry.getGeometrySpec().getSubVolume(EXTRACELLULAR_NAME);
    SurfaceClass pmSurfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(exSubVolume, cytSubVolume);
    cytosolFeatureMapping.setGeometryClass(cytSubVolume);
    extracellularFeatureMapping.setGeometryClass(exSubVolume);
    plasmaMembraneMapping.setGeometryClass(pmSurfaceClass);
    cytosolFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    extracellularFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    plasmaMembraneMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    for (int i = 0; i < initialConditions.length; i++) {
        model.addSpecies(species[i]);
        model.addSpeciesContext(speciesContexts[i]);
    }
    for (int i = 0; i < speciesContexts.length; i++) {
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(speciesContexts[i]);
        scs.getInitialConditionParameter().setExpression(initialConditions[i]);
        scs.getDiffusionParameter().setExpression(diffusionConstants[i]);
    }
    MathMapping mathMapping = simContext.createNewMathMapping();
    MathDescription mathDesc = mathMapping.getMathDescription();
    // Add PSF function
    mathDesc.addVariable(new Function(Simulation.PSF_FUNCTION_NAME, new Expression(psfFDIS.getFieldFuncArgs().infix()), null));
    simContext.setMathDescription(mathDesc);
    SimulationVersion simVersion = new SimulationVersion(simKey, "sim1", owner, new GroupAccessNone(), new KeyValue("0"), new BigDecimal(0), new Date(), VersionFlag.Current, "", null);
    Simulation newSimulation = new Simulation(simVersion, simContext.getMathDescription());
    newSimulation.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
    simContext.addSimulation(newSimulation);
    newSimulation.getSolverTaskDescription().setTimeBounds(timeBounds);
    newSimulation.getSolverTaskDescription().setOutputTimeSpec(new UniformOutputTimeSpec(timeStepVal));
    newSimulation.getMeshSpecification().setSamplingSize(cellROI_2D.getISize());
    newSimulation.getSolverTaskDescription().setTimeStep(new TimeStep(timeStepVal, timeStepVal, timeStepVal));
    return bioModel;
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) ImageException(cbit.image.ImageException) KeyValue(org.vcell.util.document.KeyValue) Extent(org.vcell.util.Extent) SurfaceClass(cbit.vcell.geometry.SurfaceClass) MathDescription(cbit.vcell.math.MathDescription) VCImage(cbit.image.VCImage) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Feature(cbit.vcell.model.Feature) TimeBounds(cbit.vcell.solver.TimeBounds) Function(cbit.vcell.math.Function) GroupAccessNone(org.vcell.util.document.GroupAccessNone) TimeStep(cbit.vcell.solver.TimeStep) SimulationVersion(org.vcell.util.document.SimulationVersion) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SubVolume(cbit.vcell.geometry.SubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) Membrane(cbit.vcell.model.Membrane) Species(cbit.vcell.model.Species) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) VCImageUncompressed(cbit.image.VCImageUncompressed) SimulationContext(cbit.vcell.mapping.SimulationContext) ROI(cbit.vcell.VirtualMicroscopy.ROI) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) MathMapping(cbit.vcell.mapping.MathMapping)

Example 5 with TimeStep

use of cbit.vcell.solver.TimeStep 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)

Aggregations

TimeStep (cbit.vcell.solver.TimeStep)18 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)9 Simulation (cbit.vcell.solver.Simulation)8 BioModel (cbit.vcell.biomodel.BioModel)7 SimulationContext (cbit.vcell.mapping.SimulationContext)7 TimeBounds (cbit.vcell.solver.TimeBounds)7 IOException (java.io.IOException)7 MathDescription (cbit.vcell.math.MathDescription)6 KeyValue (org.vcell.util.document.KeyValue)6 Geometry (cbit.vcell.geometry.Geometry)5 Model (cbit.vcell.model.Model)5 ImageException (cbit.image.ImageException)4 SubVolume (cbit.vcell.geometry.SubVolume)4 SurfaceClass (cbit.vcell.geometry.SurfaceClass)4 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 Expression (cbit.vcell.parser.Expression)4 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)4 SimulationJob (cbit.vcell.solver.SimulationJob)4 SolverException (cbit.vcell.solver.SolverException)4 SimulationVersion (org.vcell.util.document.SimulationVersion)4