Search in sources :

Example 6 with PdeEquation

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

the class SimulationSymbolTable method hasTimeVaryingDiffusionOrAdvection.

public boolean hasTimeVaryingDiffusionOrAdvection(Variable variable) throws MathException, ExpressionException {
    Enumeration<SubDomain> enum1 = simulation.getMathDescription().getSubDomains();
    while (enum1.hasMoreElements()) {
        SubDomain subDomain = enum1.nextElement();
        Equation equation = subDomain.getEquation(variable);
        // 
        if (equation instanceof PdeEquation) {
            Vector<Expression> spatialExpressionList = new Vector<Expression>();
            spatialExpressionList.add(((PdeEquation) equation).getDiffusionExpression());
            if (((PdeEquation) equation).getVelocityX() != null) {
                spatialExpressionList.add(((PdeEquation) equation).getVelocityX());
            }
            if (((PdeEquation) equation).getVelocityY() != null) {
                spatialExpressionList.add(((PdeEquation) equation).getVelocityY());
            }
            if (((PdeEquation) equation).getVelocityZ() != null) {
                spatialExpressionList.add(((PdeEquation) equation).getVelocityZ());
            }
            for (int i = 0; i < spatialExpressionList.size(); i++) {
                Expression spatialExp = spatialExpressionList.elementAt(i);
                spatialExp = substituteFunctions(spatialExp);
                String[] symbols = spatialExp.getSymbols();
                if (symbols != null) {
                    for (int j = 0; j < symbols.length; j++) {
                        SymbolTableEntry entry = spatialExp.getSymbolBinding(symbols[j]);
                        if (entry instanceof ReservedVariable) {
                            if (((ReservedVariable) entry).isTIME()) {
                                return true;
                            }
                        }
                        if (entry instanceof VolVariable) {
                            return true;
                        }
                        if (entry instanceof VolumeRegionVariable) {
                            return true;
                        }
                        if (entry instanceof MemVariable || entry instanceof MembraneRegionVariable) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolVariable(cbit.vcell.math.VolVariable) PdeEquation(cbit.vcell.math.PdeEquation) Equation(cbit.vcell.math.Equation) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) PdeEquation(cbit.vcell.math.PdeEquation) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) Expression(cbit.vcell.parser.Expression) Vector(java.util.Vector)

Example 7 with PdeEquation

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

the class MathDescriptionCellRenderer method getTreeCellRendererComponent.

/**
 * Insert the method's description here.
 * Creation date: (7/27/2000 6:41:57 PM)
 * @return java.awt.Component
 */
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    boolean bLoaded = false;
    // 
    try {
        if (value instanceof BioModelNode) {
            BioModelNode node = (BioModelNode) value;
            if (node.getUserObject() instanceof PdeEquation) {
                PdeEquation pdeEquation = (PdeEquation) node.getUserObject();
                Variable var = pdeEquation.getVariable();
                component.setToolTipText("PDE Equation");
                // \u2207 = nabla ... del operator
                // \u2219 = dot
                String DEL = "\u2207";
                // "\u2202";     //  '\u2202' is partial differentiation    'd' is regular diff
                String PARTIAL_DIFF = "d";
                String Super2 = "\u00b2";
                String DOT = "\u2219";
                // String diffusionTerm = DEL+" "+DOT+" "+"("+pdeEquation.getDiffusionExpression()+" "+DEL+" "+var.getName()+")";
                String diffusionTerm = "";
                if (pdeEquation.getVelocityX() != null || pdeEquation.getVelocityY() != null || pdeEquation.getVelocityZ() != null) {
                    if (pdeEquation.getDiffusionExpression().isZero()) {
                        // reaction/advection
                        diffusionTerm = "- " + DEL + " " + DOT + "( velocity " + var.getName() + " )";
                    } else {
                        // reaction/diffusion/advection
                        diffusionTerm = DEL + " " + DOT + " (" + pdeEquation.getDiffusionExpression().infix() + " " + DEL + "  " + var.getName() + "   -   velocity " + var.getName() + ")";
                    }
                } else {
                    diffusionTerm = "(" + pdeEquation.getDiffusionExpression().infix() + ") " + DEL + Super2 + " " + var.getName();
                }
                String gradTerm = "";
                if (pdeEquation.getGradientX() != null && !pdeEquation.getGradientX().isZero()) {
                    gradTerm += " + " + PARTIAL_DIFF + "[" + pdeEquation.getGradientX().infix() + "]/" + PARTIAL_DIFF + "x";
                }
                if (pdeEquation.getGradientY() != null && !pdeEquation.getGradientY().isZero()) {
                    gradTerm += " + " + PARTIAL_DIFF + "[" + pdeEquation.getGradientY().infix() + "]/" + PARTIAL_DIFF + "y";
                }
                if (pdeEquation.getGradientZ() != null && !pdeEquation.getGradientZ().isZero()) {
                    gradTerm += " + " + PARTIAL_DIFF + "[" + pdeEquation.getGradientZ().infix() + "]/" + PARTIAL_DIFF + "z";
                }
                String sourceTerm = pdeEquation.getRateExpression().infix();
                if (!sourceTerm.equals("0.0")) {
                    component.setText(PARTIAL_DIFF + "[" + var.getName() + "]/" + PARTIAL_DIFF + "t = " + diffusionTerm + gradTerm + " + " + sourceTerm);
                } else {
                    component.setText(PARTIAL_DIFF + "[" + var.getName() + "]/" + PARTIAL_DIFF + "t = " + diffusionTerm + gradTerm);
                }
            } else if (node.getUserObject() instanceof OdeEquation) {
                OdeEquation odeEquation = (OdeEquation) node.getUserObject();
                Variable var = odeEquation.getVariable();
                component.setToolTipText("ODE Equation");
                component.setText("d[" + var.getName() + "]/dt = " + odeEquation.getRateExpression().infix());
            } else if (node.getUserObject() instanceof MembraneRegionEquation) {
                MembraneRegionEquation membraneRegionEquation = (MembraneRegionEquation) node.getUserObject();
                Variable var = membraneRegionEquation.getVariable();
                component.setToolTipText("Membrane Region Equation");
                component.setText("Membrane Region Equation for " + var.getName());
            } else if (node.getUserObject() instanceof JumpCondition) {
                JumpCondition jumpCondition = (JumpCondition) node.getUserObject();
                Variable var = jumpCondition.getVariable();
                component.setToolTipText("Jump Condition");
                component.setText("Flux for " + var.getName());
            } else if (node.getUserObject() instanceof Constant) {
                Constant constant = (Constant) node.getUserObject();
                component.setToolTipText("Constant");
                component.setText(constant.getName() + " = " + constant.getExpression().infix());
            } else if (node.getUserObject() instanceof Function) {
                Function function = (Function) node.getUserObject();
                component.setToolTipText("Function");
                component.setText(function.getName() + " = " + function.getExpression().infix());
            } else if (node.getUserObject() instanceof SubDomain) {
                SubDomain subDomain = (SubDomain) node.getUserObject();
                component.setToolTipText("SubDomain");
                component.setText(subDomain.getName());
            } else if (node.getUserObject() instanceof FastSystem) {
                component.setToolTipText("Fast System");
                component.setText("Fast System");
            } else if (node.getUserObject() instanceof FastInvariant) {
                FastInvariant fi = (FastInvariant) node.getUserObject();
                component.setToolTipText("Fast Invariant");
                component.setText("fast invariant: " + fi.getFunction().infix());
            } else if (node.getUserObject() instanceof FastRate) {
                FastRate fr = (FastRate) node.getUserObject();
                component.setToolTipText("Fast Rate");
                component.setText("fast rate: " + fr.getFunction().infix());
            } else if (node.getUserObject() instanceof Annotation) {
                Annotation annotation = (Annotation) node.getUserObject();
                component.setToolTipText("Annotation");
                component.setText("\"" + annotation + "\"");
            } else {
            }
            if (selectedFont == null && component.getFont() != null) {
                selectedFont = component.getFont().deriveFont(Font.BOLD);
            }
            if (unselectedFont == null && component.getFont() != null) {
                unselectedFont = component.getFont().deriveFont(Font.PLAIN);
            }
            if (bLoaded) {
                component.setFont(selectedFont);
            } else {
                component.setFont(unselectedFont);
            }
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
    // 
    return component;
}
Also used : JumpCondition(cbit.vcell.math.JumpCondition) Variable(cbit.vcell.math.Variable) Constant(cbit.vcell.math.Constant) JLabel(javax.swing.JLabel) FastRate(cbit.vcell.math.FastRate) BioModelNode(cbit.vcell.desktop.BioModelNode) FastInvariant(cbit.vcell.math.FastInvariant) Annotation(cbit.vcell.desktop.Annotation) PdeEquation(cbit.vcell.math.PdeEquation) SubDomain(cbit.vcell.math.SubDomain) Function(cbit.vcell.math.Function) OdeEquation(cbit.vcell.math.OdeEquation) FastSystem(cbit.vcell.math.FastSystem) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation)

Example 8 with PdeEquation

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

the class ModelOptimizationSpec method fromMath.

/**
 * Insert the method's description here.
 * Creation date: (11/1/2005 8:11:32 PM)
 * @return cbit.vcell.mapping.MathSystemHash
 * @param mathDesc cbit.vcell.math.MathDescription
 */
private static MathSystemHash fromMath(cbit.vcell.math.MathDescription mathDesc) {
    MathSystemHash hash = new MathSystemHash();
    hash.addSymbol(new MathSystemHash.IndependentVariable("t"));
    hash.addSymbol(new MathSystemHash.IndependentVariable("x"));
    hash.addSymbol(new MathSystemHash.IndependentVariable("y"));
    hash.addSymbol(new MathSystemHash.IndependentVariable("z"));
    Variable[] vars = (Variable[]) BeanUtils.getArray(mathDesc.getVariables(), Variable.class);
    for (int i = 0; i < vars.length; i++) {
        hash.addSymbol(new MathSystemHash.Variable(vars[i].getName(), vars[i].getExpression()));
    }
    SubDomain[] subDomains = (SubDomain[]) BeanUtils.getArray(mathDesc.getSubDomains(), SubDomain.class);
    for (int i = 0; i < subDomains.length; i++) {
        Equation[] equations = (Equation[]) BeanUtils.getArray(subDomains[i].getEquations(), Equation.class);
        for (int j = 0; j < equations.length; j++) {
            MathSystemHash.Variable var = (MathSystemHash.Variable) hash.getSymbol(equations[j].getVariable().getName());
            hash.addSymbol(new MathSystemHash.VariableInitial(var, equations[j].getInitialExpression()));
            if (equations[j] instanceof PdeEquation) {
                // hash.addSymbol(new MathSystemHash.VariableDerivative(var,pde.getRateExpression()));
                throw new RuntimeException("MathSystemHash doesn't yet support spatial models");
            } else if (equations[j] instanceof VolumeRegionEquation) {
                // hash.addSymbol(new MathSystemHash.VariableDerivative(var,vre.getRateExpression()));
                throw new RuntimeException("MathSystemHash doesn't yet support spatial models");
            } else if (equations[j] instanceof MembraneRegionEquation) {
                // hash.addSymbol(new MathSystemHash.VariableDerivative(var,mre.getRateExpression()));
                throw new RuntimeException("MathSystemHash doesn't yet support spatial models");
            } else if (equations[j] instanceof FilamentRegionEquation) {
                // hash.addSymbol(new MathSystemHash.VariableDerivative(var,fre.getRateExpression()));
                throw new RuntimeException("MathSystemHash doesn't yet support spatial models");
            } else if (equations[j] instanceof OdeEquation) {
                OdeEquation ode = (OdeEquation) equations[j];
                hash.addSymbol(new MathSystemHash.VariableDerivative(var, ode.getRateExpression()));
            }
        }
    }
    return hash;
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) OdeEquation(cbit.vcell.math.OdeEquation) FilamentRegionEquation(cbit.vcell.math.FilamentRegionEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) PdeEquation(cbit.vcell.math.PdeEquation) Equation(cbit.vcell.math.Equation) SubDomain(cbit.vcell.math.SubDomain) PdeEquation(cbit.vcell.math.PdeEquation) FilamentRegionEquation(cbit.vcell.math.FilamentRegionEquation) OdeEquation(cbit.vcell.math.OdeEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation)

Example 9 with PdeEquation

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

the class FiniteVolumeFileWriter method writeMembrane_jumpConditions.

/**
 *JUMP_CONDITION_BEGIN r
 *INFLUX 0.0;
 *OUTFLUX 0.0;
 *JUMP_CONDITION_END
 * @throws ExpressionException
 * @throws MathException
 */
private void writeMembrane_jumpConditions(MembraneSubDomain msd) throws ExpressionException, MathException {
    Enumeration<JumpCondition> enum1 = msd.getJumpConditions();
    // equations for boundaryValues for inner compartment subdomain
    CompartmentSubDomain innerCompSubDomain = msd.getInsideCompartment();
    Enumeration<Equation> innercompSubDomEqnsEnum = innerCompSubDomain.getEquations();
    while (innercompSubDomEqnsEnum.hasMoreElements()) {
        Equation eqn = innercompSubDomEqnsEnum.nextElement();
        if (eqn instanceof PdeEquation) {
            PdeEquation pdeEqn = (PdeEquation) eqn;
            BoundaryConditionValue boundaryValue = pdeEqn.getBoundaryConditionValue(msd.getName());
            if (boundaryValue != null) {
                // check if the type of BoundaryConditionSpec for this membraneSubDomain (msd) in the (inner) compartmentSubDomain is Flux; if not, it cannot be handled.
                BoundaryConditionSpec bcs = innerCompSubDomain.getBoundaryConditionSpec(msd.getName());
                if (bcs == null) {
                    throw new MathException("No Boundary type specified for '" + msd.getName() + "' in '" + innerCompSubDomain.getName() + "'.");
                }
                if (bcs != null && !bcs.getBoundaryConditionType().compareEqual(BoundaryConditionType.getNEUMANN()) && !bChomboSolver) {
                    throw new MathException("Boundary type '" + bcs.getBoundaryConditionType().boundaryTypeStringValue() + "' for compartmentSubDomain '" + innerCompSubDomain.getName() + "' not handled by the chosen solver. Expecting boundary condition of type 'Flux'.");
                }
                if (pdeEqn.getVariable().getDomain() == null || pdeEqn.getVariable().getDomain().getName().equals(msd.getInsideCompartment().getName())) {
                    printWriter.println("JUMP_CONDITION_BEGIN " + pdeEqn.getVariable().getName());
                    Expression flux = subsituteExpression(boundaryValue.getBoundaryConditionExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
                    String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
                    printWriter.println(bcs.getBoundaryConditionType().boundaryTypeStringValue().toUpperCase() + " " + msd.getInsideCompartment().getName() + " " + infix + ";");
                    printWriter.println("JUMP_CONDITION_END");
                    printWriter.println();
                }
            }
        }
    }
    // equations for boundaryValues for outer compartment subdomain
    CompartmentSubDomain outerCompSubDomain = msd.getOutsideCompartment();
    Enumeration<Equation> outerCompSubDomEqnsEnum = outerCompSubDomain.getEquations();
    while (outerCompSubDomEqnsEnum.hasMoreElements()) {
        Equation eqn = outerCompSubDomEqnsEnum.nextElement();
        if (eqn instanceof PdeEquation) {
            PdeEquation pdeEqn = (PdeEquation) eqn;
            BoundaryConditionValue boundaryValue = pdeEqn.getBoundaryConditionValue(msd.getName());
            if (boundaryValue != null) {
                // check if the type of BoundaryConditionSpec for this membraneSubDomain (msd) in the (inner) compartmentSubDomain is Flux; if not, it cannot be handled.
                BoundaryConditionSpec bcs = outerCompSubDomain.getBoundaryConditionSpec(msd.getName());
                if (bcs != null && !bcs.getBoundaryConditionType().compareEqual(BoundaryConditionType.getNEUMANN()) && !bChomboSolver) {
                    throw new MathException("Boundary type '" + bcs.getBoundaryConditionType().boundaryTypeStringValue() + "' for compartmentSubDomain '" + outerCompSubDomain.getName() + "' not handled by the chosen solver. Expecting boundary condition of type 'Flux'.");
                }
                if (pdeEqn.getVariable().getDomain() == null || pdeEqn.getVariable().getDomain().getName().equals(msd.getOutsideCompartment().getName())) {
                    printWriter.println("JUMP_CONDITION_BEGIN " + pdeEqn.getVariable().getName());
                    Expression flux = subsituteExpression(boundaryValue.getBoundaryConditionExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
                    String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
                    printWriter.println(bcs.getBoundaryConditionType().boundaryTypeStringValue().toUpperCase() + " " + msd.getOutsideCompartment().getName() + " " + infix + ";");
                    printWriter.println("JUMP_CONDITION_END");
                    printWriter.println();
                }
            }
        }
    }
    while (enum1.hasMoreElements()) {
        JumpCondition jc = enum1.nextElement();
        printWriter.println("JUMP_CONDITION_BEGIN " + jc.getVariable().getName());
        // influx
        if (jc.getVariable().getDomain() == null || jc.getVariable().getDomain().getName().equals(msd.getInsideCompartment().getName())) {
            Expression flux = subsituteExpression(jc.getInFluxExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
            String infix = replaceVolumeVariable(getSimulationTask(), msd, flux);
            printWriter.println(BoundaryConditionType.NEUMANN_STRING.toUpperCase() + " " + msd.getInsideCompartment().getName() + " " + infix + ";");
        }
        if (jc.getVariable().getDomain() == null || jc.getVariable().getDomain().getName().equals(msd.getOutsideCompartment().getName())) {
            // outflux
            Expression flux = subsituteExpression(jc.getOutFluxExpression(), VariableDomain.VARIABLEDOMAIN_MEMBRANE);
            String infix = replaceVolumeVariable(simTask, msd, flux);
            printWriter.println(BoundaryConditionType.NEUMANN_STRING.toUpperCase() + " " + msd.getOutsideCompartment().getName() + " " + infix + ";");
        }
        printWriter.println("JUMP_CONDITION_END");
        printWriter.println();
    }
}
Also used : JumpCondition(cbit.vcell.math.JumpCondition) PdeEquation(cbit.vcell.math.PdeEquation) BoundaryConditionValue(cbit.vcell.math.PdeEquation.BoundaryConditionValue) Expression(cbit.vcell.parser.Expression) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) MathException(cbit.vcell.math.MathException) 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) BoundaryConditionSpec(cbit.vcell.math.SubDomain.BoundaryConditionSpec)

Example 10 with PdeEquation

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

Aggregations

PdeEquation (cbit.vcell.math.PdeEquation)15 Expression (cbit.vcell.parser.Expression)12 Equation (cbit.vcell.math.Equation)10 SubDomain (cbit.vcell.math.SubDomain)9 Variable (cbit.vcell.math.Variable)9 VolVariable (cbit.vcell.math.VolVariable)9 MemVariable (cbit.vcell.math.MemVariable)8 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)8 MembraneRegionEquation (cbit.vcell.math.MembraneRegionEquation)7 OdeEquation (cbit.vcell.math.OdeEquation)7 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)7 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)6 JumpCondition (cbit.vcell.math.JumpCondition)6 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)6 MathDescription (cbit.vcell.math.MathDescription)5 Vector (java.util.Vector)5 FilamentVariable (cbit.vcell.math.FilamentVariable)4 ReservedVariable (cbit.vcell.math.ReservedVariable)4 VolumeRegionEquation (cbit.vcell.math.VolumeRegionEquation)4 Constant (cbit.vcell.math.Constant)3