Search in sources :

Example 6 with OutputFunctionContext

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

the class SimulationContextDbDriver method getSimulationContextSQL.

/**
 * getModel method comment.
 */
private SimulationContext getSimulationContextSQL(QueryHashtable dbc, Connection con, User user, KeyValue simContextKey) throws /*, ReactStepDbDriver reactStepDB*/
SQLException, DataAccessException, IllegalMappingException, PropertyVetoException {
    SimulationContext simContext = null;
    String sql;
    Field[] f = { new cbit.sql.StarField(simContextTable), userTable.userid };
    Table[] t = { simContextTable, userTable };
    String condition = simContextTable.id.getQualifiedColName() + " = " + simContextKey + " AND " + simContextTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
    // System.out.println(sql);
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            simContext = simContextTable.getSimContext(dbc, con, user, rset, geomDB, modelDB, mathDescDB);
        } else {
            throw new ObjectNotFoundException("SimulationContext id=" + simContextKey + " not found for user '" + user + "'");
        }
    } finally {
        stmt.close();
    }
    DataSymbolTable.table.populateDataSymbols(con, simContextKey, simContext.getDataContext(), user, simContext.getModel().getUnitSystem());
    ArrayList<AnnotatedFunction> outputFunctionList = ApplicationMathTable.table.getOutputFunctionsSimcontext(con, simContextKey, dbSyntax);
    if (outputFunctionList != null) {
        OutputFunctionContext outputFnContext = simContext.getOutputFunctionContext();
        outputFnContext.setOutputFunctions(outputFunctionList);
    }
    SimContextTable.table.readAppComponents(con, simContext, dbSyntax);
    assignStimuliSQL(con, simContextKey, simContext);
    assignStructureMappingsSQL(dbc, con, simContextKey, simContext);
    assignSpeciesContextSpecsSQL(con, simContextKey, simContext);
    assignReactionSpecsSQL(con, simContextKey, simContext);
    for (GeometryClass gc : simContext.getGeometry().getGeometryClasses()) {
        try {
            StructureSizeSolver.updateUnitStructureSizes(simContext, gc);
        } catch (Exception e) {
            lg.error("failed to updateUnitStructureSizes", e);
        }
    }
    simContext.getGeometryContext().enforceHierarchicalBoundaryConditions(simContext.getModel().getStructureTopology());
    simContext.getModel().refreshDependencies();
    assignAnalysisTasksSQL(con, simContextKey, simContext);
    // really needed to calculate MembraneMapping parameters that are not stored (inside/outside flux correction factors).
    simContext.refreshDependencies();
    return simContext;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Table(cbit.sql.Table) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) DependencyException(org.vcell.util.DependencyException) RecordChangedException(cbit.sql.RecordChangedException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) Field(cbit.sql.Field) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) ResultSet(java.sql.ResultSet) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 7 with OutputFunctionContext

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

the class CLIUtils method exportPDE2HDF5.

