Search in sources :

Example 21 with GeometryClass

use of cbit.vcell.geometry.GeometryClass 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 22 with GeometryClass

use of cbit.vcell.geometry.GeometryClass 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)

Example 23 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class OutputFunctionsPanel method getPossibleGeometryClassesAndVariableTypes.

private ArrayList<Object> getPossibleGeometryClassesAndVariableTypes(Expression expr) throws ExpressionException, InconsistentDomainException {
    SimulationOwner simulationOwner = getSimulationWorkspace().getSimulationOwner();
    MathDescription mathDescription = simulationOwner.getMathDescription();
    boolean bSpatial = simulationOwner.getGeometry().getDimension() > 0;
    if (!bSpatial) {
        return null;
    }
    // making sure that output function is not direct function of constant.
    expr.bindExpression(outputFunctionContext);
    // here use math description as symbol table because we allow
    // new expression itself to be function of constant.
    expr = MathUtilities.substituteFunctions(expr, outputFunctionContext).flatten();
    String[] symbols = expr.getSymbols();
    // using bit operation to determine whether geometry classes for symbols in expression are vol, membrane or both. 01 => vol; 10 => membrane; 11 => both
    int gatherFlag = 0;
    Set<GeometryClass> geomClassSet = new HashSet<GeometryClass>();
    ArrayList<Object> objectsList = new ArrayList<Object>();
    boolean bHasVariable = false;
    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] = VariableType.VOLUME;
            } else {
                Variable var = mathDescription.getVariable(symbols[i]);
                if (var == null) {
                    var = mathDescription.getPostProcessingBlock().getDataGenerator(symbols[i]);
                }
                varTypes[i] = VariableType.getVariableType(var);
                bHasVariable = true;
                if (var.getDomain() != null) {
                    GeometryClass varGeoClass = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
                    geomClassSet.add(varGeoClass);
                    if (varGeoClass instanceof SubVolume) {
                        gatherFlag |= 1;
                    } else if (varGeoClass instanceof SurfaceClass) {
                        gatherFlag |= 2;
                    }
                }
                if (varTypes[i].equals(VariableType.POSTPROCESSING)) {
                    gatherFlag |= 4;
                }
            }
        }
    }
    if (gatherFlag > 4) {
        throw new RuntimeException("cannot mix post processing variables with membrane or volume variables");
    }
    int numGeomClasses = geomClassSet.size();
    if (numGeomClasses == 0) {
        if (bHasVariable) {
            // if there are no variables (like built in function, vcRegionArea), check with flattened expression to find out the variable type of the new expression
            Function flattenedFunction = new Function(getFunctionNameTextField().getText(), expr, null);
            flattenedFunction.bind(outputFunctionContext);
            VariableType newVarType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, simulationOwner.getMathDescription(), symbols, varTypes, bSpatial);
            objectsList.add(newVarType);
        } else {
            objectsList.add(VariableType.VOLUME);
            objectsList.add(VariableType.MEMBRANE);
        }
    } else if (numGeomClasses == 1) {
        objectsList.add(geomClassSet.iterator().next());
        if (gatherFlag == 1) {
            objectsList.add(VariableType.MEMBRANE);
        }
    } else if (gatherFlag == 1) {
        // all volumes
        if (numGeomClasses == 2) {
            // all subvolumes, if there are only 2, check for adjacency.
            GeometryClass[] geomClassesArray = geomClassSet.toArray(new GeometryClass[0]);
            SurfaceClass sc = simulationOwner.getGeometry().getGeometrySurfaceDescription().getSurfaceClass((SubVolume) geomClassesArray[0], (SubVolume) geomClassesArray[1]);
            if (sc != null) {
                objectsList.add(sc);
            }
        }
        objectsList.add(VariableType.VOLUME);
    } else if (gatherFlag == 2) {
        // all membranes
        objectsList.add(VariableType.MEMBRANE);
    } else if (gatherFlag == 3) {
        // mixed - both vols and membranes
        // add only membranes?
        objectsList.add(VariableType.MEMBRANE);
    }
    return objectsList;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Variable(cbit.vcell.math.Variable) VariableType(cbit.vcell.math.VariableType) MathDescription(cbit.vcell.math.MathDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ArrayList(java.util.ArrayList) SimulationOwner(cbit.vcell.solver.SimulationOwner) Function(cbit.vcell.math.Function) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) SubVolume(cbit.vcell.geometry.SubVolume) HashSet(java.util.HashSet)

