Search in sources :

Example 71 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class ChomboMeshSpecificationPanel method updateDisplay.

private void updateDisplay(boolean bSolverChanged) throws ChomboGeometryException, ChomboInvalidGeometryException {
    if (!simulation.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
        setVisible(false);
        return;
    }
    Geometry geometry = simulation.getMathDescription().getGeometry();
    Extent extent = geometry.getExtent();
    int dimension = geometry.getDimension();
    switch(dimension) {
        case 0:
            setVisible(false);
            break;
        case 1:
            getGeometrySizeTextField().setText("" + extent.getX());
            NyLabel.setVisible(false);
            NyComboBox.setVisible(false);
            NzLabel.setVisible(false);
            NzComboBox.setVisible(false);
            break;
        case 2:
            getGeometrySizeTextField().setText("(" + extent.getX() + ", " + extent.getY() + ")");
            NzLabel.setVisible(false);
            NzComboBox.setVisible(false);
            break;
        case 3:
            getGeometrySizeTextField().setText("(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")");
            break;
    }
    String error;
    ChomboMeshRecommendation meshRecommendation = new ChomboMeshValidator(geometry.getDimension(), geometry.getExtent(), simulation.getSolverTaskDescription().getChomboSolverSpec().getBlockFactor()).computeMeshSpecs();
    if (meshRecommendation.validate()) {
        // remove ActionListener, here we only want to set values
        removeComboBoxListener();
        HComboBox.removeAll();
        NxComboBox.removeAll();
        NyComboBox.removeAll();
        NzComboBox.removeAll();
        for (ChomboMeshSpec meshSpec : meshRecommendation.validMeshSpecList) {
            HComboBox.addItem((float) meshSpec.H);
            NxComboBox.addItem(meshSpec.Nx[0]);
            if (geometry.getDimension() > 1) {
                NyComboBox.addItem(meshSpec.Nx[1]);
                if (geometry.getDimension() == 3) {
                    NzComboBox.addItem(meshSpec.Nx[2]);
                }
            }
        }
        addComboBoxListener();
        if (bSolverChanged) {
            NxComboBox.setSelectedIndex(0);
        } else {
            ISize samplingSize = simulation.getMeshSpecification().getSamplingSize();
            NxComboBox.setSelectedItem(samplingSize.getX());
            // double check if existing mesh size is an option in drop down
            Integer selectedNx = (Integer) NxComboBox.getSelectedItem();
            Integer selectedNy = geometry.getDimension() > 1 ? (Integer) NyComboBox.getSelectedItem() : 1;
            Integer selectedNz = geometry.getDimension() > 2 ? (Integer) NzComboBox.getSelectedItem() : 1;
            boolean bMatchFound = selectedNx == samplingSize.getX() && (dimension < 2 || selectedNy == samplingSize.getY()) && (dimension < 3 || selectedNz == samplingSize.getZ());
            if (!bMatchFound) {
                NxComboBox.setSelectedIndex(0);
                throw new ChomboGeometryException(ChomboMeshValidator.ERROR_MESSAGE_INCOMPATIBLE_MESH_SIZE);
            }
        }
    } else {
        throw new ChomboInvalidGeometryException(meshRecommendation);
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) ChomboMeshRecommendation(org.vcell.chombo.ChomboMeshValidator.ChomboMeshRecommendation) ChomboMeshValidator(org.vcell.chombo.ChomboMeshValidator) ChomboGeometryException(cbit.vcell.geometry.ChomboGeometryException) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ChomboMeshSpec(org.vcell.chombo.ChomboMeshValidator.ChomboMeshSpec) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException)

Example 72 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class ChomboMeshSpecificationPanel method updateMesh.

