Search in sources :

Example 51 with Variable

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

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

the class OutputFunctionContext method getAutoCompleteSymbolFilter.

public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter() {
    AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {

        public boolean accept(SymbolTableEntry ste) {
            MathDescription math = getSimulationOwner().getMathDescription();
            Variable var = math.getVariable(ste.getName());
            return (!(var instanceof InsideVariable || var instanceof OutsideVariable));
        }

        public boolean acceptFunction(String funcName) {
            return true;
        }
    };
    return stef;
}
Also used : AutoCompleteSymbolFilter(cbit.vcell.parser.AutoCompleteSymbolFilter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) OutsideVariable(cbit.vcell.math.OutsideVariable) InsideVariable(cbit.vcell.math.InsideVariable)

Example 53 with Variable

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

the class OutputFunctionContext method getEntries.

// public abstract void validateNamingConflicts(String symbolDescription, Class<?> newSymbolClass, String newSymbolName, PropertyChangeEvent e)  throws PropertyVetoException ;
public void getEntries(Map<String, SymbolTableEntry> entryMap) {
    // add all valid entries (variables) from mathdescription
    MathDescription mathDescription = simulationOwner.getMathDescription();
    if (mathDescription != null) {
        Enumeration<Variable> varEnum = mathDescription.getVariables();
        while (varEnum.hasMoreElements()) {
            Variable var = varEnum.nextElement();
            if (!(var instanceof PseudoConstant) && !(var instanceof Constant)) {
                entryMap.put(var.getName(), var);
            }
        }
        for (DataGenerator dataGenerator : mathDescription.getPostProcessingBlock().getDataGeneratorList()) {
            entryMap.put(dataGenerator.getName(), dataGenerator);
        }
    }
    entryMap.put(ReservedVariable.TIME.getName(), ReservedVariable.TIME);
    int dimension = mathDescription.getGeometry().getDimension();
    if (dimension > 0) {
        entryMap.put(ReservedVariable.X.getName(), ReservedVariable.X);
        if (dimension > 1) {
            entryMap.put(ReservedVariable.Y.getName(), ReservedVariable.Y);
            if (dimension > 2) {
                entryMap.put(ReservedVariable.Z.getName(), ReservedVariable.Z);
            }
        }
    }
    // then add list of output functions.
    for (SymbolTableEntry ste : outputFunctionsList) {
        entryMap.put(ste.getName(), ste);
    }
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) PseudoConstant(cbit.vcell.math.PseudoConstant) PseudoConstant(cbit.vcell.math.PseudoConstant) DataGenerator(cbit.vcell.math.DataGenerator)

Example 54 with Variable

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

the class OutputFunctionContext method getAutoCompleteSymbolFilter.

public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter(final Domain functionDomain) {
    AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {

        public boolean accept(SymbolTableEntry ste) {
            if (simulationOwner.getGeometry().getDimension() > 0) {
                if (functionDomain == null) {
                    return true;
                }
                if (ste.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX) || ste.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    return false;
                }
                if (ste instanceof ReservedVariable) {
                    return true;
                }
                if (ste instanceof AnnotatedFunction) {
                    return functionDomain.compareEqual(((AnnotatedFunction) ste).getDomain());
                }
                if (ste instanceof Variable) {
                    Variable var = (Variable) ste;
                    if (var.getDomain() == null) {
                        return true;
                    }
                    GeometryClass gc = simulationOwner.getGeometry().getGeometryClass(functionDomain.getName());
                    GeometryClass vargc = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
                    if (gc instanceof SurfaceClass && vargc instanceof SubVolume) {
                        if (((SurfaceClass) gc).isAdjacentTo((SubVolume) vargc)) {
                            return true;
                        } else {
                            return false;
                        }
                    } else {
                        return var.getDomain().compareEqual(functionDomain);
                    }
                }
            }
            return true;
        }

        public boolean acceptFunction(String funcName) {
            return true;
        }
    };
    return stef;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) AutoCompleteSymbolFilter(cbit.vcell.parser.AutoCompleteSymbolFilter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume)

Example 55 with Variable

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

the class OutputFunctionContext method computeFunctionTypeWRTExpression.

