Search in sources :

Example 96 with MathDescription

use of cbit.vcell.math.MathDescription 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 97 with MathDescription

use of cbit.vcell.math.MathDescription 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 98 with MathDescription

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

the class Simulation method propertyChange.

public void propertyChange(PropertyChangeEvent evt) {
    MathDescription md = getMathDescription();
    boolean bIsMath = evt.getSource() == md;
    if (bIsMath && evt.getPropertyName().equals("geometry")) {
        try {
            refreshMeshSpec();
        } catch (PropertyVetoException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) MathDescription(cbit.vcell.math.MathDescription)

Example 99 with MathDescription

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

the class DefaultODESolver method createStateVariables.

/**
 * This method was created in VisualAge.
 */
private Vector<StateVariable> createStateVariables() throws MathException, ExpressionException {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    Simulation sim = simSymbolTable.getSimulation();
    Vector<StateVariable> stateVariables = new Vector<StateVariable>();
    // get Ode's from MathDescription and create ODEStateVariables
    Enumeration<Equation> enum1 = getSubDomain().getEquations();
    while (enum1.hasMoreElements()) {
        Equation equation = enum1.nextElement();
        if (equation instanceof OdeEquation) {
            stateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    MathDescription mathDescription = sim.getMathDescription();
    if (rateSensitivity == null) {
        rateSensitivity = new RateSensitivity(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    if (jacobian == null) {
        jacobian = new Jacobian(mathDescription, mathDescription.getSubDomains().nextElement());
    }
    // get Jacobian and RateSensitivities from MathDescription and create SensStateVariables
    for (int v = 0; v < fieldSensVariables.size(); v++) {
        stateVariables.addElement(new SensStateVariable(fieldSensVariables.elementAt(v), rateSensitivity, jacobian, fieldSensVariables, simSymbolTable));
    }
    if (stateVariables.size() == 0) {
        throw new MathException("there are no equations defined");
    }
    return (stateVariables);
}
Also used : MathDescription(cbit.vcell.math.MathDescription) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) Simulation(cbit.vcell.solver.Simulation) OdeEquation(cbit.vcell.math.OdeEquation) MathException(cbit.vcell.math.MathException) Vector(java.util.Vector)

Example 100 with MathDescription

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

the class OdeFileWriter method writeEvents.

private String writeEvents(HashMap<Discontinuity, String> discontinuityNameMap) throws ExpressionException {
    Simulation simulation = simTask.getSimulation();
    StringBuffer sb = new StringBuffer();
    MathDescription mathDescription = simulation.getMathDescription();
    Iterator<Event> iter = mathDescription.getEvents();
    sb.append("EVENTS " + mathDescription.getNumEvents() + "\n");
    while (iter.hasNext()) {
        Event event = iter.next();
        sb.append("EVENT " + event.getName() + "\n");
        Expression triggerExpression = event.getTriggerExpression();
        triggerExpression = MathUtilities.substituteFunctions(triggerExpression, varsSymbolTable).flatten();
        Vector<Discontinuity> v = triggerExpression.getDiscontinuities();
        for (Discontinuity od : v) {
            od = getSubsitutedAndFlattened(od, varsSymbolTable);
            String dname = discontinuityNameMap.get(od);
            if (dname == null) {
                dname = ROOT_VARIABLE_PREFIX + discontinuityNameMap.size();
                discontinuityNameMap.put(od, dname);
            }
            triggerExpression.substituteInPlace(od.getDiscontinuityExp(), new Expression("(" + dname + "==1)"));
        }
        sb.append("TRIGGER " + triggerExpression.infix() + ";\n");
        Delay delay = event.getDelay();
        if (delay != null) {
            Expression durationExpression = delay.getDurationExpression();
            durationExpression = MathUtilities.substituteFunctions(durationExpression, varsSymbolTable).flatten();
            sb.append("DELAY " + delay.useValuesFromTriggerTime() + " " + durationExpression.infix() + ";\n");
        }
        sb.append("EVENTASSIGNMENTS " + event.getNumEventAssignments() + "\n");
        Iterator<EventAssignment> iter2 = event.getEventAssignments();
        while (iter2.hasNext()) {
            EventAssignment eventAssignment = iter2.next();
            Expression assignmentExpression = eventAssignment.getAssignmentExpression();
            assignmentExpression = MathUtilities.substituteFunctions(assignmentExpression, varsSymbolTable).flatten();
            Variable assignmentTarget = eventAssignment.getVariable();
            for (int i = 0; i < fieldStateVariables.size(); i++) {
                if (assignmentTarget.getName().equals(fieldStateVariables.get(i).getVariable().getName())) {
                    sb.append(i + " " + assignmentExpression.infix() + ";\n");
                    break;
                }
            }
        }
    }
    return sb.toString();
}
Also used : Discontinuity(cbit.vcell.parser.Discontinuity) ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) EventAssignment(cbit.vcell.math.Event.EventAssignment) MathDescription(cbit.vcell.math.MathDescription) Delay(cbit.vcell.math.Event.Delay) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) Event(cbit.vcell.math.Event)

Aggregations

MathDescription (cbit.vcell.math.MathDescription)120 Simulation (cbit.vcell.solver.Simulation)48 Geometry (cbit.vcell.geometry.Geometry)32 SimulationContext (cbit.vcell.mapping.SimulationContext)32 Variable (cbit.vcell.math.Variable)32 Expression (cbit.vcell.parser.Expression)30 ExpressionException (cbit.vcell.parser.ExpressionException)27 PropertyVetoException (java.beans.PropertyVetoException)25 BioModel (cbit.vcell.biomodel.BioModel)24 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)22 Constant (cbit.vcell.math.Constant)22 MathException (cbit.vcell.math.MathException)21 MathModel (cbit.vcell.mathmodel.MathModel)21 KeyValue (org.vcell.util.document.KeyValue)20 SubDomain (cbit.vcell.math.SubDomain)19 ArrayList (java.util.ArrayList)18 SubVolume (cbit.vcell.geometry.SubVolume)17 Model (cbit.vcell.model.Model)17 DataAccessException (org.vcell.util.DataAccessException)17 Function (cbit.vcell.math.Function)15