use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class ReactionSpec method getEntry.
/**
* getEntry method comment.
*/
public SymbolTableEntry getEntry(java.lang.String identifierString) {
//
// look locally (in the ReactionSpec) to resolve identifier
//
SymbolTableEntry ste = getLocalEntry(identifierString);
if (ste != null) {
return ste;
}
//
// travel in namespace
//
ste = getNameScope().getExternalEntry(identifierString, this);
return ste;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class AbstractMathMapping method getIdentifierSubstitutions.
/**
* Substitutes appropriate variables for speciesContext bindings
*
* @return cbit.vcell.parser.Expression
* @param origExp cbit.vcell.parser.Expression
* @param structureMapping cbit.vcell.mapping.StructureMapping
*/
protected Expression getIdentifierSubstitutions(Expression origExp, VCUnitDefinition desiredExpUnitDef, GeometryClass geometryClass) throws ExpressionException, MappingException {
String[] symbols = origExp.getSymbols();
if (symbols == null) {
return origExp;
}
VCUnitDefinition expUnitDef = null;
try {
VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(simContext.getModel().getUnitSystem());
expUnitDef = unitEvaluator.getUnitDefinition(origExp);
if (desiredExpUnitDef == null) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
System.out.println("...........exp='" + expStr + "', desiredUnits are null");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[null], observed=[" + expUnitDef.getSymbol() + "]", Issue.SEVERITY_WARNING));
} else if (expUnitDef == null) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
System.out.println("...........exp='" + expStr + "', evaluated Units are null");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + desiredExpUnitDef.getSymbol() + "], observed=[null]", Issue.SEVERITY_WARNING));
} else if (desiredExpUnitDef.isTBD()) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
// System.out.println("...........exp='"+expStr+"', desiredUnits are ["+desiredExpUnitDef.getSymbol()+"] and expression units are ["+expUnitDef.getSymbol()+"]");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + desiredExpUnitDef.getSymbol() + "], observed=[" + expUnitDef.getSymbol() + "] for exp = " + expStr, Issue.SEVERITY_WARNING));
} else if (!desiredExpUnitDef.isEquivalent(expUnitDef) && !expUnitDef.isTBD()) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
// System.out.println("...........exp='"+expStr+"', desiredUnits are ["+desiredExpUnitDef.getSymbol()+"] and expression units are ["+expUnitDef.getSymbol()+"]");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + desiredExpUnitDef.getSymbol() + "], observed=[" + expUnitDef.getSymbol() + "] for exp = " + expStr, Issue.SEVERITY_WARNING));
}
} catch (VCUnitException e) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
System.out.println(".........exp='" + expStr + "' exception='" + e.getMessage() + "'");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + ((desiredExpUnitDef != null) ? (desiredExpUnitDef.getSymbol()) : ("null")) + "], exception=" + e.getMessage(), Issue.SEVERITY_WARNING));
} catch (ExpressionException e) {
String expStr = origExp.renameBoundSymbols(getNameScope()).infix();
System.out.println(".........exp='" + expStr + "' exception='" + e.getMessage() + "'");
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + ((desiredExpUnitDef != null) ? (desiredExpUnitDef.getSymbol()) : ("null")) + "], exception=" + e.getMessage(), Issue.SEVERITY_WARNING));
} catch (Exception e) {
e.printStackTrace(System.out);
localIssueList.add(new Issue(origExp, issueContext, IssueCategory.Units, "expected=[" + ((desiredExpUnitDef != null) ? (desiredExpUnitDef.getSymbol()) : ("null")) + "], exception=" + e.getMessage(), Issue.SEVERITY_WARNING));
}
Expression newExp = new Expression(origExp);
//
// flatten user-defined functions
//
FunctionInvocation[] functionInvocations = newExp.getFunctionInvocations(new FunctionFilter() {
@Override
public boolean accept(String functionName, FunctionType functionType) {
return functionType == FunctionType.USERDEFINED;
}
});
for (FunctionInvocation functionInvocation : functionInvocations) {
if (functionInvocation.getSymbolTableFunctionEntry() instanceof Model.ModelFunction) {
ModelFunction modelFunction = (ModelFunction) functionInvocation.getSymbolTableFunctionEntry();
newExp.substituteInPlace(functionInvocation.getFunctionExpression(), modelFunction.getFlattenedExpression(functionInvocation));
}
}
//
// then substitute Math symbols for Biological symbols.
//
newExp.bindExpression(null);
for (int i = 0; i < symbols.length; i++) {
SymbolTableEntry ste = origExp.getSymbolBinding(symbols[i]);
if (ste == null) {
throw new ExpressionBindingException("symbol '" + symbols[i] + "' not bound");
// ste = simContext.getGeometryContext().getModel().getSpeciesContext(symbols[i]);
}
if (ste != null) {
String newName = getMathSymbol(ste, geometryClass);
if (!newName.equals(symbols[i])) {
newExp.substituteInPlace(new Expression(symbols[i]), new Expression(newName));
}
}
}
return newExp;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class AbstractMathMapping method getLocalEntry.
/**
* Insert the method's description here.
* Creation date: (4/4/2004 1:01:22 AM)
* @return cbit.vcell.parser.SymbolTableEntry
* @param identifier java.lang.String
*/
public SymbolTableEntry getLocalEntry(java.lang.String identifier) {
//
// the MathMapping "nameScope" is the union of the Model and SimContext namescopes (with the addition of any locally defined parameters)
//
//
// try "truely" local first
//
SymbolTableEntry localParamSTE = getMathMappingParameter(identifier);
SymbolTableEntry localQuantitySTE = getMathMappingQuantity(identifier);
//
// try "model" next
//
SymbolTableEntry modelSTE = simContext.getModel().getLocalEntry(identifier);
//
// try "simContext" next
//
SymbolTableEntry simContextSTE = simContext.getLocalEntry(identifier);
int resolutionCount = 0;
SymbolTableEntry ste = null;
if (localParamSTE != null) {
resolutionCount++;
ste = localParamSTE;
}
if (localQuantitySTE != null) {
resolutionCount++;
ste = localQuantitySTE;
}
if (modelSTE != null) {
resolutionCount++;
ste = modelSTE;
}
if (simContextSTE != null && simContextSTE != modelSTE) {
resolutionCount++;
ste = simContextSTE;
}
if (resolutionCount == 0 || resolutionCount == 1) {
return ste;
} else {
StringBuffer buffer = new StringBuffer();
buffer.append("identifier '" + identifier + "' ambiguous, resolved by [");
if (localParamSTE != null) {
buffer.append(" MathMappingParameter(" + localParamSTE + ")");
}
if (localQuantitySTE != null) {
buffer.append(" MathMappingQuantity(" + localQuantitySTE + ")");
}
if (modelSTE != null) {
buffer.append(" Model(" + modelSTE + ")");
}
if (simContextSTE != null && simContextSTE != modelSTE) {
buffer.append(" Application(" + simContextSTE + ")");
}
buffer.append(" ]");
throw new RuntimeException(buffer.toString());
}
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class AbstractStochMathMapping method getSubstitutedExpr.
/**
* @param expr
* @param bConcentration
* @return
* @throws ExpressionException
*/
protected Expression getSubstitutedExpr(Expression expr, boolean bConcentration, boolean bIsInitialCondn) throws ExpressionException {
expr = new Expression(expr);
String[] symbols = expr.getSymbols();
// Check if 'expr' has other speciesContexts in its expression, need to replace it with 'spContext_init'
for (int j = 0; symbols != null && j < symbols.length; j++) {
// if symbol is a speciesContext, replacing it with a reference to initial condition for that speciesContext.
SpeciesContext spC = null;
SymbolTableEntry ste = expr.getSymbolBinding(symbols[j]);
if (ste instanceof ProxyParameter) {
// if expression is for speciesContextSpec or Kinetics, ste will be a ProxyParameter instance.
ProxyParameter spspp = (ProxyParameter) ste;
if (spspp.getTarget() instanceof SpeciesContext) {
spC = (SpeciesContext) spspp.getTarget();
}
} else if (ste instanceof SpeciesContext) {
// if expression is for a global parameter, ste will be a SpeciesContext instance.
spC = (SpeciesContext) ste;
}
if (spC != null) {
SpeciesContextSpec spcspec = getSimulationContext().getReactionContext().getSpeciesContextSpec(spC);
Parameter spCParm = null;
if (bConcentration && bIsInitialCondn) {
// speciesContext has initConcentration set, so need to replace 'spContext' in 'expr' 'spContext_init'
spCParm = spcspec.getParameterFromRole(SpeciesContextSpec.ROLE_InitialConcentration);
} else if (!bConcentration && bIsInitialCondn) {
// speciesContext has initCount set, so need to replace 'spContext' in 'expr' 'spContext_initCount'
spCParm = spcspec.getParameterFromRole(SpeciesContextSpec.ROLE_InitialCount);
} else if (bConcentration && !bIsInitialCondn) {
// need to replace 'spContext' in 'expr' 'spContext_Conc'
spCParm = getSpeciesConcentrationParameter(spC);
} else if (!bConcentration && !bIsInitialCondn) {
// need to replace 'spContext' in 'expr' 'spContext_Count'
spCParm = getSpeciesCountParameter(spC);
}
// need to get init condn expression, but can't get it from getMathSymbol() (mapping between bio and math), hence get it as below.
Expression scsInitExpr = new Expression(spCParm, getNameScope());
// scsInitExpr.bindExpression(this);
expr.substituteInPlace(new Expression(spC.getName()), scsInitExpr);
}
}
return expr;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class PdeEquation method isDummy.
public boolean isDummy(MathSymbolTable simSymbolTable, CompartmentSubDomain thisCompartment) {
if (!(getVariable() instanceof VolVariable)) {
return false;
}
VolVariable volVar = (VolVariable) getVariable();
// in any case the initial conditions will be respected.
if (testZero(simSymbolTable, getRateExpression()) && testZero(simSymbolTable, velocityX) && testZero(simSymbolTable, velocityY) && testZero(simSymbolTable, velocityZ) && testZero(simSymbolTable, gradientX) && testZero(simSymbolTable, gradientY) && testZero(simSymbolTable, gradientZ)) {
if (testZero(simSymbolTable, diffusionExp)) {
// zero rate, velocity and diffusion
return true;
} else {
// for non-zero diffusion, look for non zero fluxes or non-uniform initial conditions.
if (testConstant(simSymbolTable, getInitialExpression()) && testZero(simSymbolTable, boundaryXm) && testZero(simSymbolTable, boundaryXp) && testZero(simSymbolTable, boundaryYm) && testZero(simSymbolTable, boundaryYp) && testZero(simSymbolTable, boundaryZm) && testZero(simSymbolTable, boundaryZp)) {
// 1. get THIS compartment
// 2. get all membranes that touch this compartment
// 3. get jump condition for this variable
// 4. check either influx or outflux
Enumeration<SubDomain> subDomainEnum = simSymbolTable.getMathDescription().getSubDomains();
while (subDomainEnum.hasMoreElements()) {
SubDomain subDomain = (SubDomain) subDomainEnum.nextElement();
if (subDomain instanceof MembraneSubDomain) {
MembraneSubDomain memSubDomain = (MembraneSubDomain) subDomain;
if (memSubDomain.getInsideCompartment() == thisCompartment) {
JumpCondition jump = memSubDomain.getJumpCondition(volVar);
if (jump != null && !testZero(simSymbolTable, jump.getInFluxExpression())) {
// non zero jump condition
return false;
}
} else if (memSubDomain.getOutsideCompartment() == thisCompartment) {
JumpCondition jump = memSubDomain.getJumpCondition(volVar);
if (jump != null && !testZero(simSymbolTable, jump.getOutFluxExpression())) {
// non zero jump condition
return false;
}
}
// check if BoundaryConditionValue is defined for var on membrane
try {
BoundaryConditionValue boundaryValue = getBoundaryConditionValue(memSubDomain.getName());
if (boundaryValue != null) {
Expression boundaryValExpr = boundaryValue.getBoundaryConditionExpression();
BoundaryConditionSpec boundarySpec = thisCompartment.getBoundaryConditionSpec(memSubDomain.getName());
if (boundarySpec != null) {
boolean bZeroFlux = boundarySpec.getBoundaryConditionType().isNEUMANN() && testZero(simSymbolTable, boundaryValExpr);
boolean bUniformDirichlet = boundarySpec.getBoundaryConditionType().isDIRICHLET() && testZero(simSymbolTable, Expression.add(boundaryValExpr, Expression.negate(getInitialExpression())));
if (!bZeroFlux && !bUniformDirichlet) {
return false;
}
}
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
// check fast system if jump conditions are all zero
FastSystem fastSystem = thisCompartment.getFastSystem();
if (fastSystem != null) {
Enumeration<FastInvariant> fastInvariants = fastSystem.getFastInvariants();
while (fastInvariants.hasMoreElements()) {
FastInvariant fi = fastInvariants.nextElement();
try {
// look for fast invariants that involve only this variable
// which means this variable is not affected by fast system
Expression exp = new Expression(fi.getFunction());
exp.bindExpression(simSymbolTable);
exp = exp.flatten();
SymbolTableEntry ste = exp.getSymbolBinding(volVar.getName());
if (ste != null && exp.getSymbols().length == 1) {
return true;
}
} catch (ExpressionException ex) {
ex.printStackTrace(System.out);
throw new RuntimeException("PdeEquation::isDummy(), not expected: " + ex.getMessage());
}
}
// the variable is not found to be invariant in this fast system, might be changed by fast system
return false;
}
// not changed by jump conditions, boundary conditions and fast system even if diffusion rate is non zero
return true;
}
}
}
// non zero rate or velocity
return false;
}
Aggregations