public static void exportPDE2HDF5(cbit.vcell.solver.Simulation sim, File userDir, File hdf5OutputFile) throws DataAccessException, IOException {
    SimulationContext sc = (SimulationContext) sim.getSimulationOwner();
    BioModel bm = sc.getBioModel();
    // VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(sim.getKey(), sim.getSimulationInfo().getVersion().getOwner());
    User user = new User(userDir.getName(), null);
    VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(sim.getKey(), user);
    if (sim.getScanCount() > 1) {
        throw new IllegalArgumentException("Parameter scans to be implemented");
    }
    VCSimulationDataIdentifier vcId = new VCSimulationDataIdentifier(vcSimID, 0);
    Species[] species = bm.getModel().getSpecies();
    String[] variableNames = new String[species.length];
    for (int i = 0; i < species.length; i++) {
        variableNames[i] = species[i].getCommonName();
    }
    VariableSpecs variableSpecs = new VariableSpecs(variableNames, ExportConstants.VARIABLE_MULTI);
    DataSetControllerImpl dsControllerImpl = new DataSetControllerImpl(null, userDir.getParentFile(), null);
    double[] dataSetTimes = dsControllerImpl.getDataSetTimes(vcId);
    TimeSpecs timeSpecs = new TimeSpecs(0, dataSetTimes.length - 1, dataSetTimes, ExportConstants.TIME_RANGE);
    timeSpecs = new TimeSpecs(0, 0, dataSetTimes, ExportConstants.TIME_RANGE);
    int geoMode = ExportConstants.GEOMETRY_FULL;
    SpatialSelection[] selections = new SpatialSelection[0];
    selections = null;
    int axis = 2;
    int sliceNumber = 0;
    GeometrySpecs geometrySpecs = new GeometrySpecs(selections, axis, sliceNumber, geoMode);
    ExportConstants.DataType dataType = ExportConstants.DataType.PDE_VARIABLE_DATA;
    boolean switchRowsColumns = false;
    // String simulationName,VCSimulationIdentifier vcSimulationIdentifier,ExportParamScanInfo exportParamScanInfo
    ExportSpecs.SimNameSimDataID snsdi = new ExportSpecs.SimNameSimDataID(sim.getName(), vcSimID, null);
    ExportSpecs.SimNameSimDataID[] simNameSimDataIDs = { snsdi };
    int[] exportMultipleParamScans = null;
    boolean isHDF5 = true;
    FormatSpecificSpecs formatSpecificSpecs = new ASCIISpecs(ExportFormat.CSV, dataType, switchRowsColumns, simNameSimDataIDs, exportMultipleParamScans, csvRoiLayout.var_time_val, isHDF5);
    OutputFunctionContext ofc = sc.getOutputFunctionContext();
    ArrayList<AnnotatedFunction> outputFunctionsList = ofc.getOutputFunctionsList();
    AnnotatedFunction[] af = outputFunctionsList.toArray(new AnnotatedFunction[0]);
    OutputContext outputContext = new OutputContext(af);
    ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
    ASCIIExporter ae = new ASCIIExporter(exportServiceImpl);
    String contextName = bm.getName() + ":" + sc.getName();
    ExportSpecs exportSpecs = new ExportSpecs(vcId, ExportFormat.HDF5, variableSpecs, timeSpecs, geometrySpecs, formatSpecificSpecs, sim.getName(), contextName);
    DataServerImpl dataServerImpl = new DataServerImpl(dsControllerImpl, exportServiceImpl);
    FileDataContainerManager fileDataContainerManager = new FileDataContainerManager();
    JobRequest jobRequest = JobRequest.createExportJobRequest(vcId.getOwner());
    Collection<ExportOutput> eo = ae.makeASCIIData(outputContext, jobRequest, vcId.getOwner(), dataServerImpl, exportSpecs, fileDataContainerManager);
    Iterator<ExportOutput> iterator = eo.iterator();
    ExportOutput aaa = iterator.next();
    if (((ASCIISpecs) exportSpecs.getFormatSpecificSpecs()).isHDF5()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // Get location of temp HDF5 file
        aaa.writeDataToOutputStream(baos, fileDataContainerManager);
        File tempHDF5File = new File(baos.toString());
        Files.copy(tempHDF5File, hdf5OutputFile);
        tempHDF5File.delete();
    }
}
Also used : DataServerImpl(cbit.vcell.simdata.DataServerImpl) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) ExportConstants(cbit.vcell.export.server.ExportConstants) User(org.vcell.util.document.User) ExportOutput(cbit.vcell.export.server.ExportOutput) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ASCIIExporter(cbit.vcell.export.server.ASCIIExporter) FileDataContainerManager(cbit.vcell.export.server.FileDataContainerManager) GeometrySpecs(cbit.vcell.export.server.GeometrySpecs) FormatSpecificSpecs(cbit.vcell.export.server.FormatSpecificSpecs) JobRequest(cbit.vcell.export.server.JobRequest) SpatialSelection(cbit.vcell.simdata.SpatialSelection) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) Species(cbit.vcell.model.Species) TimeSpecs(cbit.vcell.export.server.TimeSpecs) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) ASCIISpecs(cbit.vcell.export.server.ASCIISpecs) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) VariableSpecs(cbit.vcell.export.server.VariableSpecs) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) BioModel(cbit.vcell.biomodel.BioModel) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl)

Example 8 with OutputFunctionContext

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

the class OutputFunctionsListTableModel method setOutputFunctionContext.

public void setOutputFunctionContext(OutputFunctionContext newValue) {
    OutputFunctionContext oldValue = this.outputFunctionContext;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(this);
        oldValue.getSimulationOwner().removePropertyChangeListener(this);
    }
    this.outputFunctionContext = newValue;
    if (this.outputFunctionContext != null) {
        this.outputFunctionContext.addPropertyChangeListener(this);
        newValue.getSimulationOwner().addPropertyChangeListener(this);
    }
    if (newValue == null) {
        setData(null);
    } else {
        fireTableStructureChanged();
        setData(newValue.getOutputFunctionsList());
    }
}
Also used : OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext)

Aggregations

OutputFunctionContext (cbit.vcell.solver.OutputFunctionContext)8 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)6 SimulationContext (cbit.vcell.mapping.SimulationContext)4 PropertyVetoException (java.beans.PropertyVetoException)4 Geometry (cbit.vcell.geometry.Geometry)3 MappingException (cbit.vcell.mapping.MappingException)3 MathDescription (cbit.vcell.math.MathDescription)3 MathException (cbit.vcell.math.MathException)3 ExpressionException (cbit.vcell.parser.ExpressionException)3 BioModel (cbit.vcell.biomodel.BioModel)2 GeometryClass (cbit.vcell.geometry.GeometryClass)2 MathModel (cbit.vcell.mathmodel.MathModel)2 ModelException (cbit.vcell.model.ModelException)2 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)2 Simulation (cbit.vcell.solver.Simulation)2 RedistributionVersion (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2