Search in sources :

Example 26 with Equation

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

the class FiniteVolumeFileWriter method writeVariables.

/**
 *# Variables : type name unit time_dependent_flag advection_flag solve_whole_mesh_flag solve_regions
 *VARIABLE_BEGIN
 *VOLUME_ODE rB uM
 *VOLUME_PDE rf uM false false
 *VOLUME_PDE r uM false false
 *VOLUME_ODE rfB uM
 *VARIABLE_END
 * @throws MathException
 * @throws ExpressionException
 * @throws IOException
 */
private void writeVariables() throws MathException, ExpressionException, IOException {
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    printWriter.println("# Variables : type name domain time_dependent_flag advection_flag grad_flag solve_whole_mesh_flag solve_regions");
    printWriter.println(FVInputFileKeyword.VARIABLE_BEGIN);
    MathDescription mathDesc = simSymbolTable.getSimulation().getMathDescription();
    Variable[] vars = simSymbolTable.getVariables();
    ArrayList<RandomVariable> rvList = new ArrayList<RandomVariable>();
    for (int i = 0; i < vars.length; i++) {
        String varName = vars[i].getName();
        String domainName = vars[i].getDomain() == null ? null : vars[i].getDomain().getName();
        if (vars[i] instanceof VolumeRandomVariable || vars[i] instanceof MembraneRandomVariable) {
            rvList.add((RandomVariable) vars[i]);
        } else if (vars[i] instanceof VolVariable) {
            if (bChomboSolver && domainName == null) {
                throw new MathException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " requires that every variable is defined in a single domain");
            }
            VolVariable volVar = (VolVariable) vars[i];
            if (mathDesc.isPDE(volVar)) {
                boolean hasTimeVaryingDiffusionOrAdvection = simSymbolTable.hasTimeVaryingDiffusionOrAdvection(volVar);
                final boolean hasVelocity = mathDesc.hasVelocity(volVar);
                final boolean hasGradient = mathDesc.hasGradient(volVar);
                if (mathDesc.isPdeSteady(volVar)) {
                    printWriter.print("VOLUME_PDE_STEADY ");
                } else {
                    printWriter.print("VOLUME_PDE ");
                }
                printWriter.print(varName + " " + domainName + " " + hasTimeVaryingDiffusionOrAdvection + " " + hasVelocity + " " + hasGradient);
            } else {
                printWriter.print("VOLUME_ODE " + varName + " " + domainName);
            }
            if (domainName == null) {
                Vector<SubDomain> listOfSubDomains = new Vector<SubDomain>();
                int totalNumCompartments = 0;
                Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
                while (subDomainEnum.hasMoreElements()) {
                    SubDomain subDomain = subDomainEnum.nextElement();
                    if (subDomain instanceof CompartmentSubDomain) {
                        CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) subDomain;
                        totalNumCompartments++;
                        Equation varEquation = subDomain.getEquation(vars[i]);
                        if (varEquation != null) {
                            if (!(varEquation instanceof PdeEquation) || !((PdeEquation) varEquation).isDummy(simSymbolTable, compartmentSubDomain)) {
                                listOfSubDomains.add(compartmentSubDomain);
                            }
                        }
                    }
                }
                if ((totalNumCompartments == listOfSubDomains.size()) || (listOfSubDomains.size() == 0 && simTask.getSimulation().getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE))) {
                    printWriter.print(" true");
                } else {
                    printWriter.print(" false");
                    for (int j = 0; j < listOfSubDomains.size(); j++) {
                        CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) listOfSubDomains.elementAt(j);
                        printWriter.print(" " + compartmentSubDomain.getName());
                    }
                }
                printWriter.println();
            } else {
                printWriter.println(" false " + domainName);
            }
        } else if (vars[i] instanceof VolumeParticleVariable) {
            printWriter.println(FVInputFileKeyword.VOLUME_PARTICLE + " " + varName + " " + domainName);
        } else if (vars[i] instanceof MembraneParticleVariable) {
            printWriter.println(FVInputFileKeyword.MEMBRANE_PARTICLE + " " + varName + " " + domainName);
        } else if (vars[i] instanceof VolumeRegionVariable) {
            printWriter.println("VOLUME_REGION " + varName + " " + domainName);
        } else if (vars[i] instanceof MemVariable) {
            if (bChomboSolver && domainName == null) {
                throw new MathException(simTask.getSimulation().getSolverTaskDescription().getSolverDescription().getDisplayLabel() + " requires that every variable is defined in a single domain");
            }
            MemVariable memVar = (MemVariable) vars[i];
            if (mathDesc.isPDE(memVar)) {
                printWriter.println("MEMBRANE_PDE " + varName + " " + domainName + " " + simSymbolTable.hasTimeVaryingDiffusionOrAdvection(memVar));
            } else {
                printWriter.println("MEMBRANE_ODE " + varName + " " + domainName);
            }
        } else if (vars[i] instanceof MembraneRegionVariable) {
            printWriter.println("MEMBRANE_REGION " + varName + " " + domainName);
        } else if (vars[i] instanceof FilamentVariable) {
            throw new RuntimeException("Filament application not supported yet");
        }
    }
    int numRandomVariables = rvList.size();
    if (numRandomVariables > 0) {
        ISize samplingSize = simTask.getSimulation().getMeshSpecification().getSamplingSize();
        String[] varNameArr = new String[numRandomVariables];
        VariableType[] varTypeArr = new VariableType[numRandomVariables];
        double[][] dataArr = new double[numRandomVariables][];
        for (int i = 0; i < numRandomVariables; i++) {
            RandomVariable rv = rvList.get(i);
            varNameArr[i] = rv.getName();
            int numRandomNumbers = 0;
            if (rv instanceof VolumeRandomVariable) {
                printWriter.print("VOLUME_RANDOM");
                varTypeArr[i] = VariableType.VOLUME;
                numRandomNumbers = samplingSize.getXYZ();
            } else if (rv instanceof MembraneRandomVariable) {
                printWriter.print("MEMBRANE_RANDOM");
                varTypeArr[i] = VariableType.MEMBRANE;
                numRandomNumbers = resampledGeometry.getGeometrySurfaceDescription().getSurfaceCollection().getTotalPolygonCount();
            } else {
                throw new RuntimeException("Unknown RandomVariable type");
            }
            printWriter.println(" " + varNameArr[i]);
            dataArr[i] = generateRandomNumbers(rv, numRandomNumbers);
        }
        File rvFile = new File(workingDirectory, simTask.getSimulationJobID() + RANDOM_VARIABLE_FILE_EXTENSION);
        DataSet.writeNew(rvFile, varNameArr, varTypeArr, samplingSize, dataArr);
    }
    printWriter.println(FVInputFileKeyword.VARIABLE_END);
    printWriter.println();
}
Also used : FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) MemVariable(cbit.vcell.math.MemVariable) Variable(cbit.vcell.math.Variable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) MathDescription(cbit.vcell.math.MathDescription) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) Vector(java.util.Vector) Enumeration(java.util.Enumeration) VariableType(cbit.vcell.math.VariableType) VolVariable(cbit.vcell.math.VolVariable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) MeasureEquation(cbit.vcell.math.MeasureEquation) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) MathException(cbit.vcell.math.MathException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) File(java.io.File)