Example 24 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class StructureMappingTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if (rowIndex < 0 || rowIndex >= getRowCount()) {
        throw new RuntimeException("StructureMappingTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
    }
    if (columnIndex < 0 || columnIndex >= getColumnCount()) {
        throw new RuntimeException("StructureMappingTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
    }
    StructureMapping structureMapping = getValueAt(rowIndex);
    Structure structure = structureMapping.getStructure();
    if (bNonSpatial) {
        switch(columnIndex) {
            case NONSPATIAL_COLUMN_SIZE:
                {
                    try {
                        Expression exp = null;
                        if (aValue instanceof String) {
                            exp = new Expression((String) aValue);
                        } else if (aValue instanceof Double) {
                            exp = new Expression(((Double) aValue).doubleValue());
                        }
                        // if the input volumn is null, leave it as it was.
                        if (exp != null) {
                            // for old ode model, once one size is input, solve the rest.                                                                                                          if it is unnamed compartment(the only one), we don't need to solve anything
                            if (!getGeometryContext().getSimulationContext().isStoch() && getGeometryContext().isAllSizeSpecifiedNull() && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().getStructureMappings().length > 1) {
                                structureMapping.getSizeParameter().setExpression(exp);
                                double size;
                                try {
                                    size = exp.evaluateConstant();
                                    VCUnitDefinition volumeUnit = getGeometryContext().getSimulationContext().getModel().getUnitSystem().getVolumeUnit();
                                    StructureSizeSolver.updateAbsoluteStructureSizes(getGeometryContext().getSimulationContext(), structure, size, volumeUnit);
                                    fireTableRowsUpdated(0, getRowCount());
                                } catch (ExpressionException ex) {
                                    ex.printStackTrace(System.out);
                                    PopupGenerator.showErrorDialog(ownerTable, "Size of Feature " + structure.getName() + " can not be solved as constant!");
                                } catch (Exception ex) {
                                    ex.printStackTrace(System.out);
                                    PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
                                }
                            } else {
                                structureMapping.getSizeParameter().setExpression(exp);
                                // set fraction in stoch math description, because these might be used when copy from stoch app to ode app.
                                if (getGeometryContext().isAllSizeSpecifiedPositive()) /*&& !getGeometryContext().getSimulationContext().isStoch()*/
                                {
                                    try {
                                        StructureSizeSolver.updateRelativeStructureSizes(getGeometryContext().getSimulationContext());
                                    } catch (Exception ex) {
                                        ex.printStackTrace(System.out);
                                        PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
                                    }
                                }
                            }
                        }
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                    }
                    break;
                }
        }
    } else {
        switch(columnIndex) {
            case SPATIAL_COLUMN_SUBDOMAIN:
                {
                    GeometryClass geometryClass = null;
                    if (aValue instanceof String) {
                        String svname = (String) aValue;
                        geometryClass = getGeometryContext().getGeometry().getGeometryClass(svname);
                    } else if (aValue instanceof GeometryClass) {
                        geometryClass = (GeometryClass) aValue;
                    }
                    if (geometryClass != null) {
                        try {
                            getGeometryContext().assignStructure(structure, geometryClass);
                        } catch (PropertyVetoException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        } catch (IllegalMappingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        } catch (MappingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        }
                    }
                    break;
                }
            case SPATIAL_COLUMN_SIZERATIO:
                try {
                    Expression exp = null;
                    if (aValue instanceof String) {
                        exp = new Expression((String) aValue);
                    } else if (aValue instanceof Double) {
                        exp = new Expression(((Double) aValue).doubleValue());
                    }
                    if (exp != null) {
                        structureMapping.getUnitSizeParameter().setExpression(exp);
                        StructureSizeSolver.updateUnitStructureSizes(getGeometryContext().getSimulationContext(), structureMapping.getGeometryClass());
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                }
                break;
            case SPATIAL_COLUMN_X_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeXm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_X_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeXp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Y_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeYm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Y_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeYp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Z_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeZm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Z_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeZp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
        }
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) StructureMapping(cbit.vcell.mapping.StructureMapping) ExpressionException(cbit.vcell.parser.ExpressionException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Structure(cbit.vcell.model.Structure)

Example 25 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class StructureMappingTableModel method isCellEditable.

/**
 * Insert the method's description here.
 * Creation date: (2/24/01 12:27:46 AM)
 * @return boolean
 * @param rowIndex int
 * @param columnIndex int
 */
public boolean isCellEditable(int rowIndex, int columnIndex) {
    if (getGeometryContext() == null) {
        return false;
    }
    StructureMapping sm = getGeometryContext().getStructureMapping(rowIndex);
    if (bNonSpatial) {
        if (columnIndex == NONSPATIAL_COLUMN_SIZE) {
            // feature size are editable
            return true;
        }
        return false;
    } else {
        // 
        if (columnIndex == SPATIAL_COLUMN_SUBDOMAIN) {
            return ((sm instanceof FeatureMapping) || (sm instanceof MembraneMapping));
        }
        if (columnIndex == SPATIAL_COLUMN_SIZERATIO) {
            GeometryClass gc = sm.getGeometryClass();
            StructureMapping[] structureMappings = getGeometryContext().getStructureMappings(gc);
            boolean bDimensionless = sm.getUnitSizeParameter() != null && sm.getUnitSizeParameter().getUnitDefinition() != null && sm.getUnitSizeParameter().getUnitDefinition().isEquivalent(getGeometryContext().getModel().getUnitSystem().getInstance_DIMENSIONLESS());
            return (structureMappings != null && structureMappings.length > 1) || !bDimensionless;
        }
        // some boundary conditions are editable
        if ((columnIndex >= SPATIAL_COLUMN_X_MINUS) && (columnIndex <= SPATIAL_COLUMN_Z_PLUS)) {
            if (sm.getGeometryClass() instanceof SurfaceClass) {
                return false;
            }
            return true;
        }
    }
    return false;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) MembraneMapping(cbit.vcell.mapping.MembraneMapping) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SurfaceClass(cbit.vcell.geometry.SurfaceClass) StructureMapping(cbit.vcell.mapping.StructureMapping)

Aggregations

GeometryClass (cbit.vcell.geometry.GeometryClass)43 SubVolume (cbit.vcell.geometry.SubVolume)21 SurfaceClass (cbit.vcell.geometry.SurfaceClass)19 Expression (cbit.vcell.parser.Expression)18 ExpressionException (cbit.vcell.parser.ExpressionException)14 PropertyVetoException (java.beans.PropertyVetoException)13 Structure (cbit.vcell.model.Structure)12 StructureMapping (cbit.vcell.mapping.StructureMapping)8 MathDescription (cbit.vcell.math.MathDescription)7 MathException (cbit.vcell.math.MathException)7 Variable (cbit.vcell.math.Variable)7 SpeciesContext (cbit.vcell.model.SpeciesContext)7 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)7 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)7 MappingException (cbit.vcell.mapping.MappingException)6 Domain (cbit.vcell.math.Variable.Domain)6 ModelException (cbit.vcell.model.ModelException)6 Parameter (cbit.vcell.model.Parameter)6 ArrayList (java.util.ArrayList)6 Geometry (cbit.vcell.geometry.Geometry)5