Search in sources :

Example 31 with SolverException

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

the class FiniteVolumeFileWriter method assignPhases.

private void assignPhases(CompartmentSubDomain[] subDomains, int startingIndex, int[] phases, int[] numAssigned) throws SolverException {
    if (phases[startingIndex] == -1) {
        return;
    }
    if (numAssigned[0] == subDomains.length) {
        return;
    }
    for (int j = subDomains.length - 1; j >= 0; j--) {
        if (startingIndex == j) {
            continue;
        }
        MembraneSubDomain mem = getSimulationTask().getSimulation().getMathDescription().getMembraneSubDomain(subDomains[startingIndex], subDomains[j]);
        if (mem != null) {
            int newPhase = phases[startingIndex] == 0 ? 1 : 0;
            if (phases[j] == -1) {
                numAssigned[0]++;
                // membrane between i and j, different phase
                phases[j] = newPhase;
                assignPhases(subDomains, j, phases, numAssigned);
            } else if (phases[j] != newPhase) {
                throw new SolverException("Geometry is invalid for " + getSimulationTask().getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + ": domains are not properly nested (membrane branching). \n\n(domain " + subDomains[j].getName() + " was assigned to phase " + phases[j] + ", is again being assigned to phase " + newPhase + ".)");
            }
        }
    }
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) SolverException(cbit.vcell.solver.SolverException)

Example 32 with SolverException

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

the class FiniteVolumeFileWriter method writePostProcessingBlock.

private void writePostProcessingBlock() throws Exception {
    // SolverException, ExpressionException and exceptions from roiDataGenerator.getROIDataGeneratorDescription()
    PostProcessingBlock postProcessingBlock = simTask.getSimulation().getMathDescription().getPostProcessingBlock();
    if (postProcessingBlock.getNumDataGenerators() == 0) {
        // to make c++ code write default var statisitcs, without the token it won't write anything
        printWriter.println(FVInputFileKeyword.POST_PROCESSING_BLOCK_BEGIN);
        printWriter.println(FVInputFileKeyword.POST_PROCESSING_BLOCK_END);
        printWriter.println();
        return;
    }
    if (bChomboSolver && postProcessingBlock.getDataGeneratorList().size() > 0) {
        throw new Exception("Data generators are not supported by " + simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel());
    }
    printWriter.println(" # Post Processing Block");
    printWriter.println(FVInputFileKeyword.POST_PROCESSING_BLOCK_BEGIN);
    for (DataGenerator dataGenerator : postProcessingBlock.getDataGeneratorList()) {
        String varName = dataGenerator.getName();
        Domain domain = dataGenerator.getDomain();
        String domainName = domain == null ? null : domain.getName();
        if (dataGenerator instanceof ProjectionDataGenerator) {
            ProjectionDataGenerator pdg = (ProjectionDataGenerator) dataGenerator;
            Expression function = subsituteExpression(pdg.getFunction(), VariableDomain.VARIABLEDOMAIN_VOLUME);
            printWriter.println(FVInputFileKeyword.PROJECTION_DATA_GENERATOR + " " + varName + " " + domainName + " " + pdg.getAxis() + " " + pdg.getOperation() + " " + function.infix() + ";");
        } else if (dataGenerator instanceof ConvolutionDataGenerator) {
            ConvolutionDataGenerator convolutionDataGenerator = (ConvolutionDataGenerator) dataGenerator;
            ConvolutionDataGeneratorKernel kernel = convolutionDataGenerator.getKernel();
            if (kernel instanceof GaussianConvolutionDataGeneratorKernel) {
                GaussianConvolutionDataGeneratorKernel gck = (GaussianConvolutionDataGeneratorKernel) kernel;
                Expression volFunction = subsituteExpression(convolutionDataGenerator.getVolFunction(), VariableDomain.VARIABLEDOMAIN_VOLUME);
                Expression memFunction = subsituteExpression(convolutionDataGenerator.getMemFunction(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
                Expression sigmaXY = subsituteExpression(gck.getSigmaXY_um(), VariableDomain.VARIABLEDOMAIN_VOLUME);
                Expression sigmaZ = subsituteExpression(gck.getSigmaZ_um(), VariableDomain.VARIABLEDOMAIN_VOLUME);
                String volFuncStr = volFunction.infix();
                String memFuncStr = memFunction.infix();
                printWriter.println(FVInputFileKeyword.GAUSSIAN_CONVOLUTION_DATA_GENERATOR + " " + varName + " " + domainName + " " + sigmaXY.infix() + " " + sigmaZ.infix() + " " + FVInputFileKeyword.GAUSSIAN_CONVOLUTION_VOL_FUNCTION + " " + volFuncStr + "; " + FVInputFileKeyword.GAUSSIAN_CONVOLUTION_MEM_FUNCTION + " " + memFuncStr + ";");
            }
        } else if (dataGenerator instanceof cbit.vcell.microscopy.ROIDataGenerator) {
            /*
			ROI_DATA_GENERATOR_BEGIN roidata
			VolumePoints 20
			2667 2676 2679 2771 2969 2877 3067 3277 3185 3283 3473 3580 3690 3687 3878 4086 3990 4182 4193 1077 (all points in one line)
			SampleImage 9 0 1341426862190 vcField('sumROIData','roiSumDataVar',0.0,'Volume')
			StoreEnabled false

			SampleImageFile roiSumDataVar 0.0 C:\Users\abcde\VirtualMicroscopy\SimulationData\SimID_1341426862125_0_sumROIData_roiSumDataVar_0_0_Volume.fdat
			DATA_PROCESSOR_END
			*/
            cbit.vcell.microscopy.ROIDataGenerator roiDataGenerator = (cbit.vcell.microscopy.ROIDataGenerator) dataGenerator;
            printWriter.println(roiDataGenerator.getROIDataGeneratorDescription(workingDirectory, simTask.getSimulationJob()));
        } else if (dataGenerator instanceof org.vcell.vmicro.workflow.data.ROIDataGenerator) {
            /*
			ROI_DATA_GENERATOR_BEGIN roidata
			VolumePoints 20
			2667 2676 2679 2771 2969 2877 3067 3277 3185 3283 3473 3580 3690 3687 3878 4086 3990 4182 4193 1077 (all points in one line)
			SampleImage 9 0 1341426862190 vcField('sumROIData','roiSumDataVar',0.0,'Volume')
			StoreEnabled false

			SampleImageFile roiSumDataVar 0.0 C:\Users\abcde\VirtualMicroscopy\SimulationData\SimID_1341426862125_0_sumROIData_roiSumDataVar_0_0_Volume.fdat
			DATA_PROCESSOR_END
			*/
            org.vcell.vmicro.workflow.data.ROIDataGenerator roiDataGenerator = (org.vcell.vmicro.workflow.data.ROIDataGenerator) dataGenerator;
            printWriter.println(roiDataGenerator.getROIDataGeneratorDescription(workingDirectory, simTask.getSimulationJob()));
        } else {
            throw new SolverException(dataGenerator.getClass() + " : data generator not supported yet.");
        }
    }
    printWriter.println(FVInputFileKeyword.POST_PROCESSING_BLOCK_END);
    printWriter.println();
}
Also used : ConvolutionDataGenerator(cbit.vcell.math.ConvolutionDataGenerator) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) ImageException(cbit.image.ImageException) FileNotFoundException(java.io.FileNotFoundException) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) GaussianConvolutionDataGeneratorKernel(cbit.vcell.math.ConvolutionDataGenerator.GaussianConvolutionDataGeneratorKernel) ConvolutionDataGeneratorKernel(cbit.vcell.math.ConvolutionDataGenerator.ConvolutionDataGeneratorKernel) PostProcessingBlock(cbit.vcell.math.PostProcessingBlock) Expression(cbit.vcell.parser.Expression) ConvolutionDataGenerator(cbit.vcell.math.ConvolutionDataGenerator) DataGenerator(cbit.vcell.math.DataGenerator) ProjectionDataGenerator(cbit.vcell.math.ProjectionDataGenerator) ProjectionDataGenerator(cbit.vcell.math.ProjectionDataGenerator) GaussianConvolutionDataGeneratorKernel(cbit.vcell.math.ConvolutionDataGenerator.GaussianConvolutionDataGeneratorKernel) SolverException(cbit.vcell.solver.SolverException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) SubDomain(cbit.vcell.math.SubDomain) Domain(cbit.vcell.math.Variable.Domain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain)

