Search in sources :

Example 11 with MathMappingCallbackTaskAdapter

use of cbit.vcell.mapping.MathMappingCallbackTaskAdapter in project vcell by virtualcell.

the class ClientRequestManager method updateMath.

public static Collection<AsynchClientTask> updateMath(final Component requester, final SimulationContext simulationContext, final boolean bShowWarning, final NetworkGenerationRequirements networkGenerationRequirements) {
    ArrayList<AsynchClientTask> rval = new ArrayList<>();
    AsynchClientTask task1 = new AsynchClientTask("generating math", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Geometry geometry = simulationContext.getGeometry();
            if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
                geometry.getGeometrySurfaceDescription().updateAll();
            }
            // Use differnt mathmapping for different applications (stoch or non-stoch)
            simulationContext.checkValidity();
            MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
            MathMapping mathMapping = simulationContext.createNewMathMapping(callback, networkGenerationRequirements);
            MathDescription mathDesc = mathMapping.getMathDescription(callback);
            callback.setProgressFraction(1.0f / 3.0f * 2.0f);
            hashTable.put("mathMapping", mathMapping);
            hashTable.put("mathDesc", mathDesc);
        }
    };
    rval.add(task1);
    AsynchClientTask task2 = new AsynchClientTask("formating math", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            MathDescription mathDesc = (MathDescription) hashTable.get("mathDesc");
            if (mathDesc != null) {
                simulationContext.setMathDescription(mathDesc);
            }
        }
    };
    rval.add(task2);
    if (bShowWarning) {
        AsynchClientTask task3 = new AsynchClientTask("showing issues", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                MathMapping mathMapping = (MathMapping) hashTable.get("mathMapping");
                MathDescription mathDesc = (MathDescription) hashTable.get("mathDesc");
                if (mathDesc != null) {
                    // 
                    // inform user if any issues
                    // 
                    Issue[] issues = mathMapping.getIssues();
                    if (issues != null && issues.length > 0) {
                        StringBuffer messageBuffer = new StringBuffer("Issues encountered during Math Generation:\n");
                        int issueCount = 0;
                        for (int i = 0; i < issues.length; i++) {
                            if (issues[i].getSeverity() == Issue.SEVERITY_ERROR || issues[i].getSeverity() == Issue.SEVERITY_WARNING) {
                                messageBuffer.append(issues[i].getCategory() + " " + issues[i].getSeverityName() + " : " + issues[i].getMessage() + "\n");
                                issueCount++;
                            }
                        }
                        if (issueCount > 0) {
                            PopupGenerator.showWarningDialog(requester, messageBuffer.toString(), new String[] { "OK" }, "OK");
                        }
                    }
                }
            }
        };
        rval.add(task3);
    }
    return rval;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathMappingCallbackTaskAdapter(cbit.vcell.mapping.MathMappingCallbackTaskAdapter) Issue(org.vcell.util.Issue) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) SetMathDescription(cbit.vcell.client.task.SetMathDescription) MathDescription(cbit.vcell.math.MathDescription) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Geometry(cbit.vcell.geometry.Geometry) MathMapping(cbit.vcell.mapping.MathMapping)

Aggregations

MathMappingCallbackTaskAdapter (cbit.vcell.mapping.MathMappingCallbackTaskAdapter)11 SimulationContext (cbit.vcell.mapping.SimulationContext)9 MathMappingCallback (cbit.vcell.mapping.SimulationContext.MathMappingCallback)9 ArrayList (java.util.ArrayList)7 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)6 Simulation (cbit.vcell.solver.Simulation)6 Hashtable (java.util.Hashtable)6 BioModel (cbit.vcell.biomodel.BioModel)5 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)3 OutputTimeSpec (cbit.vcell.solver.OutputTimeSpec)3 TempSimulation (cbit.vcell.solver.TempSimulation)3 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)3 XMLSource (cbit.vcell.xml.XMLSource)3 Application (cbit.vcell.mapping.SimulationContext.Application)2 NetworkGenerationRequirements (cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements)2 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)2 SimulationTask (cbit.vcell.messaging.server.SimulationTask)2 SolverDescription (cbit.vcell.solver.SolverDescription)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2