Search in sources :

Example 51 with Constant

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

the class ConstantArraySpec method clone.

/**
 * Insert the method's description here.
 * Creation date: (10/15/2005 6:09:19 PM)
 * @return cbit.vcell.solver.ConstantArraySpec
 * @param spec cbit.vcell.solver.ConstantArraySpec
 */
public static ConstantArraySpec clone(ConstantArraySpec spec) {
    ConstantArraySpec clone = new ConstantArraySpec();
    clone.logInterval = spec.logInterval;
    clone.maxValue = spec.maxValue;
    clone.minValue = spec.minValue;
    clone.name = spec.name;
    clone.numValues = spec.numValues;
    clone.type = spec.type;
    clone.constants = new Constant[spec.constants.length];
    for (int i = 0; i < clone.constants.length; i++) {
        clone.constants[i] = new Constant(spec.constants[i].getName(), new Expression(spec.constants[i].getExpression()));
    }
    return clone;
}
Also used : Expression(cbit.vcell.parser.Expression) Constant(cbit.vcell.math.Constant)

Example 52 with Constant

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

the class MathOverrides method updateFromMathDescription.

void updateFromMathDescription() {
    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
    // 
    // 1) try to "repair" overridden constants for automatically generated constant names (via math generation)
    // which have changed due to changes to Math generation
    // 
    // 2) if not repaired, will be reported as an issue.
    // 
    HashMap<String, String> renamedMap = new HashMap<String, String>();
    boolean bNameRepaired = true;
    while (bNameRepaired) {
        bNameRepaired = false;
        Enumeration<String> mathOverrideNamesEnum = getOverridesHash().keys();
        while (mathOverrideNamesEnum.hasMoreElements()) {
            String name = mathOverrideNamesEnum.nextElement();
            if (!mathDescriptionHash.contains(name)) {
                // 
                if (name.endsWith(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old)) {
                    String name_repaired_to_uM = name.replace(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old, DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old_uM);
                    if (mathDescriptionHash.contains(name_repaired_to_uM)) {
                        Element element = overridesHash.remove(name);
                        element.name = name_repaired_to_uM;
                        overridesHash.put(name_repaired_to_uM, element);
                        renamedMap.put(name, name_repaired_to_uM);
                        removeConstant(name);
                        bNameRepaired = true;
                        break;
                    }
                }
                // 
                if (name.endsWith(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old)) {
                    String name_repaired_to_molecule_per_um2 = name.replace(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old, DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old_molecules_um_2);
                    if (mathDescriptionHash.contains(name_repaired_to_molecule_per_um2)) {
                        Element element = overridesHash.remove(name);
                        element.name = name_repaired_to_molecule_per_um2;
                        overridesHash.put(name_repaired_to_molecule_per_um2, element);
                        renamedMap.put(name, name_repaired_to_molecule_per_um2);
                        removeConstant(name);
                        bNameRepaired = true;
                        break;
                    }
                }
                // 
                if (name.endsWith(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old_molecules_per_um2)) {
                    String name_repaired_to_molecule_per_um2 = name.replace(DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old_molecules_per_um2, DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONCENTRATION_old_molecules_um_2);
                    if (mathDescriptionHash.contains(name_repaired_to_molecule_per_um2)) {
                        Element element = overridesHash.remove(name);
                        element.name = name_repaired_to_molecule_per_um2;
                        overridesHash.put(name_repaired_to_molecule_per_um2, element);
                        renamedMap.put(name, name_repaired_to_molecule_per_um2);
                        removeConstant(name);
                        bNameRepaired = true;
                        break;
                    }
                }
            }
        }
    }
    // 
    for (String origName : renamedMap.keySet()) {
        for (Element element : overridesHash.values()) {
            if (element.actualValue != null && element.actualValue.hasSymbol(origName)) {
                try {
                    element.actualValue = element.actualValue.getSubstitutedExpression(new Expression(origName), new Expression(mathDescription.getVariable(renamedMap.get(origName)), null));
                } catch (ExpressionException e) {
                    // won't happen ... here because new Expression(origName) throws a parse exception ... but it must be able to parse.
                    e.printStackTrace();
                }
            }
        }
    }
    refreshDependencies();
}
Also used : MathDescription(cbit.vcell.math.MathDescription) HashMap(java.util.HashMap) Constant(cbit.vcell.math.Constant) ExpressionException(cbit.vcell.parser.ExpressionException) Expression(cbit.vcell.parser.Expression)

Example 53 with Constant

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

the class MathOverrides method removeUnusedOverrides.

/**
 * explicit user action invokes this method (currently pressing a button), this is not automatic cleanup of old/obsolete models ... we want the user to address the issues.
 */
public void removeUnusedOverrides() {
    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
    // 
    ArrayList<String> overridesToDelete = new ArrayList<String>();
    Enumeration<String> mathOverrideNamesEnum = getOverridesHash().keys();
    while (mathOverrideNamesEnum.hasMoreElements()) {
        String name = mathOverrideNamesEnum.nextElement();
        if (!mathDescriptionHash.contains(name)) {
            // constant 'name' no longer part of mathDescription
            overridesToDelete.add(name);
        } else if (getSimulation().getSimulationOwner() != null) {
            IssueContext issueContext = new IssueContext(ContextType.Simulation, getSimulation(), null);
            if (getSimulation().getSimulationOwner().gatherIssueForMathOverride(issueContext, getSimulation(), name) != null) {
                // constant 'name' is part of math, but simulation owner doesn't want you to override it.
                overridesToDelete.add(name);
            }
        }
    }
    for (String deletedName : overridesToDelete) {
        removeConstant(deletedName);
    }
}
Also used : MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) ArrayList(java.util.ArrayList) IssueContext(org.vcell.util.IssueContext)

Example 54 with Constant

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

the class MathOverrides method putConstant.

/**
 * Maps the specified <code>key</code> to the specified
 * <code>value</code> . Neither the key nor the
 * value can be <code>null</code>. <p>
 */
private void putConstant(Constant value, boolean bFireEvent) throws ExpressionException {
    // 
    // verify that new expression can be bound properly
    // 
    verifyExpression(value, false);
    // put new element in the hash if value different from default
    // if same as default, remove element if we had it in hash, otherwise do nothing
    String name = value.getName();
    Expression act = value.getExpression();
    Expression def = null;
    Variable var = getSimulation().getMathDescription().getVariable(name);
    if (var != null && var instanceof Constant) {
        def = ((Constant) var).getExpression();
    } else {
        // ignore
        System.out.println(">>>>WARNING: Math does not have constant with name: " + name);
        return;
    }
    if (act.compareEqual(def)) {
        if (getOverridesHash().containsKey(name)) {
            removeConstant(name);
        }
    } else {
        getOverridesHash().put(name, new MathOverrides.Element(name, act));
    }
    if (bFireEvent) {
        fireConstantChanged(new MathOverridesEvent(value.getName()));
    }
}
Also used : Variable(cbit.vcell.math.Variable) Expression(cbit.vcell.parser.Expression) Constant(cbit.vcell.math.Constant)

Example 55 with Constant

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

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