Search in sources :

Example 1 with ODESimData

use of cbit.vcell.solver.ode.ODESimData in project vcell by virtualcell.

the class ODEDataManager method connect.

private void connect() throws DataAccessException {
    // clone, so we can operate safely on it (adding/removing user-defined functions) - real remote data is being cached...
    odeSolverResultSet = new ODESimData(getVCDataIdentifier(), getVCDataManager().getODEData(getVCDataIdentifier()));
    nFSimMolecularConfigurations = getVCDataManager().getNFSimMolecularConfigurations(getVCDataIdentifier());
}
Also used : ODESimData(cbit.vcell.solver.ode.ODESimData)

Example 2 with ODESimData

use of cbit.vcell.solver.ode.ODESimData in project vcell by virtualcell.

the class SimulationData method getVarAndFunctionDataIdentifiers.

/**
 * This method was created in VisualAge.
 * @return java.lang.String[]
 */
public synchronized DataIdentifier[] getVarAndFunctionDataIdentifiers(OutputContext outputContext) throws IOException, DataAccessException {
    // Is this zip format?
    boolean bIsChombo = false;
    try {
        bIsChombo = isChombo();
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.out);
    }
    File zipFile1 = getZipFile(bIsChombo, null);
    File zipFile2 = getZipFile(bIsChombo, 0);
    bZipFormat1 = false;
    bZipFormat2 = false;
    if (zipFile1.exists()) {
        bZipFormat1 = true;
    } else if (zipFile2.exists()) {
        bZipFormat2 = true;
    }
    refreshLogFile();
    if (!isComsol()) {
        try {
            refreshMeshFile();
        } catch (MathException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException(e.getMessage());
        }
    }
    if (!isRulesData && !getIsODEData() && !isComsol() && dataFilenames != null) {
        // read variables only when I have never read the file since variables don't change
        if (dataSetIdentifierList.size() == 0) {
            File file = getPDEDataFile(0.0);
            DataSet dataSet = getPDEDataSet(file, 0.0);
            String[] varNames = dataSet.getDataNames();
            int[] varTypeInts = dataSet.getVariableTypeIntegers();
            if (varNames == null) {
                return null;
            }
            dataSetIdentifierList.clear();
            for (int i = 0; i < varNames.length; i++) {
                VariableType varType = null;
                try {
                    varType = VariableType.getVariableTypeFromInteger(varTypeInts[i]);
                } catch (IllegalArgumentException e) {
                    if (LG.isEnabledFor(Level.WARN)) {
                        LG.warn("Exception typing " + varNames[i] + " has unsupported type " + varTypeInts[i] + ": " + e.getMessage());
                    }
                    varType = SimulationData.getVariableTypeFromLength(mesh, dataSet.getDataLength(varNames[i]));
                }
                Domain domain = Variable.getDomainFromCombinedIdentifier(varNames[i]);
                String varName = Variable.getNameFromCombinedIdentifier(varNames[i]);
                dataSetIdentifierList.addElement(new DataSetIdentifier(varName, varType, domain));
            }
            refreshDataProcessingOutputInfo(outputContext);
            if (dataProcessingOutputInfo != null) {
                for (int i = 0; i < dataProcessingOutputInfo.getVariableNames().length; i++) {
                    if (dataProcessingOutputInfo.getPostProcessDataType(dataProcessingOutputInfo.getVariableNames()[i]).equals(DataProcessingOutputInfo.PostProcessDataType.image)) {
                        dataSetIdentifierList.addElement(new DataSetIdentifier(dataProcessingOutputInfo.getVariableNames()[i], VariableType.POSTPROCESSING, null));
                    }
                }
            }
        }
        // always read functions file since functions might change
        getFunctionDataIdentifiers(outputContext);
    }
    if ((isRulesData || getIsODEData()) && dataSetIdentifierList.size() == 0) {
        ODEDataBlock odeDataBlock = getODEDataBlock();
        if (odeDataBlock == null) {
            throw new DataAccessException("Results are not availabe yet. Please try again later.");
        }
        ODESimData odeSimData = odeDataBlock.getODESimData();
        int colCount = odeSimData.getColumnDescriptionsCount();
        // assume index=0 is time "t"
        int DATA_OFFSET = 1;
        dataSetIdentifierList.clear();
        for (int i = 0; i < (colCount - DATA_OFFSET); i++) {
            String varName = odeSimData.getColumnDescriptions(i + DATA_OFFSET).getDisplayName();
            // TODO domain
            Domain domain = null;
            dataSetIdentifierList.addElement(new DataSetIdentifier(varName, VariableType.NONSPATIAL, domain));
        }
    }
    if (isComsol() && dataSetIdentifierList.size() == 0) {
        ComsolSimFiles comsolSimFiles = getComsolSimFiles();
        if (comsolSimFiles.simTaskXMLFile != null) {
            try {
                String xmlString = FileUtils.readFileToString(comsolSimFiles.simTaskXMLFile);
                SimulationTask simTask = XmlHelper.XMLToSimTask(xmlString);
                Enumeration<Variable> variablesEnum = simTask.getSimulation().getMathDescription().getVariables();
                while (variablesEnum.hasMoreElements()) {
                    Variable var = variablesEnum.nextElement();
                    if (var instanceof VolVariable) {
                        dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), VariableType.VOLUME, var.getDomain()));
                    } else if (var instanceof MemVariable) {
                        dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), VariableType.MEMBRANE, var.getDomain()));
                    } else if (var instanceof Function) {
                        VariableType varType = VariableType.UNKNOWN;
                        if (var.getDomain() != null && var.getDomain().getName() != null) {
                            SubDomain subDomain = simTask.getSimulation().getMathDescription().getSubDomain(var.getDomain().getName());
                            if (subDomain instanceof CompartmentSubDomain) {
                                varType = VariableType.VOLUME;
                            } else if (subDomain instanceof MembraneSubDomain) {
                                varType = VariableType.MEMBRANE;
                            } else if (subDomain instanceof FilamentSubDomain) {
                                throw new RuntimeException("filament subdomains not supported");
                            } else if (subDomain instanceof PointSubDomain) {
                                varType = VariableType.POINT_VARIABLE;
                            }
                        }
                        dataSetIdentifierList.addElement(new DataSetIdentifier(var.getName(), varType, var.getDomain()));
                    } else if (var instanceof Constant) {
                        System.out.println("ignoring Constant " + var.getName());
                    } else if (var instanceof InsideVariable) {
                        System.out.println("ignoring InsideVariable " + var.getName());
                    } else if (var instanceof OutsideVariable) {
                        System.out.println("ignoring OutsideVariable " + var.getName());
                    } else {
                        throw new RuntimeException("unexpected variable " + var.getName() + " of type " + var.getClass().getName());
                    }
                }
            } catch (XmlParseException | ExpressionException e) {
                e.printStackTrace();
                throw new RuntimeException("failed to read sim task file, msg: " + e.getMessage(), e);
            }
        }
    }
    DataIdentifier[] dis = new DataIdentifier[dataSetIdentifierList.size()];
    for (int i = 0; i < dataSetIdentifierList.size(); i++) {
        DataSetIdentifier dsi = (DataSetIdentifier) dataSetIdentifierList.elementAt(i);
        String displayName = dsi.getName();
        if (dsi.isFunction()) {
            AnnotatedFunction f = null;
            for (int j = 0; j < annotatedFunctionList.size(); j++) {
                AnnotatedFunction function = (AnnotatedFunction) annotatedFunctionList.elementAt(j);
                if (function.getName().equals(dsi.getName())) {
                    f = function;
                    break;
                }
            }
            if (f != null) {
                displayName = f.getDisplayName();
            }
        }
        dis[i] = new DataIdentifier(dsi.getName(), dsi.getVariableType(), dsi.getDomain(), dsi.isFunction(), displayName);
    }
    return dis;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) SimulationTask(cbit.vcell.messaging.server.SimulationTask) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Constant(cbit.vcell.math.Constant) FileNotFoundException(java.io.FileNotFoundException) PointSubDomain(cbit.vcell.math.PointSubDomain) ODESimData(cbit.vcell.solver.ode.ODESimData) InsideVariable(cbit.vcell.math.InsideVariable) ExpressionException(cbit.vcell.parser.ExpressionException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) SubDomain(cbit.vcell.math.SubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Function(cbit.vcell.math.Function) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) MemVariable(cbit.vcell.math.MemVariable) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) ComsolSimFiles(org.vcell.vis.io.ComsolSimFiles) VariableType(cbit.vcell.math.VariableType) VolVariable(cbit.vcell.math.VolVariable) XmlParseException(cbit.vcell.xml.XmlParseException) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) MathException(cbit.vcell.math.MathException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) OutsideVariable(cbit.vcell.math.OutsideVariable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) SubDomain(cbit.vcell.math.SubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 3 with ODESimData

use of cbit.vcell.solver.ode.ODESimData in project vcell by virtualcell.

the class NagiosVCellMonitor method checkVCell.

private CheckResults checkVCell(VCELL_CHECK_LEVEL checkLevel, String rmiHostName, int rmiPort, String rmiBootstrapStubName, String vcellNagiosPassword, int criticalTimeout, int monitorPort) throws Exception {
    SimulationStatusPersistent lastSimStatus = null;
    String vcellVersion = null;
    TreeMap<VCELL_CHECK_LEVEL, Long> levelTimesMillisec = new TreeMap<NagiosVCellMonitor.VCELL_CHECK_LEVEL, Long>();
    long startTime = System.currentTimeMillis();
    VCellConnection vcellConnection = null;
    try {
        if (rmiHostName == null || rmiPort == -1) {
            throw new UnexpectedTestStateException("Host name/ip and rmiPort required for testing, rmihostname=" + rmiHostName + " rmiport=" + rmiPort);
        }
        String rmiUrl = "//" + rmiHostName + ":" + rmiPort + "/" + rmiBootstrapStubName;
        VCellBootstrap vcellBootstrap = null;
        try {
            vcellBootstrap = (VCellBootstrap) Naming.lookup(rmiUrl);
        } catch (Exception e) {
            throw new UnexpectedTestStateException("Error during bootstrap lookup, " + e.getClass().getSimpleName() + " " + e.getMessage());
        }
        vcellVersion = vcellBootstrap.getVCellSoftwareVersion();
        levelTimesMillisec.put(VCELL_CHECK_LEVEL.RMI_ONLY_0, System.currentTimeMillis() - startTime);
        if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.CONNECT_1.ordinal()) {
            if (vcellNagiosPassword == null) {
                throw new UnexpectedTestStateException("vcellNagios Password required for " + VCELL_CHECK_LEVEL.CONNECT_1.toString() + " and above");
            }
            UserLoginInfo userLoginInfo = new UserLoginInfo(VCELL_NAGIOS_USER, new DigestedPassword(vcellNagiosPassword));
            vcellConnection = vcellBootstrap.getVCellConnection(userLoginInfo);
            levelTimesMillisec.put(VCELL_CHECK_LEVEL.CONNECT_1, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.RMI_ONLY_0));
            if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.INFOS_2.ordinal()) {
                VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
                levelTimesMillisec.put(VCELL_CHECK_LEVEL.INFOS_2, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.CONNECT_1));
                if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.LOAD_3.ordinal()) {
                    KeyValue bioModelKey = null;
                    final String testModelName = "Solver Suite 5.1 (BETA only ode)";
                    for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                        if (userLoginInfo.getUserName().equals(bioModelInfo.getVersion().getOwner().getName()) && bioModelInfo.getVersion().getName().equals(testModelName)) {
                            bioModelKey = bioModelInfo.getVersion().getVersionKey();
                            break;
                        }
                    }
                    BigString bioModelXML = vcellConnection.getUserMetaDbServer().getBioModelXML(bioModelKey);
                    BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
                    bioModel.refreshDependencies();
                    levelTimesMillisec.put(VCELL_CHECK_LEVEL.LOAD_3, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.INFOS_2));
                    if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.DATA_4.ordinal()) {
                        final String testSimContextName = "non-spatial ODE";
                        SimulationContext simulationContext = bioModel.getSimulationContext(testSimContextName);
                        final String testSimName = "Copy of combined ida/cvode";
                        Simulation simulation = simulationContext.getSimulation(testSimName);
                        if (simulation == null) {
                            throw new UnexpectedTestStateException("Couldn't find sim '" + testSimName + "' for " + checkLevel.toString());
                        }
                        VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), 0);
                        ArrayList<AnnotatedFunction> outputFunctionsList = simulationContext.getOutputFunctionContext().getOutputFunctionsList();
                        OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
                        double[] times = vcellConnection.getDataSetController().getDataSetTimes(vcSimulationDataIdentifier);
                        ODESimData odeSimData = vcellConnection.getDataSetController().getODEData(vcSimulationDataIdentifier);
                        levelTimesMillisec.put(VCELL_CHECK_LEVEL.DATA_4, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.LOAD_3));
                        if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.RUN_5.ordinal()) {
                            KeyValue copy1Key = null;
                            KeyValue copy2Key = null;
                            VCSimulationIdentifier testRunSimID = null;
                            try {
                                if (simulationContext.getSimulations().length != 1) {
                                    throw new UnexpectedTestStateException("Expecting only 1 sim to be copied for " + checkLevel.toString());
                                }
                                SimulationStatusPersistent simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(simulation.getVersion().getVersionKey());
                                if (!simulationStatus.isCompleted()) {
                                    throw new UnexpectedTestStateException("Expecting completed sim to copy for " + checkLevel.toString());
                                }
                                String copyModelName = testModelName + "_" + rmiHostName + "_rmi" + rmiPort + "_siteprt" + monitorPort;
                                boolean bForceCleanup = true;
                                while (true) {
                                    boolean bMessy = false;
                                    for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                                        if (userLoginInfo.getUserName().equals(bioModelInfo.getVersion().getOwner().getName()) && bioModelInfo.getVersion().getName().equals(copyModelName)) {
                                            bMessy = true;
                                            if (bForceCleanup) {
                                                try {
                                                    vcellConnection.getUserMetaDbServer().deleteBioModel(bioModelInfo.getVersion().getVersionKey());
                                                } catch (Exception e) {
                                                    e.printStackTrace();
                                                }
                                            } else {
                                                throw new MessyTestEnvironmentException("Messy test environment, not expecting " + copyModelName + " and couldn't cleanup");
                                            }
                                        }
                                    }
                                    if (!bMessy) {
                                        break;
                                    }
                                    // get new vcInfoContainer without cleaned-up model
                                    vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
                                    bForceCleanup = false;
                                }
                                BigString copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModelAs(bioModelXML, copyModelName, null);
                                BioModel copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
                                copy1Key = copyBioModel.getVersion().getVersionKey();
                                copyBioModel.refreshDependencies();
                                Simulation copySim = copyBioModel.getSimulationContext(testSimContextName).copySimulation(copyBioModel.getSimulationContext(testSimContextName).getSimulation(testSimName));
                                final String copyTestSimName = "test";
                                copySim.setName(copyTestSimName);
                                copyBioModel.refreshDependencies();
                                copyBioModelXMLStr = new BigString(XmlHelper.bioModelToXML(copyBioModel));
                                copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModel(copyBioModelXMLStr, null);
                                copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
                                copy2Key = copyBioModel.getVersion().getVersionKey();
                                copyBioModel.refreshDependencies();
                                Simulation newSimulation = copyBioModel.getSimulationContext(testSimContextName).getSimulation(copyTestSimName);
                                simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                                if (simulationStatus != null && !simulationStatus.isNeverRan()) {
                                    throw new UnexpectedTestStateException("Expecting new sim to have 'never ran' status for " + checkLevel.toString());
                                }
                                testRunSimID = new VCSimulationIdentifier(newSimulation.getVersion().getVersionKey(), copyBioModel.getVersion().getOwner());
                                vcellConnection.getSimulationController().startSimulation(testRunSimID, 1);
                                lastSimStatus = simulationStatus;
                                MessageEvent[] messageEvents = null;
                                while (simulationStatus == null || (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed())) {
                                    Thread.sleep(200);
                                    if (((System.currentTimeMillis() - startTime) / 1000) > criticalTimeout) {
                                        vcellConnection.getSimulationController().stopSimulation(testRunSimID);
                                        vcellConnection.getMessageEvents();
                                        break;
                                    }
                                    simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                                    if (simulationStatus != null && !simulationStatus.toString().equals((lastSimStatus == null ? null : lastSimStatus.toString()))) {
                                        lastSimStatus = simulationStatus;
                                    }
                                    if (simulationStatus != null && simulationStatus.isFailed()) {
                                        throw new Exception("time " + ((System.currentTimeMillis() - startTime) / 1000) + ", Sim execution failed key:" + testRunSimID.getSimulationKey() + " sim " + newSimulation.getName() + " model " + copyBioModel.getVersion().getName() + " messg " + simulationStatus.getFailedMessage());
                                    }
                                    messageEvents = vcellConnection.getMessageEvents();
                                }
                            } finally {
                                try {
                                    if (copy1Key != null) {
                                        vcellConnection.getUserMetaDbServer().deleteBioModel(copy1Key);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                try {
                                    if (copy2Key != null) {
                                        vcellConnection.getUserMetaDbServer().deleteBioModel(copy2Key);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                if (testRunSimID != null) {
                                    deleteSimData(testRunSimID);
                                }
                            }
                            levelTimesMillisec.put(VCELL_CHECK_LEVEL.RUN_5, System.currentTimeMillis() - startTime - levelTimesMillisec.get(VCELL_CHECK_LEVEL.DATA_4));
                        }
                    }
                }
            }
        }
        return new CheckResults(vcellVersion, levelTimesMillisec, lastSimStatus, System.currentTimeMillis() - startTime, null);
    } catch (Exception e) {
        return new CheckResults(vcellVersion, levelTimesMillisec, lastSimStatus, System.currentTimeMillis() - startTime, e);
    } finally {
        vcellConnection = null;
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) MessageEvent(cbit.rmi.event.MessageEvent) VCellBootstrap(cbit.vcell.server.VCellBootstrap) BigString(org.vcell.util.BigString) ODESimData(cbit.vcell.solver.ode.ODESimData) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) BigString(org.vcell.util.BigString) VCInfoContainer(org.vcell.util.document.VCInfoContainer) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) VCellConnection(cbit.vcell.server.VCellConnection) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) TreeMap(java.util.TreeMap) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) IOException(java.io.IOException) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) UserLoginInfo(org.vcell.util.document.UserLoginInfo) XMLSource(cbit.vcell.xml.XMLSource)