Example 27 with Equation

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

the class Xmlproducer method getXML.

private Element getXML(PointSubDomain param) throws XmlParseException {
    Element pointSubDomain = new Element(XMLTags.PointSubDomainTag);
    // Add attributes
    pointSubDomain.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
    // Add Equation subelements
    Enumeration<Equation> enum1 = param.getEquations();
    while (enum1.hasMoreElements()) {
        Equation equ = enum1.nextElement();
        pointSubDomain.addContent(getXML(equ));
    }
    if (param.getPositionX() != null) {
        Element positionX = new Element(XMLTags.PositionXTag);
        positionX.addContent(param.getPositionX().infix());
        pointSubDomain.addContent(positionX);
    }
    if (param.getPositionY() != null) {
        Element positionY = new Element(XMLTags.PositionYTag);
        positionY.addContent(param.getPositionY().infix());
        pointSubDomain.addContent(positionY);
    }
    if (param.getPositionZ() != null) {
        Element positionZ = new Element(XMLTags.PositionZTag);
        positionZ.addContent(param.getPositionZ().infix());
        pointSubDomain.addContent(positionZ);
    }
    return pointSubDomain;
}
Also used : Element(org.jdom.Element) ComputeNormalComponentEquation(cbit.vcell.math.ComputeNormalComponentEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) PdeEquation(cbit.vcell.math.PdeEquation) ComputeMembraneMetricEquation(cbit.vcell.math.ComputeMembraneMetricEquation) OdeEquation(cbit.vcell.math.OdeEquation) ComputeCentroidComponentEquation(cbit.vcell.math.ComputeCentroidComponentEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation)