private void updateMesh(int selectedIndex) {
    Geometry geometry = simulation.getMathDescription().getGeometry();
    if (selectedIndex >= HComboBox.getItemCount() || selectedIndex >= NxComboBox.getItemCount() || geometry.getDimension() > 1 && selectedIndex >= NyComboBox.getItemCount() || geometry.getDimension() > 2 && selectedIndex >= NzComboBox.getItemCount()) {
        return;
    }
    String error = null;
    // remove ActionListener, here we only want to set values
    removeComboBoxListener();
    HComboBox.setSelectedIndex(selectedIndex);
    NxComboBox.setSelectedIndex(selectedIndex);
    if (geometry.getDimension() > 1) {
        NyComboBox.setSelectedIndex(selectedIndex);
        if (geometry.getDimension() > 2) {
            NzComboBox.setSelectedIndex(selectedIndex);
        }
    }
    addComboBoxListener();
    Integer Nx = (Integer) NxComboBox.getSelectedItem();
    Integer Ny = geometry.getDimension() > 1 ? (Integer) NyComboBox.getSelectedItem() : 1;
    Integer Nz = geometry.getDimension() > 2 ? (Integer) NzComboBox.getSelectedItem() : 1;
    try {
        ISize iSize = new ISize(Nx, Ny, Nz);
        simulation.getMeshSpecification().setSamplingSize(iSize);
    } catch (NumberFormatException nexc) {
        error = "NumberFormatException " + nexc.getMessage();
    } catch (java.beans.PropertyVetoException pexc) {
        error = pexc.getMessage();
    }
    if (error != null) {
        DialogUtils.showErrorDialog(this, "Error setting mesh size : " + error);
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) ISize(org.vcell.util.ISize)

Example 73 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class SimulationSummaryPanel method displayMesh.

/**
 * Comment
 */
private void displayMesh() {
    try {
        boolean isSpatial = getSimulation().isSpatial();
        getJLabel11().setVisible(isSpatial);
        getJLabelMesh().setVisible(isSpatial);
        labelMeshRefinementTitle.setVisible(isSpatial);
        getJLabelMeshRefinement().setVisible(isSpatial);
        labelFinestMeshTitle.setVisible(isSpatial);
        labelFinestMesh.setVisible(isSpatial);
        labelRefinementRoiTitle.setVisible(isSpatial);
        labelRefinementRoi.setVisible(isSpatial);
        labelViewLevelMeshTitle.setVisible(isSpatial);
        labelViewLevelMesh.setVisible(isSpatial);
        if (getSimulation() != null && getSimulation().getMeshSpecification() != null) {
            ISize samplingSize = getSimulation().getMeshSpecification().getSamplingSize();
            String labelText = "";
            int dimension = getSimulation().getMeshSpecification().getGeometry().getDimension();
            switch(dimension) {
                case 0:
                    {
                        labelText = "error: no mesh expected";
                        break;
                    }
                default:
                    {
                        labelText = GuiUtils.getMeshSizeText(dimension, samplingSize, true) + " elements";
                        break;
                    }
            }
            getJLabelMesh().setText(labelText);
            ChomboSolverSpec chomboSolverSpec = getSimulation().getSolverTaskDescription().getChomboSolverSpec();
            if (getSimulation().getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
                int numRefinementLevels = chomboSolverSpec.getNumRefinementLevels();
                labelMeshRefinementTitle.setVisible(true);
                getJLabelMeshRefinement().setVisible(true);
                labelFinestMeshTitle.setVisible(true);
                labelFinestMesh.setVisible(true);
                ISize finestISize = chomboSolverSpec.getFinestSamplingSize(samplingSize);
                String text = GuiUtils.getMeshSizeText(dimension, finestISize, true);
                labelFinestMesh.setText(text);
                boolean bHasRefinement = numRefinementLevels > 0;
                if (bHasRefinement) {
                    String refinementText = numRefinementLevels + " level(s)";
                    getJLabelMeshRefinement().setText(refinementText);
                    labelRefinementRoiTitle.setVisible(true);
                    labelRefinementRoi.setVisible(true);
                    String roiText = "Membrane ROI(s): " + chomboSolverSpec.getMembraneRefinementRois().size() + "; Volume ROI(s): " + chomboSolverSpec.getVolumeRefinementRois().size() + ";";
                    labelViewLevelMeshTitle.setVisible(true);
                    labelViewLevelMesh.setVisible(true);
                    labelViewLevelMesh.setText(GuiUtils.getMeshSizeText(dimension, chomboSolverSpec.getViewLevelSamplingSize(samplingSize), true));
                    labelRefinementRoi.setText(roiText);
                } else {
                    labelMeshRefinementTitle.setVisible(false);
                    meshRefinementLabel.setVisible(false);
                    labelFinestMeshTitle.setVisible(false);
                    labelFinestMesh.setVisible(false);
                    labelRefinementRoiTitle.setVisible(false);
                    labelRefinementRoi.setVisible(false);
                    labelViewLevelMeshTitle.setVisible(false);
                    labelViewLevelMesh.setVisible(false);
                }
            } else {
                labelMeshRefinementTitle.setVisible(false);
                getJLabelMeshRefinement().setVisible(false);
                labelFinestMesh.setVisible(false);
                labelFinestMeshTitle.setVisible(false);
                labelRefinementRoiTitle.setVisible(false);
                labelRefinementRoi.setVisible(false);
                labelViewLevelMeshTitle.setVisible(false);
                labelViewLevelMesh.setVisible(false);
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        getJLabelMesh().setText("");
    }
}
Also used : ISize(org.vcell.util.ISize) ChomboSolverSpec(org.vcell.chombo.ChomboSolverSpec) PropertyVetoException(java.beans.PropertyVetoException)

Example 74 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class ClientDocumentManager method save.

/**
 * Insert the method's description here.
 * Creation date: (2/5/01 4:58:40 PM)
 */
public VCImage save(VCImage vcImage) throws DataAccessException {
    try {
        String vcImageXML = null;
        try {
            vcImageXML = XmlHelper.imageToXML(vcImage);
        } catch (XmlParseException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException(e.getMessage());
        }
        String savedVCImageXML = sessionManager.getUserMetaDbServer().saveVCImage(new BigString(vcImageXML)).toString();
        VCImage savedVCImage = null;
        try {
            savedVCImage = XmlHelper.XMLToImage(savedVCImageXML);
        } catch (XmlParseException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException(e.getMessage());
        }
        savedVCImage.refreshDependencies();
        KeyValue savedKey = savedVCImage.getVersion().getVersionKey();
        if (xmlHash.get(savedKey) == null) {
            xmlHash.put(savedKey, savedVCImageXML);
        }
        try {
            ISize size = new ISize(savedVCImage.getNumX(), savedVCImage.getNumY(), savedVCImage.getNumZ());
            GIFImage browseData = BrowseImage.makeBrowseGIFImage(savedVCImage);
            VCImageInfo savedVCImageInfo = new VCImageInfo(savedVCImage.getVersion(), size, savedVCImage.getExtent(), browseData, VCellSoftwareVersion.fromSystemProperty());
            imgInfoHash.put(savedKey, savedVCImageInfo);
            fireDatabaseInsert(new DatabaseEvent(this, DatabaseEvent.INSERT, null, savedVCImageInfo));
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
        return savedVCImage;
    } catch (RemoteProxyException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(VCellErrorMessages.FAIL_SAVE_MESSAGE + "\n\n" + e.getMessage());
    }
}
Also used : GIFImage(cbit.image.GIFImage) KeyValue(org.vcell.util.document.KeyValue) ISize(org.vcell.util.ISize) VCImage(cbit.image.VCImage) BigString(org.vcell.util.BigString) XmlParseException(cbit.vcell.xml.XmlParseException) BigString(org.vcell.util.BigString) DataAccessException(org.vcell.util.DataAccessException) VCImageInfo(cbit.image.VCImageInfo) ParseException(java.text.ParseException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)

Example 75 with ISize

use of org.vcell.util.ISize 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

ISize (org.vcell.util.ISize)139 Extent (org.vcell.util.Extent)53 Origin (org.vcell.util.Origin)46 CartesianMesh (cbit.vcell.solvers.CartesianMesh)27 IOException (java.io.IOException)22 VCImage (cbit.image.VCImage)21 VCImageUncompressed (cbit.image.VCImageUncompressed)21 Geometry (cbit.vcell.geometry.Geometry)21 ExpressionException (cbit.vcell.parser.ExpressionException)21 DataAccessException (org.vcell.util.DataAccessException)21 RegionImage (cbit.vcell.geometry.RegionImage)20 ImageException (cbit.image.ImageException)19 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)19 File (java.io.File)18 MathException (cbit.vcell.math.MathException)17 ArrayList (java.util.ArrayList)16 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)14 Expression (cbit.vcell.parser.Expression)14 PropertyVetoException (java.beans.PropertyVetoException)14 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)13