Example 4 with ODESimData

use of cbit.vcell.solver.ode.ODESimData in project vcell by virtualcell.

the class StochtestRunService method runsolver.

private static void runsolver(Simulation newSimulation, File baseDirectory, int numRuns, TimeSeriesMultitrialData timeSeriesMultitrialData) {
    Simulation versSimulation = null;
    File destDir = null;
    boolean bTimeout = false;
    // int progress = 1;
    for (int trialIndex = 0; trialIndex < numRuns; trialIndex++) {
        System.out.println("\n=====================================\n\nStarting trial " + (trialIndex + 1) + " of " + numRuns + "\n\n==============================\n");
        long startTime = System.currentTimeMillis();
        // }
        try {
            versSimulation = new TempSimulation(newSimulation, false);
            // printout(ruleBasedTestDir.getAbsolutePath());
            destDir = new File(baseDirectory, timeSeriesMultitrialData.datasetName);
            SimulationTask simTask = new SimulationTask(new SimulationJob(versSimulation, 0, null), 0);
            Solver solver = ClientSimManager.createQuickRunSolver(destDir, simTask);
            solver.startSolver();
            while (true) {
                try {
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (System.currentTimeMillis() - startTime > 30 * 1000) {
                    // timeout after 30 seconds .. otherwise multiple runs will take forever
                    bTimeout = true;
                    solver.stopSolver();
                    throw new RuntimeException("timed out");
                }
                SolverStatus solverStatus = solver.getSolverStatus();
                if (solverStatus != null) {
                    if (solverStatus.getStatus() == SolverStatus.SOLVER_ABORTED) {
                        throw new RuntimeException(solverStatus.getSimulationMessage().getDisplayMessage());
                    }
                    if (solverStatus.getStatus() != SolverStatus.SOLVER_STARTING && solverStatus.getStatus() != SolverStatus.SOLVER_READY && solverStatus.getStatus() != SolverStatus.SOLVER_RUNNING) {
                        break;
                    }
                }
            }
            SimulationData simData = new SimulationData(simTask.getSimulationJob().getVCDataIdentifier(), destDir, null, null);
            ODEDataBlock odeDataBlock = simData.getODEDataBlock();
            ODESimData odeSimData = odeDataBlock.getODESimData();
            timeSeriesMultitrialData.addDataSet(odeSimData, trialIndex);
        } catch (Exception e) {
            e.printStackTrace();
            File file = new File(baseDirectory, Simulation.createSimulationID(versSimulation.getKey()) + "_solverExc.txt");
            StochtestFileUtils.writeMessageTofile(file, e.getMessage());
            if (bTimeout) {
                throw new RuntimeException("timed out");
            } else {
                throw new RuntimeException("solver failed : " + e.getMessage(), e);
            }
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        StochtestFileUtils.clearDir(destDir);
    }
// printout("\n");
}
Also used : Solver(cbit.vcell.solver.server.Solver) SimulationTask(cbit.vcell.messaging.server.SimulationTask) TempSimulation(cbit.vcell.solver.TempSimulation) ODESimData(cbit.vcell.solver.ode.ODESimData) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) GeometryException(cbit.vcell.geometry.GeometryException) TempSimulation(cbit.vcell.solver.TempSimulation) Simulation(cbit.vcell.solver.Simulation) SimulationData(cbit.vcell.simdata.SimulationData) ODEDataBlock(cbit.vcell.simdata.ODEDataBlock) File(java.io.File) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 5 with ODESimData

use of cbit.vcell.solver.ode.ODESimData in project vcell by virtualcell.

the class ASCIIExporter method getODEDataValues.

/**
 * Insert the method's description here.
 * Creation date: (1/17/00 6:02:37 PM)
 * @return java.lang.String
 * @param odeSimData cbit.vcell.simdata.ODESimData
 * @param variableNames java.lang.String[]
 * @param beginIndex int
 * @param endIndex int
 * @param switchRowsColumns boolean
 * @exception org.vcell.util.DataAccessException The exception description.
 * @throws IOException
 */
private FileDataContainerID getODEDataValues(long jobID, User user, DataServerImpl dataServerImpl, VCDataIdentifier vcdID, String[] variableNames, int beginIndex, int endIndex, boolean switchRowsColumns, FileDataContainerManager fileDataContainerManager) throws DataAccessException, IOException {
    ODESimData odeSimData = dataServerImpl.getODEData(user, vcdID);
    double progress = 0.0;
    boolean isTimeSeries = (odeSimData.findColumn("t") > -1) ? true : false;
    boolean isMultiTrial = (odeSimData.findColumn("TrialNo") > -1) ? true : false;
    // get arrays
    double[] allTimes = null;
    try {
        if (isTimeSeries)
            allTimes = odeSimData.extractColumn(odeSimData.findColumn("t"));
        else if (isMultiTrial)
            allTimes = odeSimData.extractColumn(odeSimData.findColumn("TrialNo"));
    } catch (cbit.vcell.parser.ExpressionException e) {
        e.printStackTrace(System.out);
    }
    double[][] variableValues = new double[variableNames.length][endIndex - beginIndex + 1];
    for (int k = 0; k < variableNames.length; k++) {
        for (int i = beginIndex; i <= endIndex; i++) {
            progress = (double) (i + k * (endIndex - beginIndex + 1)) / (2 * variableNames.length * (endIndex - beginIndex + 1));
            exportServiceImpl.fireExportProgress(jobID, vcdID, "CSV", progress);
            try {
                variableValues[k][i - beginIndex] = odeSimData.extractColumn(odeSimData.findColumn(variableNames[k]))[i];
            } catch (cbit.vcell.parser.ExpressionException e) {
                e.printStackTrace(System.out);
                throw new DataAccessException("error evaluating function in dataset: " + e.getMessage());
            }
        }
    }
    // put data in csv format
    FileDataContainerID fileDataContainerID = fileDataContainerManager.getNewFileDataContainerID();
    if (isTimeSeries) {
        fileDataContainerManager.append(fileDataContainerID, "Variable values over the time range " + allTimes[beginIndex] + " to " + allTimes[endIndex] + "\n\n");
    } else if (isMultiTrial) {
        fileDataContainerManager.append(fileDataContainerID, "Variable values over the Trials " + allTimes[beginIndex] + " to " + allTimes[endIndex] + "\n\n");
    }
    if (switchRowsColumns) {
        fileDataContainerManager.append(fileDataContainerID, ",Variable\n");
        if (isTimeSeries)
            fileDataContainerManager.append(fileDataContainerID, "Time,");
        else if (isMultiTrial)
            fileDataContainerManager.append(fileDataContainerID, "Trial No,");
        for (int i = beginIndex; i <= endIndex; i++) {
            fileDataContainerManager.append(fileDataContainerID, "," + allTimes[i]);
        }
        fileDataContainerManager.append(fileDataContainerID, "\n");
        for (int k = 0; k < variableNames.length; k++) {
            fileDataContainerManager.append(fileDataContainerID, "," + variableNames[k]);
            for (int i = beginIndex; i <= endIndex; i++) {
                progress = 0.5 + (double) (i + k * (endIndex - beginIndex + 1)) / (2 * variableNames.length * (endIndex - beginIndex + 1));
                exportServiceImpl.fireExportProgress(jobID, vcdID, "CSV", progress);
                fileDataContainerManager.append(fileDataContainerID, "," + variableValues[k][i - beginIndex]);
            }
            fileDataContainerManager.append(fileDataContainerID, "\n");
        }
    } else {
        if (isTimeSeries)
            fileDataContainerManager.append(fileDataContainerID, ",Time\n");
        else if (isMultiTrial)
            fileDataContainerManager.append(fileDataContainerID, ",Trial No\n");
        fileDataContainerManager.append(fileDataContainerID, "Variable,");
        for (int k = 0; k < variableNames.length; k++) {
            fileDataContainerManager.append(fileDataContainerID, "," + variableNames[k]);
        }
        fileDataContainerManager.append(fileDataContainerID, "\n");
        for (int i = beginIndex; i <= endIndex; i++) {
            fileDataContainerManager.append(fileDataContainerID, "," + allTimes[i]);
            for (int k = 0; k < variableNames.length; k++) {
                progress = 0.5 + (double) (i + k * (endIndex - beginIndex + 1)) / (2 * variableNames.length * (endIndex - beginIndex + 1));
                exportServiceImpl.fireExportProgress(jobID, vcdID, "CSV", progress);
                fileDataContainerManager.append(fileDataContainerID, "," + variableValues[k][i - beginIndex]);
            }
            fileDataContainerManager.append(fileDataContainerID, "\n");
        }
    }
    return fileDataContainerID;
}
Also used : FileDataContainerID(cbit.vcell.export.server.FileDataContainerManager.FileDataContainerID) ODESimData(cbit.vcell.solver.ode.ODESimData) SinglePoint(cbit.vcell.geometry.SinglePoint) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

ODESimData (cbit.vcell.solver.ode.ODESimData)12 ExpressionException (cbit.vcell.parser.ExpressionException)5 Simulation (cbit.vcell.solver.Simulation)5 File (java.io.File)5 DataAccessException (org.vcell.util.DataAccessException)5 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 ODEDataBlock (cbit.vcell.simdata.ODEDataBlock)3 SimulationData (cbit.vcell.simdata.SimulationData)3 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)3 SimulationJob (cbit.vcell.solver.SimulationJob)3 TempSimulation (cbit.vcell.solver.TempSimulation)3 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)3 MessageEvent (cbit.rmi.event.MessageEvent)2 BioModel (cbit.vcell.biomodel.BioModel)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 SimulationStatusPersistent (cbit.vcell.server.SimulationStatusPersistent)2 VCellBootstrap (cbit.vcell.server.VCellBootstrap)2 VCellConnection (cbit.vcell.server.VCellConnection)2 OutputContext (cbit.vcell.simdata.OutputContext)2 Solver (cbit.vcell.solver.server.Solver)2