// check if the new expression is valid for outputFunction of functionType
public VariableType computeFunctionTypeWRTExpression(AnnotatedFunction outputFunction, Expression exp) throws ExpressionException, InconsistentDomainException {
    MathDescription mathDescription = getSimulationOwner().getMathDescription();
    boolean bSpatial = getSimulationOwner().getGeometry().getDimension() > 0;
    if (!bSpatial) {
        return VariableType.NONSPATIAL;
    }
    Expression newexp = new Expression(exp);
    // making sure that output function is not direct function of constant.
    newexp.bindExpression(this);
    // here use math description as symbol table because we allow
    // new expression itself to be function of constant.
    newexp = MathUtilities.substituteFunctions(newexp, this).flatten();
    String[] symbols = newexp.getSymbols();
    VariableType functionType = outputFunction.getFunctionType();
    String funcName = outputFunction.getName();
    Domain funcDomain = outputFunction.getDomain();
    VariableType[] varTypes = null;
    if (symbols != null && symbols.length > 0) {
        // making sure that new expression is defined in the same domain
        varTypes = new VariableType[symbols.length];
        for (int i = 0; i < symbols.length; i++) {
            if (ReservedMathSymbolEntries.getReservedVariableEntry(symbols[i]) != null) {
                varTypes[i] = functionType;
            } else {
                Variable var = mathDescription.getVariable(symbols[i]);
                if (var == null) {
                    var = mathDescription.getPostProcessingBlock().getDataGenerator(symbols[i]);
                }
                varTypes[i] = VariableType.getVariableType(var);
                if (funcDomain != null) {
                    if (var.getDomain() == null) {
                        // OK
                        continue;
                    }
                    GeometryClass funcGeoClass = simulationOwner.getGeometry().getGeometryClass(funcDomain.getName());
                    GeometryClass varGeoClass = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
                    if (varGeoClass instanceof SubVolume && funcGeoClass instanceof SurfaceClass) {
                        // seems ok if membrane refereces volume
                        if (!((SurfaceClass) funcGeoClass).isAdjacentTo((SubVolume) varGeoClass)) {
                            // but has to be adjacent
                            String errMsg = "'" + funcName + "' defined on Membrane '" + funcDomain.getName() + "' directly or indirectly references " + " variable '" + symbols[i] + "' defined on Volume '" + var.getDomain().getName() + " which is not adjacent to Membrane '" + funcDomain.getName() + "'.";
                            throw new ExpressionException(errMsg);
                        }
                    } else if (!var.getDomain().compareEqual(funcDomain)) {
                        String errMsg = "'" + funcName + "' defined on '" + funcDomain.getName() + "' directly or indirectly references " + " variable '" + symbols[i] + "' defined on '" + var.getDomain().getName() + ".";
                        throw new ExpressionException(errMsg);
                    }
                }
            }
        }
    }
    // if there are no variables (like built in function, vcRegionArea), check with flattened expression to find out the variable type of the new expression
    VariableDomain functionVariableDomain = functionType.getVariableDomain();
    Function flattenedFunction = new Function(funcName, newexp, funcDomain);
    flattenedFunction.bind(this);
    VariableType newVarType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, getSimulationOwner().getMathDescription(), symbols, varTypes, bSpatial);
    if (!newVarType.getVariableDomain().equals(functionVariableDomain)) {
        String errMsg = "The expression for '" + funcName + "' includes at least one " + newVarType.getVariableDomain().getName() + " variable. Please make sure that only " + functionVariableDomain.getName() + " variables are " + "referenced in " + functionVariableDomain.getName() + " output functions.";
        throw new ExpressionException(errMsg);
    }
    return newVarType;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) VariableType(cbit.vcell.math.VariableType) MathDescription(cbit.vcell.math.MathDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ExpressionException(cbit.vcell.parser.ExpressionException) Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) SubVolume(cbit.vcell.geometry.SubVolume) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) Domain(cbit.vcell.math.Variable.Domain)

Aggregations

Variable (cbit.vcell.math.Variable)108 Expression (cbit.vcell.parser.Expression)69 VolVariable (cbit.vcell.math.VolVariable)63 MemVariable (cbit.vcell.math.MemVariable)48 ReservedVariable (cbit.vcell.math.ReservedVariable)43 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)38 MathException (cbit.vcell.math.MathException)37 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)36 FilamentVariable (cbit.vcell.math.FilamentVariable)35 InsideVariable (cbit.vcell.math.InsideVariable)34 OutsideVariable (cbit.vcell.math.OutsideVariable)34 ExpressionException (cbit.vcell.parser.ExpressionException)34 Function (cbit.vcell.math.Function)32 MathDescription (cbit.vcell.math.MathDescription)32 Constant (cbit.vcell.math.Constant)31 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)29 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)25 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)24 ParticleVariable (cbit.vcell.math.ParticleVariable)24 Vector (java.util.Vector)23