Example 33 with SolverException

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

the class HTCSolver method writeJavaInputFile.

protected void writeJavaInputFile() throws SolverException {
    PrintWriter pw = null;
    try {
        File inputFile = new File(getBaseName() + JAVA_INPUT_EXTENSION);
        if (!inputFile.exists()) {
            // write input file which is just xml
            String xmlString = XmlHelper.simToXML(simTask.getSimulation());
            pw = new PrintWriter(inputFile);
            pw.println(xmlString);
            pw.close();
        }
    } catch (XmlParseException e) {
        e.printStackTrace(System.out);
        throw new SolverException(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.out);
        throw new SolverException(e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 34 with SolverException

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

the class MovingBoundaryFileWriter method writeMovingBoundaryXML.

// 
// XML producer - here all the work is done
// 
public Element writeMovingBoundaryXML(SimulationTask simTask) throws SolverException {
    try {
        int subdomainsWithPdeEquations = subdomainsSanityCheck();
        if (subdomainsWithPdeEquations != 1) {
            throw new RuntimeException("MovingBoundary Solver only accepts ONE subdomain containing PDE equations.");
        }
        Element rootElement = new Element(MBTags.MovingBoundarySetup);
        if (bUseMessaging) {
            // jms
            rootElement.addContent(getXMLJms());
        }
        // problem
        rootElement.addContent(getXMLProblem());
        // report
        rootElement.addContent(getXMLReport());
        // progress
        rootElement.addContent(getXMLProgress());
        // trace
        rootElement.addContent(getXMLTrace());
        // debug
        rootElement.addContent(getXMLDebug());
        Element tr = getXMLTextReport();
        if (tr != null) {
            rootElement.addContent(tr);
        }
        return rootElement;
    } catch (Exception e) {
        throw new SolverException("Can't generate MovingBoundary input", e);
    }
}
Also used : Element(org.jdom.Element) SolverException(cbit.vcell.solver.SolverException) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Example 35 with SolverException

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

the class OptXmlWriter method getModelXML.

public static Element getModelXML(PdeObjectiveFunction pdeObjectiveFunction, String[] parameterNames) {
    Element modelElement = new Element(OptXmlTags.Model_Tag);
    try {
        SpatialReferenceData refData = pdeObjectiveFunction.getReferenceData();
        double refDataEndTime = refData.getDataByRow(refData.getNumDataRows() - 1)[0];
        // 
        // post the problem either as an IDA or CVODE model
        // 
        org.vcell.util.document.SimulationVersion simVersion = new org.vcell.util.document.SimulationVersion(new KeyValue("12345"), "name", new org.vcell.util.document.User("user", new KeyValue("123")), new org.vcell.util.document.GroupAccessNone(), // versionBranchPointRef
        null, // branchID
        new java.math.BigDecimal(1.0), new java.util.Date(), org.vcell.util.document.VersionFlag.Archived, "", null);
        Simulation simulation = new Simulation(simVersion, pdeObjectiveFunction.getMathDescription());
        simulation.getMeshSpecification().setSamplingSize(refData.getDataISize());
        double[] times = refData.getDataByColumn(0);
        double minDt = Double.POSITIVE_INFINITY;
        for (int i = 1; i < times.length; i++) {
            minDt = Math.min(minDt, times[i] - times[i - 1]);
        }
        simulation.getSolverTaskDescription().setTimeBounds(new cbit.vcell.solver.TimeBounds(0.0, refDataEndTime));
        simulation.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolume);
        simulation.getSolverTaskDescription().setTimeStep(new TimeStep(minDt / 5, minDt / 5, minDt / 5));
        // clone and resample geometry
        Geometry resampledGeometry = null;
        try {
            resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
            GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
            ISize newSize = simulation.getMeshSpecification().getSamplingSize();
            geoSurfaceDesc.setVolumeSampleSize(newSize);
            geoSurfaceDesc.updateAll();
        } catch (Exception e) {
            e.printStackTrace();
            throw new SolverException(e.getMessage());
        }
        SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, pdeObjectiveFunction.getFieldDataIDSs()), 0);
        StringWriter simulationInputStringWriter = new StringWriter();
        FiniteVolumeFileWriter fvFileWriter = new FiniteVolumeFileWriter(new PrintWriter(simulationInputStringWriter, true), simTask, resampledGeometry, pdeObjectiveFunction.getWorkingDirectory());
        fvFileWriter.write(parameterNames);
        simulationInputStringWriter.close();
        modelElement.setAttribute(OptXmlTags.ModelType_Attr, OptXmlTags.ModelType_Attr_FVSOLVER);
        CDATA simulationInputText = new CDATA(simulationInputStringWriter.getBuffer().toString());
        modelElement.addContent(simulationInputText);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new OptimizationException("failed to create fv input file: " + e.getMessage());
    }
    return modelElement;
}
Also used : OptimizationException(cbit.vcell.opt.OptimizationException) KeyValue(org.vcell.util.document.KeyValue) SimulationTask(cbit.vcell.messaging.server.SimulationTask) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) Element(org.jdom.Element) FiniteVolumeFileWriter(cbit.vcell.solvers.FiniteVolumeFileWriter) TimeStep(cbit.vcell.solver.TimeStep) StringWriter(java.io.StringWriter) SpatialReferenceData(cbit.vcell.opt.SpatialReferenceData) SimulationJob(cbit.vcell.solver.SimulationJob) PrintWriter(java.io.PrintWriter) Constraint(cbit.vcell.opt.Constraint) OptimizationException(cbit.vcell.opt.OptimizationException) XMLStreamException(javax.xml.stream.XMLStreamException) SBMLException(org.sbml.jsbml.SBMLException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) SolverException(cbit.vcell.solver.SolverException) CDATA(org.jdom.CDATA)

Aggregations

SolverException (cbit.vcell.solver.SolverException)53 ExpressionException (cbit.vcell.parser.ExpressionException)28 IOException (java.io.IOException)23 MathException (cbit.vcell.math.MathException)20 PrintWriter (java.io.PrintWriter)16 File (java.io.File)15 Element (org.jdom.Element)13 SolverStatus (cbit.vcell.solver.server.SolverStatus)10 DataAccessException (org.vcell.util.DataAccessException)9 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)8 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)8 Variable (cbit.vcell.math.Variable)8 FileNotFoundException (java.io.FileNotFoundException)8 ISize (org.vcell.util.ISize)8 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)7 ImageException (cbit.image.ImageException)6 GeometryException (cbit.vcell.geometry.GeometryException)6 Expression (cbit.vcell.parser.Expression)5 SubVolume (cbit.vcell.geometry.SubVolume)4 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)4