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;
}
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;
}
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;
}
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;
}
}
}
}
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;
}
Aggregations