Search in sources :

Example 11 with VolumeRegionVariable

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

the class MathOverridesPanel method jMenuItemPaste_ActionPerformed.

/**
 * Comment
 */
private void jMenuItemPaste_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
    java.util.Vector<String> pasteDescriptionsV = new java.util.Vector<String>();
    java.util.Vector<Expression> newConstantsV = new java.util.Vector<Expression>();
    java.util.Vector<String> changedParameterNamesV = new java.util.Vector<String>();
    try {
        if (actionEvent.getSource().equals(getJMenuItemPaste()) || actionEvent.getSource().equals(getJMenuItemPasteAll())) {
            int[] rows = null;
            if (actionEvent.getSource() == getJMenuItemPasteAll()) {
                rows = new int[getJTableFixed().getRowCount()];
                for (int i = 0; i < rows.length; i += 1) {
                    rows[i] = i;
                }
            } else {
                rows = getJTableFixed().getSelectedRows();
            }
            Object pasteThis = VCellTransferable.getFromClipboard(VCellTransferable.OBJECT_FLAVOR);
            for (int i = 0; i < rows.length; i += 1) {
                if (pasteThis instanceof VCellTransferable.ResolvedValuesSelection) {
                    VCellTransferable.ResolvedValuesSelection rvs = (VCellTransferable.ResolvedValuesSelection) pasteThis;
                    for (int j = 0; j < rvs.getPrimarySymbolTableEntries().length; j += 1) {
                        Constant pastedConstant = null;
                        if (rvs.getPrimarySymbolTableEntries()[j] instanceof Constant) {
                            pastedConstant = (Constant) rvs.getPrimarySymbolTableEntries()[j];
                        } else if (rvs.getAlternateSymbolTableEntries() != null && rvs.getAlternateSymbolTableEntries()[j] instanceof Constant) {
                            pastedConstant = (Constant) rvs.getAlternateSymbolTableEntries()[j];
                        }
                        // 
                        if (pastedConstant == null && (rvs.getPrimarySymbolTableEntries()[j] instanceof Function) || (rvs.getPrimarySymbolTableEntries()[j] instanceof VolVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof VolumeRegionVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof MemVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof MembraneRegionVariable)) {
                            MathDescription mathDescription = getMathOverrides().getSimulation().getMathDescription();
                            Enumeration<Constant> constants = mathDescription.getConstants();
                            while (constants.hasMoreElements()) {
                                Constant constant = constants.nextElement();
                                if (constant.getName().startsWith(rvs.getPrimarySymbolTableEntries()[j].getName() + DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX)) {
                                    pastedConstant = new Constant(constant.getName(), rvs.getExpressionValues()[j]);
                                }
                            }
                        }
                        // 
                        // find row of math overrides table with the same name as the pastedConstant and propose to change that override to the pasted value
                        // 
                        String rowName = (String) getJTableFixed().getValueAt(rows[i], MathOverridesTableModel.COLUMN_PARAMETER);
                        if (pastedConstant != null && pastedConstant.getName().equals(rowName)) {
                            changedParameterNamesV.add(rowName);
                            newConstantsV.add(rvs.getExpressionValues()[j]);
                            String originalValueDescription = null;
                            if (getMathOverrides().getConstantArraySpec(rowName) != null) {
                                originalValueDescription = getMathOverrides().getConstantArraySpec(rowName).toString();
                            } else if (getMathOverrides().getActualExpression(rowName, 0) != null) {
                                originalValueDescription = getMathOverrides().getActualExpression(rowName, 0).infix();
                            } else {
                                throw new Exception("MathOverridesPanel can't find value for '" + rowName + "'");
                            }
                            pasteDescriptionsV.add(VCellCopyPasteHelper.formatPasteList(rowName, pastedConstant.getName(), originalValueDescription, rvs.getExpressionValues()[j].infix() + ""));
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        PopupGenerator.showErrorDialog(this, "Paste failed during pre-check (no changes made).\n" + e.getClass().getName() + " " + e.getMessage(), e);
        return;
    }
    // Do paste
    try {
        if (pasteDescriptionsV.size() > 0) {
            String[] pasteDescriptionArr = new String[pasteDescriptionsV.size()];
            pasteDescriptionsV.copyInto(pasteDescriptionArr);
            String[] changedParameterNamesArr = new String[changedParameterNamesV.size()];
            changedParameterNamesV.copyInto(changedParameterNamesArr);
            VCellCopyPasteHelper.chooseApplyPaste(this, pasteDescriptionArr, getMathOverrides(), changedParameterNamesArr, newConstantsV);
        } else {
            PopupGenerator.showInfoDialog(this, "No paste items match the destination (no changes made).");
        }
    } catch (Throwable e) {
        PopupGenerator.showErrorDialog(this, "Paste Error\n" + e.getClass().getName() + " " + e.getMessage(), e);
    }
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolVariable(cbit.vcell.math.VolVariable) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) VCellTransferable(cbit.vcell.desktop.VCellTransferable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) Function(cbit.vcell.math.Function) MemVariable(cbit.vcell.math.MemVariable) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression)

Example 12 with VolumeRegionVariable

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

the class XmlReader method getVolumeRegionEquation.

/**
 * This method returns a VolumeRegionEquation from a XML Element.
 * Creation date: (5/17/2001 3:52:40 PM)
 * @return cbit.vcell.math.VolumeRegionEquation
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private VolumeRegionEquation getVolumeRegionEquation(Element param, MathDescription mathDesc) throws XmlParseException {
    // get attributes
    String varname = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    // try a VolumeRegionVariable
    VolumeRegionVariable varref = (VolumeRegionVariable) mathDesc.getVariable(varname);
    if (varref == null) {
        throw new XmlParseException("The reference to the VolumeRegion variable " + varname + " could not be resolved!");
    }
    // get Initial condition
    String temp = param.getChildText(XMLTags.InitialTag, vcNamespace);
    Expression exp = unMangleExpression(temp);
    // ** Create the Equation **
    VolumeRegionEquation volRegEq = new VolumeRegionEquation(varref, exp);
    // set the Uniform Rate
    temp = param.getChildText(XMLTags.UniformRateTag, vcNamespace);
    exp = unMangleExpression(temp);
    volRegEq.setUniformRateExpression(exp);
    // Set the Volume Rate
    temp = param.getChildText(XMLTags.VolumeRateTag, vcNamespace);
    exp = unMangleExpression(temp);
    volRegEq.setVolumeRateExpression(exp);
    return volRegEq;
}
Also used : VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) Expression(cbit.vcell.parser.Expression) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation)

Example 13 with VolumeRegionVariable

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

the class XmlReader method getComputeCentroid.

private ComputeCentroidComponentEquation getComputeCentroid(Element param, MathDescription mathDesc) throws XmlParseException {
    // get attributes
    String varname = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    // find reference in the dictionnary
    // try a MembraneRegionVariable
    VolumeRegionVariable varref = (VolumeRegionVariable) mathDesc.getVariable(varname);
    if (varref == null) {
        throw new XmlParseException("The reference to the Volume Region variable " + varname + " could not be resolved!");
    }
    CentroidComponent normalComponent = null;
    String normalComponentString = param.getAttributeValue(XMLTags.ComputeCentroidComponentAttrTag);
    if (normalComponentString.equals(XMLTags.ComputeCentroidComponentAttrTagValue_X)) {
        normalComponent = CentroidComponent.X;
    } else if (normalComponentString.equals(XMLTags.ComputeCentroidComponentAttrTagValue_Y)) {
        normalComponent = CentroidComponent.Y;
    } else if (normalComponentString.equals(XMLTags.ComputeCentroidComponentAttrTagValue_Z)) {
        normalComponent = CentroidComponent.Z;
    }
    ComputeCentroidComponentEquation centroid = new ComputeCentroidComponentEquation(varref, normalComponent);
    return centroid;
}
Also used : VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ComputeCentroidComponentEquation(cbit.vcell.math.ComputeCentroidComponentEquation) CentroidComponent(cbit.vcell.math.ComputeCentroidComponentEquation.CentroidComponent)

Example 14 with VolumeRegionVariable

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

the class MathTestingUtilities method substituteWithExactSolution.

/**
 * Insert the method's description here.
 * Creation date: (1/24/2003 10:18:14 AM)
 * @return cbit.vcell.parser.Expression
 * @param origExp cbit.vcell.parser.Expression
 * @param subDomain cbit.vcell.math.SubDomain
 */
private static Expression substituteWithExactSolution(Expression origExp, CompartmentSubDomain subDomain, MathDescription exactMathDesc) throws ExpressionException {
    Expression substitutedExp = new Expression(origExp);
    substitutedExp.bindExpression(exactMathDesc);
    substitutedExp = MathUtilities.substituteFunctions(substitutedExp, exactMathDesc);
    substitutedExp.bindExpression(null);
    substitutedExp = substitutedExp.flatten();
    substitutedExp.bindExpression(exactMathDesc);
    String[] symbols = substitutedExp.getSymbols();
    for (int i = 0; i < symbols.length; i++) {
        Variable var = (Variable) substitutedExp.getSymbolBinding(symbols[i]);
        if (var instanceof VolVariable) {
            String exactVarName = var.getName() + "_" + subDomain.getName() + "_exact";
            substitutedExp.substituteInPlace(new Expression(var.getName()), new Expression(exactVarName));
        } else if (var instanceof VolumeRegionVariable || var instanceof MemVariable || var instanceof MembraneRegionVariable || var instanceof FilamentVariable || var instanceof FilamentRegionVariable) {
            throw new RuntimeException("variable substitution not yet implemented for Variable type " + var.getClass().getName() + "(" + var.getName() + ")");
        }
    }
    substitutedExp.bindExpression(null);
    return substitutedExp;
}
Also used : VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) SensVariable(cbit.vcell.solver.ode.SensVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) MemVariable(cbit.vcell.math.MemVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) Expression(cbit.vcell.parser.Expression) VolVariable(cbit.vcell.math.VolVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) FilamentVariable(cbit.vcell.math.FilamentVariable)

Example 15 with VolumeRegionVariable

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

VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)17 MemVariable (cbit.vcell.math.MemVariable)14 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)14 VolVariable (cbit.vcell.math.VolVariable)14 Variable (cbit.vcell.math.Variable)11 FilamentVariable (cbit.vcell.math.FilamentVariable)10 Expression (cbit.vcell.parser.Expression)10 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)8 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)7 ReservedVariable (cbit.vcell.math.ReservedVariable)7 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)6 InsideVariable (cbit.vcell.math.InsideVariable)6 OutsideVariable (cbit.vcell.math.OutsideVariable)6 SubDomain (cbit.vcell.math.SubDomain)6 Constant (cbit.vcell.math.Constant)5 MathDescription (cbit.vcell.math.MathDescription)5 Function (cbit.vcell.math.Function)4 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)4 PointSubDomain (cbit.vcell.math.PointSubDomain)4 PointVariable (cbit.vcell.math.PointVariable)4