Example 28 with Equation

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

the class MovingBoundaryFileWriter method manageCompartment.

private void manageCompartment(Element e, SubDomain sd) {
    try {
        if (!sd.getEquationCollection().isEmpty()) {
            Element se = getXMLSubdomain(sd);
            if (sd instanceof CompartmentSubDomain || sd instanceof PointSubDomain) {
                for (Equation equation : sd.getEquationCollection()) {
                    System.out.println("add this: " + equation.getVariable().getName());
                    se.addContent(getSpecies(equation));
                }
                e.addContent(se);
            }
        }
    } catch (Exception exc) {
        throw new RuntimeException("error managing compartment", exc);
    }
}
Also used : CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) Element(org.jdom.Element) PointSubDomain(cbit.vcell.math.PointSubDomain) PdeEquation(cbit.vcell.math.PdeEquation) Equation(cbit.vcell.math.Equation) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Example 29 with Equation

use of cbit.vcell.math.Equation 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 30 with Equation

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

the class RateSensitivity method parseMathDesc.

/**
 * This method was created by a SmartGuide.
 * @exception java.lang.Exception The exception description.
 */
private void parseMathDesc() throws MathException {
    Vector equationList = new Vector();
    Enumeration enum1 = subDomain.getEquations();
    while (enum1.hasMoreElements()) {
        Equation equ = (Equation) enum1.nextElement();
        if (equ instanceof OdeEquation) {
            equationList.addElement(equ);
        } else {
            throw new MathException("encountered non-ode equation, unsupported");
        }
    }
    Vector constantList = new Vector();
    enum1 = mathDesc.getVariables();
    while (enum1.hasMoreElements()) {
        Variable var = (Variable) enum1.nextElement();
        if (var instanceof Constant) {
            constantList.addElement(var);
        }
    }
    numConstants = constantList.size();
    numRates = equationList.size();
    rates = new Expression[numRates];
    vars = new Variable[numRates];
    consts = new Constant[numConstants];
    for (int i = 0; i < numRates; i++) {
        OdeEquation odeEqu = (OdeEquation) equationList.elementAt(i);
        rates[i] = odeEqu.getRateExpression();
        vars[i] = odeEqu.getVariable();
    }
    for (int i = 0; i < numConstants; i++) {
        consts[i] = (Constant) constantList.elementAt(i);
    }
}
Also used : Enumeration(java.util.Enumeration) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) OdeEquation(cbit.vcell.math.OdeEquation) MathException(cbit.vcell.math.MathException) Constant(cbit.vcell.math.Constant) OdeEquation(cbit.vcell.math.OdeEquation) Equation(cbit.vcell.math.Equation) Vector(java.util.Vector)

Aggregations

Equation (cbit.vcell.math.Equation)32 PdeEquation (cbit.vcell.math.PdeEquation)21 OdeEquation (cbit.vcell.math.OdeEquation)20 SubDomain (cbit.vcell.math.SubDomain)17 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)16 Variable (cbit.vcell.math.Variable)16 Expression (cbit.vcell.parser.Expression)16 Vector (java.util.Vector)14 MembraneRegionEquation (cbit.vcell.math.MembraneRegionEquation)13 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)13 VolVariable (cbit.vcell.math.VolVariable)13 MathDescription (cbit.vcell.math.MathDescription)12 VolumeRegionEquation (cbit.vcell.math.VolumeRegionEquation)12 MathException (cbit.vcell.math.MathException)10 Constant (cbit.vcell.math.Constant)8 JumpCondition (cbit.vcell.math.JumpCondition)8 MemVariable (cbit.vcell.math.MemVariable)8 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)8 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)8 Function (cbit.vcell.math.Function)7