Search in sources :

Example 46 with Domain

use of cbit.vcell.math.Variable.Domain 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 47 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class FunctionFileGenerator method readFunctionsFile.

/**
 * This method was created in VisualAge.
 * @param logFile java.io.File
 */
public static synchronized Vector<AnnotatedFunction> readFunctionsFile(File functionsFile, String simJobID) throws java.io.FileNotFoundException, java.io.IOException {
    // Check if file exists
    if (!functionsFile.exists()) {
        throw new java.io.FileNotFoundException("functions file " + functionsFile.getPath() + " not found");
    }
    // 
    // Read characters from functionFile into character array and transfer into string buffer.
    // 
    Vector<AnnotatedFunction> annotatedFunctionsVector = new Vector<AnnotatedFunction>();
    long fnFileLength = functionsFile.length();
    StringBuffer stringBuffer = new StringBuffer();
    FileInputStream is = null;
    try {
        is = new FileInputStream(functionsFile);
        InputStreamReader reader = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(reader);
        char[] charArray = new char[10000];
        while (true) {
            int numRead = br.read(charArray, 0, charArray.length);
            if (numRead > 0) {
                stringBuffer.append(charArray, 0, numRead);
            } else if (numRead == -1) {
                break;
            }
        }
    } finally {
        if (is != null) {
            is.close();
        }
    }
    if (stringBuffer.length() != fnFileLength) {
        System.out.println("<<<SYSOUT ALERT>>>SimulationData.readFunctionFile(), read " + stringBuffer.length() + " of " + fnFileLength + " bytes of input file");
    }
    String newLineDelimiters = "\n\r";
    StringTokenizer lineTokenizer = new StringTokenizer(stringBuffer.toString(), newLineDelimiters);
    String token1 = new String("");
    int j = 0;
    // 
    // Each token is a line representing a function name and function expression,
    // separated by a semicolon
    // 
    HashSet<String> allSymbols = new HashSet<String>();
    while (lineTokenizer.hasMoreTokens()) {
        token1 = lineTokenizer.nextToken();
        FunctionFileGenerator.FuncFileLineInfo funcFileLineInfo = readFunctionLine(token1);
        if (funcFileLineInfo != null && funcFileLineInfo.functionName != null && funcFileLineInfo.functionExpr != null && funcFileLineInfo.funcVarType != null) {
            Expression functionExpr = null;
            try {
                functionExpr = new Expression(funcFileLineInfo.functionExpr);
                functionExpr = MathFunctionDefinitions.fixFunctionSyntax(functionExpr);
            } catch (cbit.vcell.parser.ExpressionException e) {
                throw new RuntimeException("Error in reading expression '" + funcFileLineInfo.functionExpr + "' for function \"" + funcFileLineInfo.functionName + "\"");
            }
            Domain domain = Variable.getDomainFromCombinedIdentifier(funcFileLineInfo.functionName);
            String funcName = Variable.getNameFromCombinedIdentifier(funcFileLineInfo.functionName);
            AnnotatedFunction annotatedFunc = new AnnotatedFunction(funcName, functionExpr, domain, funcFileLineInfo.errorString, funcFileLineInfo.funcVarType, funcFileLineInfo.funcIsUserDefined ? FunctionCategory.OLDUSERDEFINED : FunctionCategory.PREDEFINED);
            allSymbols.add(annotatedFunc.getName());
            String[] symbols = annotatedFunc.getExpression().getSymbols();
            if (symbols != null) {
                allSymbols.addAll(Arrays.asList(symbols));
            }
            annotatedFunctionsVector.addElement(annotatedFunc);
        }
        j++;
    }
    if (simJobID != null && simJobID.trim().length() > 0) {
        SimpleSymbolTable simpleSymbolTable = new SimpleSymbolTable(allSymbols.toArray(new String[0]));
        // bind
        for (AnnotatedFunction func : annotatedFunctionsVector) {
            if (func.isOldUserDefined()) {
                try {
                    func.bind(simpleSymbolTable);
                } catch (ExpressionBindingException e) {
                    e.printStackTrace();
                }
            }
        }
        // rename symbol table entries
        for (int i = 0; i < annotatedFunctionsVector.size(); i++) {
            AnnotatedFunction func = annotatedFunctionsVector.get(i);
            if (func.isOldUserDefined()) {
                SimpleSymbolTableEntry ste = (SimpleSymbolTableEntry) simpleSymbolTable.getEntry(func.getName());
                ste.setName(simJobID + "_" + func.getName());
            }
        }
        // rename in the expressions
        for (int i = 0; i < annotatedFunctionsVector.size(); i++) {
            AnnotatedFunction func = annotatedFunctionsVector.get(i);
            if (func.isOldUserDefined()) {
                try {
                    Expression exp = func.getExpression().renameBoundSymbols(simpleSymbolTable.getNameScope());
                    AnnotatedFunction newfunc = new AnnotatedFunction(simJobID + "_" + func.getName(), exp, func.getDomain(), func.getName(), func.getErrorString(), func.getFunctionType(), FunctionCategory.OLDUSERDEFINED);
                    annotatedFunctionsVector.set(i, newfunc);
                } catch (ExpressionBindingException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return annotatedFunctionsVector;
}
Also used : SimpleSymbolTableEntry(cbit.vcell.parser.SimpleSymbolTable.SimpleSymbolTableEntry) Vector(java.util.Vector) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) HashSet(java.util.HashSet) InputStreamReader(java.io.InputStreamReader) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) FileInputStream(java.io.FileInputStream) StringTokenizer(java.util.StringTokenizer) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Expression(cbit.vcell.parser.Expression) BufferedReader(java.io.BufferedReader) Domain(cbit.vcell.math.Variable.Domain)

Example 48 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class XmlReader method getOutputFunction.

private AnnotatedFunction getOutputFunction(Element param) throws XmlParseException {
    // get attributes
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String temp = param.getText();
    Expression exp = unMangleExpression(temp);
    String errStr = unMangle(param.getAttributeValue(XMLTags.ErrorStringTag));
    VariableType funcType = VariableType.UNKNOWN;
    String funcTypeAttr = param.getAttributeValue(XMLTags.FunctionTypeTag);
    if (funcTypeAttr != null) {
        String funcTypeStr = unMangle(funcTypeAttr);
        funcType = VariableType.getVariableTypeFromVariableTypeName(funcTypeStr);
    }
    // -- create new AnnotatedFunction --
    String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    AnnotatedFunction function = new AnnotatedFunction(name, exp, domain, errStr, funcType, FunctionCategory.OUTPUTFUNCTION);
    return function;
}
Also used : VariableType(cbit.vcell.math.VariableType) Expression(cbit.vcell.parser.Expression) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 49 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class XmlReader method getMembraneRegionVariable.

/**
 * This method returns a MembraneRegionVariable object from a XML Element.
 * Creation date: (5/16/2001 2:56:34 PM)
 * @return cbit.vcell.math.MembraneRegionVariable
 * @param param org.jdom.Element
 */
private MembraneRegionVariable getMembraneRegionVariable(Element param) {
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    // -- create new MembraneRegionVariable object
    MembraneRegionVariable memRegVariable = new MembraneRegionVariable(name, domain);
    transcribeComments(param, memRegVariable);
    return memRegVariable;
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain)

Example 50 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class CellQuanVCTranslator method addCompartmentSubDomain.

/**
 * 	addCompartmentSubDomain : we pick the variable name by reading through the mathML.
 * 	Redundancy in variable name with the volume variable?
 */
protected void addCompartmentSubDomain() throws Exception {
    String csdName = sRoot.getAttributeValue(CELLMLTags.name, sAttNamespace);
    CompartmentSubDomain csd = new CompartmentSubDomain(csdName, CompartmentSubDomain.NON_SPATIAL_PRIORITY);
    Iterator<?> compElementIter = sRoot.getChildren(CELLMLTags.COMPONENT, sNamespace).iterator();
    // JDOMTreeWalker walker = new JDOMTreeWalker(sRoot, new ElementFilter(CELLMLTags.COMPONENT));
    Element comp, math;
    String compName, varName, mangledName;
    while (compElementIter.hasNext()) {
        comp = (Element) compElementIter.next();
        compName = comp.getAttributeValue(CELLMLTags.name, sAttNamespace);
        @SuppressWarnings("unchecked") Iterator<Element> mathIter = comp.getChildren(CELLMLTags.MATH, mathns).iterator();
        while (mathIter.hasNext()) {
            math = mathIter.next();
            Element apply, apply2, apply3, ci;
            // allow multiple 'apply' children.
            @SuppressWarnings("unchecked") Iterator<Element> applyIter = math.getChildren(MathMLTags.APPLY, mathns).iterator();
            while (applyIter.hasNext()) {
                apply = applyIter.next();
                @SuppressWarnings("unchecked") ArrayList<Element> list = new ArrayList<Element>(apply.getChildren());
                if (list.size() < 3)
                    continue;
                if (!(list.get(0)).getName().equals(MathMLTags.EQUAL))
                    continue;
                apply2 = list.get(1);
                if (!apply2.getName().equals(MathMLTags.APPLY))
                    continue;
                @SuppressWarnings("unchecked") ArrayList<Element> list2 = new ArrayList<Element>(apply2.getChildren());
                if (list2.size() < 3)
                    continue;
                if (!(list2.get(0)).getName().equals(MathMLTags.DIFFERENTIAL))
                    continue;
                // skip the time variable
                ci = list2.get(2);
                varName = ci.getTextTrim();
                // can be a constant
                apply3 = list.get(2);
                mangledName = nm.getMangledName(compName, varName);
                Element trimmedMath = new Element(CELLMLTags.MATH, mathns).addContent(apply3.detach());
                fixMathMLBug(trimmedMath);
                Expression rateExp = null;
                try {
                    rateExp = (new ExpressionMathMLParser(null)).fromMathML(trimmedMath);
                    rateExp = processMathExp(comp, rateExp);
                    rateExp = rateExp.flatten();
                    nl.mangleString(rateExp.infix());
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    throw new RuntimeException(e.getMessage());
                }
                Expression initExp = new Expression(getInitial(comp, varName));
                Domain domain = null;
                OdeEquation ode = new OdeEquation(new VolVariable(mangledName, domain), initExp, rateExp);
                csd.addEquation(ode);
            }
        }
    }
    mathDescription.addSubDomain(csd);
}
Also used : VolVariable(cbit.vcell.math.VolVariable) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ExpressionMathMLParser(cbit.vcell.parser.ExpressionMathMLParser) ExpressionException(cbit.vcell.parser.ExpressionException) OdeEquation(cbit.vcell.math.OdeEquation) Expression(cbit.vcell.parser.Expression) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) Domain(cbit.vcell.math.Variable.Domain)

Aggregations

Domain (cbit.vcell.math.Variable.Domain)54 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)35 Expression (cbit.vcell.parser.Expression)34 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)28 PointSubDomain (cbit.vcell.math.PointSubDomain)22 FilamentSubDomain (cbit.vcell.math.FilamentSubDomain)19 VolVariable (cbit.vcell.math.VolVariable)15 ExpressionException (cbit.vcell.parser.ExpressionException)14 Function (cbit.vcell.math.Function)13 SubDomain (cbit.vcell.math.SubDomain)13 Variable (cbit.vcell.math.Variable)13 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)10 Element (org.jdom.Element)10 Constant (cbit.vcell.math.Constant)9 MemVariable (cbit.vcell.math.MemVariable)9 VariableHash (cbit.vcell.math.VariableHash)9 VariableType (cbit.vcell.math.VariableType)9 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)8 GeometryClass (cbit.vcell.geometry.GeometryClass)7 SubVolume (cbit.vcell.geometry.SubVolume)7