Search in sources :

Example 91 with Variable

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

the class MathOverrides method verifyExpression.

/**
 * Insert the method's description here.
 * Creation date: (9/22/2005 3:24:36 PM)
 */
private void verifyExpression(Constant value, boolean checkScan) throws ExpressionBindingException {
    Expression exp = value.getExpression();
    String[] symbols = exp.getSymbols();
    MathDescription mathDescription = getSimulation().getMathDescription();
    exp.bindExpression(mathDescription);
    if (symbols != null) {
        for (int i = 0; i < symbols.length; i++) {
            // 
            // expression must be a function of another Simulation parameter
            // 
            Variable variable = mathDescription.getVariable(symbols[i]);
            if (!(variable != null && variable instanceof Constant)) {
                throw new ExpressionBindingException("identifier " + symbols[i] + " is not a constant. " + "Parameter overrides should only refer to constants.");
            }
            if (checkScan && isScan(symbols[i])) {
                throw new ExpressionBindingException("Parameter overrides cannot depend on another scanned parameter " + symbols[i]);
            }
            // 
            if (symbols[i].equals(value.getName())) {
                throw new ExpressionBindingException("Parameter overrides can not be recursive definition, can't use identifier " + value.getName() + " in expression for " + value.getName());
            }
        }
    }
}
Also used : Variable(cbit.vcell.math.Variable) Expression(cbit.vcell.parser.Expression) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException)

Example 92 with Variable

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

the class MathOverrides method gatherIssues.

/**
 * This method was created in VisualAge.
 * @return boolean
 */
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
    MathDescription mathDescription = getSimulation().getMathDescription();
    // 
    // get list of names of constants in this math
    // 
    Enumeration<Constant> enumeration = mathDescription.getConstants();
    java.util.HashSet<String> mathDescriptionHash = new java.util.HashSet<String>();
    while (enumeration.hasMoreElements()) {
        Constant constant = enumeration.nextElement();
        mathDescriptionHash.add(constant.getName());
    }
    // 
    // for any elements in this MathOverrides but not in the new MathDescription, add an "error" issue
    // 
    Enumeration<String> mathOverrideNamesEnum = getOverridesHash().keys();
    while (mathOverrideNamesEnum.hasMoreElements()) {
        String name = mathOverrideNamesEnum.nextElement();
        if (!mathDescriptionHash.contains(name)) {
            Issue issue = new Issue(getSimulation(), issueContext, IssueCategory.Simulation_Override_NotFound, VCellErrorMessages.getErrorMessage(VCellErrorMessages.SIMULATION_OVERRIDE_NOTFOUND, name, getSimulation().getName()), Issue.SEVERITY_ERROR);
            issueList.add(issue);
        }
        Variable var = mathDescription.getVariable(name);
        if (getSimulation().getSimulationOwner() != null) {
            Issue issue = getSimulation().getSimulationOwner().gatherIssueForMathOverride(issueContext, getSimulation(), name);
            if (issue != null) {
                issueList.add(issue);
            }
        }
    }
}
Also used : Issue(org.vcell.util.Issue) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant)

Example 93 with Variable

use of cbit.vcell.math.Variable 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());
            }
        }
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) VariableType(cbit.vcell.math.VariableType) MathDescription(cbit.vcell.math.MathDescription) ArrayList(java.util.ArrayList) ExpressionException(cbit.vcell.parser.ExpressionException) Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) InconsistentDomainException(cbit.vcell.math.InconsistentDomainException)

Example 94 with Variable

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

the class SimulationSymbolTable method getLocalConstant.

/**
 * Insert the method's description here.
 * Creation date: (6/6/2001 7:52:15 PM)
 * @return cbit.vcell.math.Function
 * @param functionName java.lang.String
 */
private Constant getLocalConstant(Constant referenceConstant) throws ExpressionException {
    if (localVariableHash == null) {
        localVariableHash = new HashMap<String, Variable>();
    }
    Variable var = localVariableHash.get(referenceConstant.getName());
    if (var instanceof Constant) {
        Constant localConstant = (Constant) var;
        // 
        // make sure expression for localConstant is still up to date with MathOverrides table
        // 
        Expression exp = simulation.getMathOverrides().getActualExpression(referenceConstant.getName(), index);
        if (exp.compareEqual(localConstant.getExpression())) {
            // localConstant.bind(this); // update bindings to latest mathOverrides
            return localConstant;
        } else {
            // 
            // MathOverride's Expression changed for this Constant, remove and create new one
            // 
            localVariableHash.remove(localConstant.getName());
        }
    } else if (var != null) {
        throw new RuntimeException("Variable " + var + " expected to be a Constant");
    }
    // 
    // if local Constant not found, create new one, bind it to the Simulation (which ensures MathOverrides), and add to list
    // 
    String name = referenceConstant.getName();
    Constant newLocalConstant = new Constant(name, simulation.getMathOverrides().getActualExpression(name, index));
    // newLocalConstant.bind(this);
    localVariableHash.put(newLocalConstant.getName(), newLocalConstant);
    return newLocalConstant;
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) PointVariable(cbit.vcell.math.PointVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) Expression(cbit.vcell.parser.Expression) Constant(cbit.vcell.math.Constant)

Example 95 with Variable

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

the class SimulationSymbolTable method getLocalFunction.

/**
 * Insert the method's description here.
 * Creation date: (6/6/2001 7:52:15 PM)
 * @return cbit.vcell.math.Function
 * @param functionName java.lang.String
 */
private Function getLocalFunction(Function referenceFunction) throws ExpressionException {
    if (localVariableHash == null) {
        localVariableHash = new HashMap<String, Variable>();
    }
    Variable var = localVariableHash.get(referenceFunction.getName());
    if (var instanceof Function) {
        Function localFunction = (Function) var;
        if (localFunction.compareEqual(referenceFunction)) {
            // localFunction.bind(this); // update bindings to latest mathOverrides
            return localFunction;
        }
    } else if (var != null) {
        throw new RuntimeException("Variable " + var + " expected to be a Function");
    }
    // 
    // if local Function not found, create new one, bind it to the Simulation (which ensures MathOverrides), and add to list
    // 
    Function newLocalFunction = new Function(referenceFunction.getName(), referenceFunction.getExpression(), referenceFunction.getDomain());
    // newLocalFunction.bind(this);
    localVariableHash.put(newLocalFunction.getName(), newLocalFunction);
    return newLocalFunction;
}
Also used : Function(cbit.vcell.math.Function) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) PointVariable(cbit.vcell.math.PointVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable)

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