use of cbit.vcell.math.InconsistentDomainException in project vcell by virtualcell.
the class SimulationSymbolTable method getFunctionVariableType.
/**
* Insert the method's description here.
* Creation date: (2/19/2004 11:17:15 AM)
* @return cbit.vcell.simdata.VariableType
* @param function cbit.vcell.math.Function
* @param variableNames java.lang.String[]
* @param variableTypes cbit.vcell.simdata.VariableType[]
*/
public static VariableType getFunctionVariableType(Function function, MathDescription mathDescription, String[] variableNames, VariableType[] variableTypes, boolean isSpatial) throws InconsistentDomainException {
if (!isSpatial) {
return VariableType.NONSPATIAL;
}
VariableType domainFuncType = null;
// initial guess, restrict variable type to be consistent with domain.
if (function.getDomain() != null) {
String domainName = function.getDomain().getName();
if (mathDescription != null) {
SubDomain subdomain = mathDescription.getSubDomain(domainName);
if (subdomain instanceof MembraneSubDomain) {
domainFuncType = VariableType.MEMBRANE_REGION;
} else {
domainFuncType = VariableType.VOLUME_REGION;
}
}
}
Expression exp = function.getExpression();
String[] symbols = exp.getSymbols();
ArrayList<VariableType> varTypeList = new ArrayList<VariableType>();
boolean bExplicitFunctionOfSpace = false;
if (symbols != null) {
for (int j = 0; j < symbols.length; j++) {
if (symbols[j].equals(ReservedVariable.X.getName()) || symbols[j].equals(ReservedVariable.Y.getName()) || symbols[j].equals(ReservedVariable.Z.getName())) {
bExplicitFunctionOfSpace = true;
continue;
}
for (int k = 0; k < variableNames.length; k++) {
if (symbols[j].equals(variableNames[k])) {
varTypeList.add(variableTypes[k]);
break;
} else if (symbols[j].equals(variableNames[k] + InsideVariable.INSIDE_VARIABLE_SUFFIX) || symbols[j].equals(variableNames[k] + OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
if (variableTypes[k].equals(VariableType.VOLUME)) {
varTypeList.add(VariableType.MEMBRANE);
} else if (variableTypes[k].equals(VariableType.VOLUME_REGION)) {
varTypeList.add(VariableType.MEMBRANE_REGION);
}
break;
}
}
}
}
// Size Functions
Set<FunctionInvocation> sizeFunctionInvocationSet = SolverUtilities.getSizeFunctionInvocations(function.getExpression());
for (FunctionInvocation fi : sizeFunctionInvocationSet) {
String functionName = fi.getFunctionName();
if (functionName.equals(MathFunctionDefinitions.Function_regionArea_current.getFunctionName())) {
varTypeList.add(VariableType.MEMBRANE_REGION);
} else if (functionName.equals(MathFunctionDefinitions.Function_regionVolume_current.getFunctionName())) {
varTypeList.add(VariableType.VOLUME_REGION);
}
}
// Membrane Normal Functions
FunctionInvocation[] functionInvocations = function.getExpression().getFunctionInvocations(null);
for (FunctionInvocation fi : functionInvocations) {
String functionName = fi.getFunctionName();
if (functionName.equals(MathFunctionDefinitions.Function_normalX.getFunctionName()) || functionName.equals(MathFunctionDefinitions.Function_normalY.getFunctionName())) {
varTypeList.add(VariableType.MEMBRANE);
}
}
FieldFunctionArguments[] fieldFuncArgs = FieldUtilities.getFieldFunctionArguments(function.getExpression());
if (fieldFuncArgs != null && fieldFuncArgs.length > 0) {
varTypeList.add(fieldFuncArgs[0].getVariableType());
}
VariableType funcType = domainFuncType;
for (VariableType vt : varTypeList) {
if (funcType == null) {
funcType = vt;
} else {
//
if (vt.isExpansionOf(funcType)) {
funcType = vt;
} else if (vt.equals(VariableType.VOLUME)) {
if (funcType.equals(VariableType.MEMBRANE_REGION)) {
funcType = VariableType.MEMBRANE;
}
} else if (vt.equals(VariableType.VOLUME_REGION)) {
} else if (vt.equals(VariableType.MEMBRANE)) {
if (domainFuncType != null && domainFuncType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
throw new InconsistentDomainException("Function '" + function.getName() + "' defined on a volume subdomain '" + function.getDomain().getName() + "' references a variable or a function defined on a membrane subdomain");
}
} else if (vt.equals(VariableType.MEMBRANE_REGION)) {
if (funcType.equals(VariableType.VOLUME)) {
if (domainFuncType != null && domainFuncType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
throw new InconsistentDomainException("Function '" + function.getName() + "' defined on '" + function.getDomain().getName() + "' references a size function defined on a membrane");
}
funcType = VariableType.MEMBRANE;
} else if (funcType.equals(VariableType.VOLUME_REGION)) {
if (domainFuncType != null && domainFuncType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
throw new InconsistentDomainException("Function '" + function.getName() + "' defined on '" + function.getDomain().getName() + "' references a size function defined on a membrane");
}
funcType = VariableType.MEMBRANE_REGION;
}
} else if (vt.incompatibleWith(funcType)) {
throw new InconsistentDomainException("Function domains conflict between variable domains '" + vt.getDefaultLabel() + "' and '" + funcType.getDefaultLabel() + " for function " + function.getName());
}
}
}
//
if (funcType != null && bExplicitFunctionOfSpace) {
if (funcType.equals(VariableType.MEMBRANE_REGION)) {
funcType = VariableType.MEMBRANE;
} else if (funcType.equals(VariableType.VOLUME_REGION)) {
funcType = VariableType.VOLUME;
} else if (funcType.equals(VariableType.CONTOUR_REGION)) {
funcType = VariableType.CONTOUR;
}
}
if (funcType == null) {
// no knowledge from expression, default variable type
return VariableType.VOLUME;
}
return funcType;
}
use of cbit.vcell.math.InconsistentDomainException in project vcell by virtualcell.
the class OutputFunctionContext method propertyChange.
public void propertyChange(java.beans.PropertyChangeEvent event) {
if (event.getSource() == simulationOwner && event.getPropertyName().equals("mathDescription")) {
rebindAll();
}
if (event.getPropertyName().equals("geometry")) {
Geometry oldGeometry = (Geometry) event.getOldValue();
Geometry newGeometry = (Geometry) event.getNewValue();
// changing from ode to pde
if (oldGeometry != null && oldGeometry.getDimension() == 0 && newGeometry.getDimension() > 0) {
ArrayList<AnnotatedFunction> newFuncList = new ArrayList<AnnotatedFunction>();
for (AnnotatedFunction function : outputFunctionsList) {
try {
Expression newexp = new Expression(function.getExpression());
// 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.
MathDescription mathDescription = getSimulationOwner().getMathDescription();
newexp = MathUtilities.substituteFunctions(newexp, mathDescription).flatten();
VariableType newFuncType = VariableType.VOLUME;
String[] symbols = newexp.getSymbols();
if (symbols != null) {
// figure out the function type
VariableType[] varTypes = new VariableType[symbols.length];
for (int i = 0; i < symbols.length; i++) {
Variable var = mathDescription.getVariable(symbols[i]);
varTypes[i] = VariableType.getVariableType(var);
}
// check with flattened expression to find out the variable type of the new expression
Function flattenedFunction = new Function(function.getName(), newexp, function.getDomain());
newFuncType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, getSimulationOwner().getMathDescription(), symbols, varTypes, true);
}
AnnotatedFunction newFunc = new AnnotatedFunction(function.getName(), function.getExpression(), function.getDomain(), "", newFuncType, FunctionCategory.OUTPUTFUNCTION);
newFuncList.add(newFunc);
newFunc.bind(this);
} catch (ExpressionException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
} catch (InconsistentDomainException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
try {
setOutputFunctions0(newFuncList);
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
}
}
use of cbit.vcell.math.InconsistentDomainException in project vcell by virtualcell.
the class OutputFunctionsListTableModel method setValueAt.
/**
* Insert the method's description here.
* Creation date: (7/12/2004 2:01:23 PM)
* @param aValue java.lang.Object
* @param rowIndex int
* @param columnIndex int
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
AnnotatedFunction outputFunction = getValueAt(rowIndex);
switch(columnIndex) {
case COLUMN_OUTPUTFN_EXPRESSION:
{
try {
Expression exp = new Expression((String) aValue);
if (exp.compareEqual(outputFunction.getExpression())) {
return;
}
exp.bindExpression(outputFunctionContext);
VariableType vt = outputFunctionContext.computeFunctionTypeWRTExpression(outputFunction, exp);
if (!vt.compareEqual(outputFunction.getFunctionType())) {
}
outputFunction.setExpression(exp);
fireTableRowsUpdated(rowIndex, rowIndex);
outputFunctionContext.firePropertyChange("outputFunctions", null, outputFunctionContext.getOutputFunctionsList());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
} catch (InconsistentDomainException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
}
break;
}
case COLUMN_OUTPUTFN_VARIABLETYPE:
{
for (int i = 0; i < availableGeometryClasses.length; i++) {
if (availableGeometryClasses[i].getName().equals(aValue)) {
Domain newDomain = new Domain(availableGeometryClasses[i]);
outputFunction.setDomain(newDomain);
fireTableRowsUpdated(rowIndex, rowIndex);
outputFunctionContext.firePropertyChange("outputFunctions", null, outputFunctionContext.getOutputFunctionsList());
break;
}
}
break;
}
}
}
Aggregations