Search in sources :

Example 56 with Constant

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

the class MathOverrides method getVCML.

/**
 * Insert the method's description here.
 * Creation date: (10/24/00 12:41:09 PM)
 * @return java.lang.String
 */
public String getVCML() {
    // 
    // write format as follows:
    // 
    // MathOverrides {
    // Constant K1 200;
    // Constant K2 400;
    // Constant K3 494.0;
    // }
    // 
    // 
    StringBuffer buffer = new StringBuffer();
    buffer.append(VCML.MathOverrides + " " + VCML.BeginBlock + "\n");
    java.util.Enumeration<String> enum1 = getOverridesHash().keys();
    while (enum1.hasMoreElements()) {
        String name = enum1.nextElement();
        MathOverrides.Element element = (MathOverrides.Element) getOverridesHash().get(name);
        Expression exp = element.actualValue;
        if (exp != null) {
            // regular override
            Constant constant = new Constant(name, exp);
            buffer.append("   " + constant.getVCML());
        } else {
            // scan override
            buffer.append("   " + element.spec.getVCML());
        }
    }
    buffer.append("\n" + VCML.EndBlock + "\n");
    return buffer.toString();
}
Also used : Expression(cbit.vcell.parser.Expression) Constant(cbit.vcell.math.Constant)

Example 57 with Constant

use of cbit.vcell.math.Constant 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 58 with Constant

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

the class OutputFunctionContext method getEntry.

public SymbolTableEntry getEntry(java.lang.String identifierString) {
    // 
    // use MathDescription as the primary SymbolTable, just replace the Constants with the overrides.
    // 
    SymbolTableEntry ste = null;
    MathDescription mathDescription = simulationOwner.getMathDescription();
    if (mathDescription != null) {
        ste = mathDescription.getEntry(identifierString);
        if (ste != null && !(ste instanceof PseudoConstant) && !(ste instanceof Constant)) {
            return ste;
        }
        ste = mathDescription.getPostProcessingBlock().getDataGenerator(identifierString);
        if (ste instanceof DataGenerator) {
            return ste;
        }
    }
    // see if it is an output function.
    ste = getOutputFunction(identifierString);
    return ste;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) PseudoConstant(cbit.vcell.math.PseudoConstant) PseudoConstant(cbit.vcell.math.PseudoConstant) DataGenerator(cbit.vcell.math.DataGenerator)

Example 59 with Constant

use of cbit.vcell.math.Constant 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 60 with Constant

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

the class SimulationSymbolTable method getVariables.

/**
 * Insert the method's description here.
 * Creation date: (5/25/01 11:34:08 AM)
 * @return cbit.vcell.math.Variable[]
 */
public Variable[] getVariables() {
    Vector<Variable> varList = new Vector<Variable>();
    // 
    // get all variables from MathDescription, but replace MathOverrides
    // 
    Enumeration<Variable> enum1 = simulation.getMathDescription().getVariables();
    while (enum1.hasMoreElements()) {
        Variable mathDescriptionVar = enum1.nextElement();
        // 
        if (mathDescriptionVar instanceof Constant) {
            try {
                Constant overriddenConstant = getLocalConstant((Constant) mathDescriptionVar);
                varList.addElement(overriddenConstant);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("local Constant " + mathDescriptionVar.getName() + " not found for Simulation");
            }
        // 
        // replace all Functions with local Functions that are bound to this Simulation
        // 
        } else if (mathDescriptionVar instanceof Function) {
            try {
                Function overriddenFunction = getLocalFunction((Function) mathDescriptionVar);
                varList.addElement(overriddenFunction);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("local Function " + mathDescriptionVar.getName() + " not found for Simulation");
            }
        // 
        // pass all other Variables through
        // 
        } else {
            varList.addElement(mathDescriptionVar);
        }
    }
    Variable[] variables = (Variable[]) BeanUtils.getArray(varList, Variable.class);
    return variables;
}
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) Constant(cbit.vcell.math.Constant) Vector(java.util.Vector) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

Constant (cbit.vcell.math.Constant)69 Expression (cbit.vcell.parser.Expression)43 Variable (cbit.vcell.math.Variable)31 Function (cbit.vcell.math.Function)24 MathDescription (cbit.vcell.math.MathDescription)22 VolVariable (cbit.vcell.math.VolVariable)21 ExpressionException (cbit.vcell.parser.ExpressionException)21 MathException (cbit.vcell.math.MathException)15 Vector (java.util.Vector)15 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)14 MemVariable (cbit.vcell.math.MemVariable)14 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)13 SubDomain (cbit.vcell.math.SubDomain)13 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)12 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)12 ReservedVariable (cbit.vcell.math.ReservedVariable)11 FilamentVariable (cbit.vcell.math.FilamentVariable)10 InsideVariable (cbit.vcell.math.InsideVariable)10 OutsideVariable (cbit.vcell.math.OutsideVariable)10 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)9