Search in sources :

Example 71 with Coordinate

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

the class CurveEditorTool method mousePressed.

/**
 * This method was created in VisualAge.
 * @param event MouseEvent
 */
public void mousePressed(MouseEvent event) {
    if (!getProperlyConfigured()) {
        return;
    }
    if ((event.getModifiers() & event.BUTTON3_MASK) != 0) {
        setTool(TOOL_SELECT);
        return;
    }
    if (getTool() == TOOL_ADDCP) {
        if (getCurveRenderer().getSelection() != null && getCurveRenderer().getSelection().getCurve() instanceof ControlPointCurve && ((ControlPointCurve) getCurveRenderer().getSelection().getCurve()).isControlPointAddable()) {
            ((ControlPointCurve) (getCurveRenderer().getSelection().getCurve())).insertControlPoint(getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())), getCurveRenderer().getSelection().getControlPoint());
        }
        getVcellDrawable().repaint();
    } else if (getTool() == TOOL_LINE || getTool() == TOOL_SPLINE || getTool() == TOOL_POINT) {
        CurveSelectionInfo selectedCSI = getCurveRenderer().getSelection();
        if (selectedCSI == null || getTool() == TOOL_POINT) {
            boolean wasFromCVP = false;
            if (getCurveValueProvider() != null && getCurveValueProvider().providesInitalCurve(getTool(), getWorldCoordinateValue(event.getPoint()))) {
                // Returns null if curve shouldn't be started at this point
                selectedCSI = getCurveValueProvider().getInitalCurveSelection(getTool(), getWorldCoordinateValue(event.getPoint()));
                wasFromCVP = true;
            } else if (getTool() == TOOL_LINE) {
                selectedCSI = new CurveSelectionInfo(new PolyLine());
            } else if (getTool() == TOOL_SPLINE) {
                selectedCSI = new CurveSelectionInfo(new Spline());
            } else if (getTool() == TOOL_POINT) {
                selectedCSI = new CurveSelectionInfo(new SinglePoint());
            }
            if (selectedCSI != null) {
                if (getCurveValueProvider() != null) {
                    getCurveValueProvider().setDescription(selectedCSI.getCurve());
                }
                getCurveRenderer().addCurve(selectedCSI.getCurve());
                getCurveRenderer().renderPropertySubSelectionType(selectedCSI.getCurve(), CurveRenderer.SUBSELECTION_CONTROL_POINT);
                getCurveRenderer().renderPropertyEditable(selectedCSI.getCurve(), (!wasFromCVP ? true : false));
            }
        }
        // 
        if (selectedCSI != null && selectedCSI.getCurve() instanceof ControlPointCurve && (getCurveValueProvider() == null || !getCurveValueProvider().providesInitalCurve(getTool(), getWorldCoordinateValue(event.getPoint())) || getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateValue(event.getPoint()), selectedCSI.getCurve()))) {
            if ((!(selectedCSI.getCurve() instanceof CurveSelectionCurve)) && getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())), selectedCSI.getCurve())) {
                ((ControlPointCurve) (selectedCSI.getCurve())).appendControlPoint(getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())));
            } else if (getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateValue(event.getPoint()), selectedCSI.getCurve())) {
                try {
                    if (selectedCSI.getCurve() instanceof CurveSelectionCurve) {
                        ControlPointCurve targetCurve = (ControlPointCurve) (((CurveSelectionCurve) selectedCSI.getCurve()).getSourceCurveSelectionInfo().getCurve());
                        double dist = targetCurve.getDistanceTo(getWorldCoordinateValue(event.getPoint()));
                        int segmentIndex = targetCurve.pickSegment(getWorldCoordinateValue(event.getPoint()), dist * 1.1);
                        Coordinate[] coordArr = targetCurve.getSampledCurve().getControlPointsForSegment(segmentIndex);
                        Coordinate middleCoord = new Coordinate((coordArr[0].getX() + coordArr[1].getX()) / 2, (coordArr[0].getY() + coordArr[1].getY()) / 2, (coordArr[0].getZ() + coordArr[1].getZ()) / 2);
                        ((ControlPointCurve) (selectedCSI.getCurve())).appendControlPoint(getWorldCoordinateCalculator().snapWorldCoordinateFace(middleCoord));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        if (selectedCSI != null && !selectedCSI.getCurve().isValid()) {
            int subSel = getCurveRenderer().getRenderPropertySubSelectionType(selectedCSI.getCurve());
            boolean bEdit = getCurveRenderer().getRenderPropertyEditable(selectedCSI.getCurve());
            getCurveRenderer().setSelection(null);
            getCurveRenderer().addCurve(selectedCSI.getCurve());
            getCurveRenderer().renderPropertyEditable(selectedCSI.getCurve(), bEdit);
            getCurveRenderer().renderPropertySubSelectionType(selectedCSI.getCurve(), subSel);
        }
        getCurveRenderer().setSelection(selectedCSI);
        if (getCurveValueProvider() != null && selectedCSI != null && selectedCSI.getCurve().isValid()) {
            getCurveValueProvider().curveAdded(selectedCSI.getCurve());
        }
        getVcellDrawable().repaint();
    } else if (getTool() == TOOL_SELECT) {
        CurveSelectionInfo invalidCSI = null;
        if (getCurveRenderer().getSelection() != null && !getCurveRenderer().getSelection().getCurve().isValid()) {
            invalidCSI = getCurveRenderer().getSelection();
        }
        // 
        lastSnappedWorldCoord = getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint()));
        CurveSelectionInfo csi = getCurveRenderer().pick(getWorldCoordinateValue(event.getPoint()));
        if (csi != null && getCurveRenderer().getRenderPropertySelectable(csi.getCurve())) {
            getCurveRenderer().setSelection(csi);
        } else {
            getCurveRenderer().selectNothing();
        }
        // 
        if (getCurveValueProvider() != null) {
            if (invalidCSI != null) {
                getCurveValueProvider().curveRemoved(invalidCSI.getCurve());
            } else {
                getCurveValueProvider().curveAdded(null);
            }
        }
        // 
        getVcellDrawable().repaint();
    }
// 
}
Also used : CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) Coordinate(org.vcell.util.Coordinate) PolyLine(cbit.vcell.geometry.PolyLine) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo) Spline(cbit.vcell.geometry.Spline) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 72 with Coordinate

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

the class CurveEditorTool method step.

/**
 * Insert the method's description here.
 * Creation date: (10/14/00 3:53:50 PM)
 */
private void step(KeyEvent event) {
    if (getCurveRenderer() == null || getCurveRenderer().getSelection() == null || !(getCurveRenderer().getSelection().getCurve() instanceof ControlPointCurve)) {
        return;
    }
    Coordinate wd = getCurveRenderer().getWorldDelta();
    double xDelta = Coordinate.convertAxisFromStandardXYZToNormal(wd, Coordinate.X_AXIS, getCurveRenderer().getNormalAxis());
    double yDelta = Coordinate.convertAxisFromStandardXYZToNormal(wd, Coordinate.Y_AXIS, getCurveRenderer().getNormalAxis());
    int multiplier = event.isShiftDown() ? 10 : 1;
    double dx = 0;
    double dy = 0;
    switch(event.getKeyCode()) {
        case KeyEvent.VK_UP:
            dy = -multiplier * yDelta;
            break;
        case KeyEvent.VK_DOWN:
            dy = multiplier * yDelta;
            break;
        case KeyEvent.VK_LEFT:
            dx = -multiplier * xDelta;
            break;
        case KeyEvent.VK_RIGHT:
            dx = multiplier * xDelta;
            break;
    }
    ControlPointCurve cpc = (ControlPointCurve) getCurveRenderer().getSelection().getCurve();
    move(dx, dy, getCurveRenderer().getSelection(), getCurveRenderer().getNormalAxis(), event.isControlDown());
}
Also used : Coordinate(org.vcell.util.Coordinate) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 73 with Coordinate

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

the class DataSetControllerImpl method findFunctionIndexes.

/**
 * Insert the method's description here.
 * Creation date: (10/13/00 9:13:52 AM)
 * @return cbit.vcell.simdata.SimDataBlock
 * @param user cbit.vcell.server.User
 * @param simResults cbit.vcell.simdata.SimResults
 * @param function cbit.vcell.math.Function
 * @param time double
 */
private FunctionIndexes[] findFunctionIndexes(VCDataIdentifier vcdID, AnnotatedFunction function, int[] dataIndexes, OutputContext outputContext) throws ExpressionException, DataAccessException, IOException, MathException {
    if (function.getFunctionType().equals(VariableType.POSTPROCESSING)) {
        FunctionIndexes[] fiArr = new FunctionIndexes[dataIndexes.length];
        Vector<DataSetIdentifier> dependencyList = identifyDataDependencies(function);
        SimulationData simData = (SimulationData) getVCData(vcdID);
        String[] varNames = new String[dependencyList.size()];
        String[] simFileVarNames = new String[dependencyList.size()];
        for (int i = 0; i < varNames.length; i++) {
            varNames[i] = dependencyList.get(i).getName();
            simFileVarNames[i] = dependencyList.get(i).getName();
        }
        CartesianMesh mesh = simData.getPostProcessingMesh(function.getName(), outputContext);
        int[][] varIndexes = new int[dataIndexes.length][varNames.length];
        for (int i = 0; i < dataIndexes.length; i += 1) {
            for (int j = 0; j < varNames.length; j++) {
                varIndexes[i][j] = dataIndexes[i];
            }
        }
        // VolumeIndexNearFar[][] outside_near_far_indexes = null;//new VolumeIndexNearFar[dataIndexes.length][/*varNames.length*/];
        for (int i = 0; i < dataIndexes.length; i += 1) {
            fiArr[i] = new FunctionIndexes(function, mesh.getCoordinateFromVolumeIndex(dataIndexes[i]), varNames, simFileVarNames, varIndexes[i], null, null);
        }
        return fiArr;
    }
    VariableType variableType = function.getFunctionType();
    Vector<DataSetIdentifier> dependencyList = identifyDataDependencies(function);
    int varIndex = TXYZ_OFFSET + dependencyList.size();
    // 
    // get Indexes and simFileNames
    // 
    Coordinate initCoord = new Coordinate(0, 0, 0);
    Coordinate[] coords = new Coordinate[dataIndexes.length];
    for (int i = 0; i < coords.length; i += 1) {
        coords[i] = initCoord;
    }
    String[] varNames = new String[varIndex - TXYZ_OFFSET];
    String[] simFileVarNames = new String[varNames.length];
    int[][] varIndexes = new int[dataIndexes.length][varNames.length];
    // New data needed for INSIDE-OUTSIDE interpolation
    VolumeIndexNearFar[][] inside_near_far_indexes = new VolumeIndexNearFar[dataIndexes.length][varNames.length];
    VolumeIndexNearFar[][] outside_near_far_indexes = new VolumeIndexNearFar[dataIndexes.length][varNames.length];
    CartesianMesh mesh = getMesh(vcdID);
    // 
    for (int i = 0; i < dataIndexes.length; i += 1) {
        coords[i] = mesh.getCoordinateFromVolumeIndex(dataIndexes[i]);
        if (variableType.equals(VariableType.VOLUME)) {
            // coord = mesh.getCoordinateFromVolumeIndex(dataIndex);
            coords[i] = mesh.getCoordinateFromVolumeIndex(dataIndexes[i]);
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
                if (dsi.getVariableType().equals(VariableType.VOLUME)) {
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName();
                    varIndexes[i][j] = dataIndexes[i];
                } else if (dsi.getVariableType().equals(VariableType.VOLUME_REGION)) {
                    int volumeIndex = mesh.getVolumeRegionIndex(dataIndexes[i]);
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName();
                    varIndexes[i][j] = volumeIndex;
                }
            }
        } else if (variableType.equals(VariableType.VOLUME_REGION)) {
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
                if (dsi.getVariableType().equals(VariableType.VOLUME_REGION)) {
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName();
                    varIndexes[i][j] = dataIndexes[i];
                }
            }
        } else if (variableType.equals(VariableType.MEMBRANE)) {
            // coord = mesh.getCoordinateFromMembraneIndex(dataIndex);
            coords[i] = mesh.getCoordinateFromMembraneIndex(dataIndexes[i]);
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
                if (dsi.getVariableType().equals(VariableType.VOLUME)) {
                    if (mesh.isChomboMesh()) {
                        // don't do any varname modifications here,
                        // because chombo needs this info to decide
                        // which data set to read, extrapolate values or solution.
                        // if varname doesn't have _INSIDE or _OUTSIDE
                        // add _INSIDE to varname to indicate it needs to read extrapolated values
                        String varName = dsi.getName();
                        if (!varName.endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX) && !varName.endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                            varName += InsideVariable.INSIDE_VARIABLE_SUFFIX;
                            // add this new varname to the list if it's not already there
                            getVCData(vcdID).getEntry(varName);
                        }
                        simFileVarNames[j] = varName;
                        varIndexes[i][j] = dataIndexes[i];
                    } else {
                        if (dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                            int volInsideIndex = mesh.getMembraneElements()[dataIndexes[i]].getInsideVolumeIndex();
                            varNames[j] = dsi.getName();
                            simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
                            varIndexes[i][j] = volInsideIndex;
                            inside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], true, false);
                        } else if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                            int volOutsideIndex = mesh.getMembraneElements()[dataIndexes[i]].getOutsideVolumeIndex();
                            varNames[j] = dsi.getName();
                            simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
                            varIndexes[i][j] = volOutsideIndex;
                            outside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], false, false);
                        } else {
                            varNames[j] = dsi.getName();
                            simFileVarNames[j] = dsi.getName();
                            if (isDomainInside(mesh, dsi.getDomain(), dataIndexes[i])) {
                                inside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dsi.getDomain(), dataIndexes[i], false);
                                varIndexes[i][j] = inside_near_far_indexes[i][j].volIndexNear;
                            } else {
                                outside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dsi.getDomain(), dataIndexes[i], false);
                                varIndexes[i][j] = outside_near_far_indexes[i][j].volIndexNear;
                            }
                        }
                    }
                } else if (dsi.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                    int insideVolumeIndex = mesh.getMembraneElements()[dataIndexes[i]].getInsideVolumeIndex();
                    int volRegionIndex = mesh.getVolumeRegionIndex(insideVolumeIndex);
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
                    varIndexes[i][j] = volRegionIndex;
                    inside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], true, true);
                } else if (dsi.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    int outsideVolumeIndex = mesh.getMembraneElements()[dataIndexes[i]].getOutsideVolumeIndex();
                    int volRegionIndex = mesh.getVolumeRegionIndex(outsideVolumeIndex);
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
                    varIndexes[i][j] = volRegionIndex;
                    outside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], false, true);
                } else if (dsi.getVariableType().equals(VariableType.MEMBRANE)) {
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName();
                    varIndexes[i][j] = dataIndexes[i];
                } else if (dsi.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
                    int memRegionIndex = mesh.getMembraneRegionIndex(dataIndexes[i]);
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName();
                    varIndexes[i][j] = memRegionIndex;
                }
            }
        } else if (variableType.equals(VariableType.MEMBRANE_REGION)) {
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
                if (dsi.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                    // 
                    // find "inside" volume element index for first membrane element in MembraneRegion 'i'.
                    // 
                    int insideVolumeIndex = -1;
                    for (int k = 0; k < mesh.getMembraneElements().length; k++) {
                        if (mesh.getMembraneRegionIndex(k) == dataIndexes[i]) {
                            insideVolumeIndex = mesh.getMembraneElements()[k].getInsideVolumeIndex();
                            break;
                        }
                    }
                    int volRegionIndex = mesh.getVolumeRegionIndex(insideVolumeIndex);
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
                    varIndexes[i][j] = volRegionIndex;
                    inside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], true, true);
                    ;
                } else if (dsi.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    // 
                    // find "outside" volume element index for first membrane element in MembraneRegion 'i'.
                    // 
                    int outsideVolumeIndex = -1;
                    for (int k = 0; k < mesh.getMembraneElements().length; k++) {
                        if (mesh.getMembraneRegionIndex(k) == dataIndexes[i]) {
                            outsideVolumeIndex = mesh.getMembraneElements()[k].getOutsideVolumeIndex();
                            break;
                        }
                    }
                    int volRegionIndex = mesh.getVolumeRegionIndex(outsideVolumeIndex);
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
                    varIndexes[i][j] = volRegionIndex;
                    outside_near_far_indexes[i][j] = interpolateFindNearFarIndex(mesh, dataIndexes[i], false, true);
                } else if (dsi.getVariableType().equals(VariableType.MEMBRANE)) {
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName();
                    varIndexes[i][j] = dataIndexes[i];
                } else if (dsi.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
                    int memRegionIndex = mesh.getMembraneRegionIndex(dataIndexes[i]);
                    varNames[j] = dsi.getName();
                    simFileVarNames[j] = dsi.getName();
                    varIndexes[i][j] = memRegionIndex;
                }
            }
        }
    }
    FunctionIndexes[] fiArr = new FunctionIndexes[dataIndexes.length];
    for (int i = 0; i < dataIndexes.length; i += 1) {
        fiArr[i] = new FunctionIndexes(function, coords[i], varNames, simFileVarNames, varIndexes[i], inside_near_far_indexes[i], outside_near_far_indexes[i]);
    }
    return fiArr;
// 
}
Also used : VariableType(cbit.vcell.math.VariableType) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Coordinate(org.vcell.util.Coordinate)

Example 74 with Coordinate

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

the class DataSetControllerImpl method getSpatialNeighborData.

/**
 * Insert the method's description here.
 * Creation date: (2/10/2007 1:37:32 PM)
 * @return double[]
 */
private double[] getSpatialNeighborData(CartesianMesh mesh, int volumeIndex, int numArgs, double time, Vector<SimDataHolder> dataSetList, double[] args) {
    int regionIndex = mesh.getVolumeRegionIndex(volumeIndex);
    double[] spatialNeighborData = args;
    int argCount = numArgs;
    for (int i = 0; i < 12; i += 1) {
        int x = (i == 0 ? -1 : 0) + (i == 1 ? 1 : 0) + (i == 6 ? -2 : 0) + (i == 7 ? 2 : 0);
        int y = (i == 2 ? -1 : 0) + (i == 3 ? 1 : 0) + (i == 8 ? -2 : 0) + (i == 9 ? 2 : 0);
        int z = (i == 4 ? -1 : 0) + (i == 5 ? 1 : 0) + (i == 10 ? -2 : 0) + (i == 11 ? 2 : 0);
        // for(int z=-1;z<=1;z+=2){
        // for(int y=-1;y<=1;y+=2){
        // for(int x=-1;x<=1;x+=2){
        spatialNeighborData[argCount] = time;
        argCount += 1;
        // 
        CoordinateIndex ci = mesh.getCoordinateIndexFromVolumeIndex(volumeIndex);
        ci.x += x;
        ci.y += y;
        ci.z += z;
        if (ci.x >= 0 && ci.x < mesh.getSizeX() && ci.y >= 0 && ci.y < mesh.getSizeY() && ci.z >= 0 && ci.z < mesh.getSizeZ()) {
            // Inside boundary of data
            Coordinate coord = mesh.getCoordinate(ci);
            int neighborVolumeIndex = mesh.getVolumeIndex(ci);
            int neighborRegionIndex = mesh.getVolumeRegionIndex(neighborVolumeIndex);
            if (neighborRegionIndex == regionIndex) {
                spatialNeighborData[argCount] = coord.getX();
                argCount += 1;
                spatialNeighborData[argCount] = coord.getY();
                argCount += 1;
                spatialNeighborData[argCount] = coord.getZ();
                argCount += 1;
                for (int j = 0; j < numArgs - TXYZ_OFFSET; j++) {
                    SimDataHolder simDataHolder = dataSetList.elementAt(j);
                    if (simDataHolder.getVariableType().equals(VariableType.VOLUME)) {
                        spatialNeighborData[argCount] = simDataHolder.getData()[neighborVolumeIndex];
                        argCount += 1;
                    } else {
                        throw new RuntimeException("only VOLUME variables allowed in grad functions");
                    }
                }
                continue;
            }
        // else{//Outside the current region, mark neighbor as undefined
        // for(int j=0;j<(numArgs-4);j+= 1){//four less because time and coordinate are inserted already
        // spatialNeighborData[argCount] = Double.NaN;
        // argCount+= 1;
        // }
        // }
        }
        // Outside boundary of data, mark neighbor as undefined
        for (int j = 0; j < (numArgs - 1); j += 1) {
            // one less because time is inserted already
            spatialNeighborData[argCount] = Double.NaN;
            argCount += 1;
        }
    // }
    // }
    // }
    // }
    }
    return spatialNeighborData;
}
Also used : Coordinate(org.vcell.util.Coordinate) CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 75 with Coordinate

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

the class DataSetControllerImpl method evaluateFunction.

/**
 * Insert the method's description here.
 * Creation date: (10/13/00 9:13:52 AM)
 * @return cbit.vcell.simdata.SimDataBlock
 * @param user cbit.vcell.server.User
 * @param simResults cbit.vcell.simdata.SimResults
 * @param function cbit.vcell.math.Function
 * @param time double
 */
private SimDataBlock evaluateFunction(OutputContext outputContext, final VCDataIdentifier vcdID, VCData simData, AnnotatedFunction function, double time) throws ExpressionException, DataAccessException, IOException, MathException {
    Expression exp = new Expression(function.getExpression());
    exp = SolverUtilities.substituteSizeAndNormalFunctions(exp, function.getFunctionType().getVariableDomain());
    exp.bindExpression(simData);
    exp = fieldFunctionSubstitution(outputContext, vcdID, exp);
    // 
    // get Dependent datasets
    // 
    // variables are indexed by a number, t=0, x=1, y=2, z=3, a(i) = 4+i where a's are other variables
    // these variables
    // 
    CartesianMesh mesh = null;
    if (function.getFunctionType().equals(VariableType.POSTPROCESSING)) {
        mesh = ((SimulationData) simData).getPostProcessingMesh(function.getName(), outputContext);
    }
    if (mesh == null) {
        mesh = getMesh(vcdID);
    }
    String[] dependentIDs = exp.getSymbols();
    Vector<SimDataHolder> dataSetList = new Vector<SimDataHolder>();
    Vector<DataSetIdentifier> dependencyList = new Vector<DataSetIdentifier>();
    int varIndex = TXYZ_OFFSET;
    int dataLength = 0;
    long lastModified = 0;
    VariableType variableType = function.getFunctionType();
    if (variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.POSTPROCESSING)) {
        dataLength = mesh.getNumVolumeElements();
    } else if (variableType.equals(VariableType.MEMBRANE)) {
        dataLength = mesh.getNumMembraneElements();
    } else if (variableType.equals(VariableType.VOLUME_REGION)) {
        dataLength = mesh.getNumVolumeRegions();
    } else if (variableType.equals(VariableType.MEMBRANE_REGION)) {
        dataLength = mesh.getNumMembraneRegions();
    }
    VariableType computedVariableType = null;
    int computedDataLength = 0;
    for (int i = 0; dependentIDs != null && i < dependentIDs.length; i++) {
        SymbolTableEntry ste = exp.getSymbolBinding(dependentIDs[i]);
        if (ste instanceof DataSetIdentifier) {
            DataSetIdentifier dsi = (DataSetIdentifier) ste;
            dependencyList.addElement(dsi);
            dsi.setIndex(varIndex++);
            if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX) || dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                String volVarName = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
                SimDataBlock simDataBlock = getSimDataBlock(outputContext, vcdID, volVarName, time);
                lastModified = simDataBlock.getPDEDataInfo().getTimeStamp();
                // 
                if (simDataBlock.getVariableType().equals(VariableType.VOLUME)) {
                    computedVariableType = VariableType.MEMBRANE;
                    computedDataLength = mesh.getMembraneElements().length;
                // 
                // if inside/outside volume element dependent, then can only be a membrane type
                // 
                } else if (simDataBlock.getVariableType().equals(VariableType.VOLUME_REGION) && variableType == null) {
                    computedVariableType = VariableType.MEMBRANE_REGION;
                    computedDataLength = mesh.getNumMembraneRegions();
                }
                dataSetList.addElement(simDataBlock);
            } else {
                SimDataBlock simDataBlock = getSimDataBlock(outputContext, vcdID, dsi.getName(), time);
                if (variableType == null || simDataBlock.getVariableType().isExpansionOf(variableType)) {
                    lastModified = simDataBlock.getPDEDataInfo().getTimeStamp();
                    computedDataLength = simDataBlock.getData().length;
                    computedVariableType = simDataBlock.getVariableType();
                }
                dataSetList.addElement(simDataBlock);
            }
        } else if (ste instanceof ReservedVariable) {
            ReservedVariable rv = (ReservedVariable) ste;
            if (rv.isTIME()) {
                rv.setIndex(0);
            } else if (rv.isX()) {
                rv.setIndex(1);
            } else if (rv.isY()) {
                rv.setIndex(2);
            } else if (rv.isZ()) {
                rv.setIndex(3);
            }
        } else if (ste instanceof FieldDataParameterVariable) {
            // Field Data
            ((FieldDataParameterVariable) ste).setIndex(varIndex++);
            final double[] steResampledFieldData = ((FieldDataParameterVariable) ste).getResampledFieldData();
            final VariableType newVariableType = (steResampledFieldData.length == mesh.getNumVolumeElements() ? VariableType.VOLUME : (steResampledFieldData.length == mesh.getNumMembraneElements() ? VariableType.MEMBRANE : null));
            if (newVariableType == null) {
                throw new DataAccessException("Couldn't determine VariableType for FieldData");
            }
            if (variableType != null && !variableType.equals(newVariableType)) {
                throw new DataAccessException("Incompatible VariableType for FieldData");
            }
            SimDataHolder newSimDataHolder = new SimDataHolder() {

                public double[] getData() {
                    return steResampledFieldData;
                }

                public VariableType getVariableType() {
                    return newVariableType;
                }
            };
            dataSetList.addElement(newSimDataHolder);
            dependencyList.add(new DataSetIdentifier(ste.getName(), newVariableType, ((FieldDataParameterVariable) ste).getDomain()));
            if (variableType == null) {
                computedVariableType = newVariableType;
                computedDataLength = newSimDataHolder.getData().length;
            }
        }
    }
    if (computedDataLength <= 0) {
        if (lg.isWarnEnabled())
            lg.warn("dependencies for function '" + function + "' not found, assuming datalength of volume");
        computedDataLength = mesh.getDataLength(VariableType.VOLUME);
        computedVariableType = VariableType.VOLUME;
    // try {
    // computedDataLength = mesh.getDataLength(VariableType.VOLUME);
    // computedVariableType = VariableType.VOLUME;
    // }catch (MathException e){
    // lg.error(e.getMessage(), e);
    // throw new RuntimeException("MathException, cannot determine domain for function '"+function+"'");
    // }catch (FileNotFoundException e){
    // lg.error(e.getMessage(), e);
    // throw new RuntimeException("Mesh not found, cannot determine domain for function '"+function+"'");
    // }
    }
    if (!variableType.equals(computedVariableType)) {
        System.err.println("function [" + function.getName() + "] variable type [" + variableType.getTypeName() + "] is not equal to computed variable type [" + computedVariableType.getTypeName() + "].");
    }
    if (dataLength == 0) {
        dataLength = computedDataLength;
        variableType = computedVariableType;
    }
    // 
    // Gradient Info for special processing
    // 
    boolean isGrad = hasGradient(exp);
    if (isGrad && !variableType.equals(VariableType.VOLUME)) {
        throw new DataAccessException("Gradient function is not implemented for datatype " + variableType.getTypeName());
    }
    double[] args = new double[varIndex + (isGrad ? 12 * varIndex : 0)];
    double[] data = new double[dataLength];
    // time
    args[0] = time;
    // x
    args[1] = 0.0;
    // y
    args[2] = 0.0;
    // z
    args[3] = 0.0;
    String dividedByZeroMsg = "";
    for (int i = 0; i < dataLength; i++) {
        // 
        if (variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.POSTPROCESSING)) {
            Coordinate coord = mesh.getCoordinateFromVolumeIndex(i);
            args[1] = coord.getX();
            args[2] = coord.getY();
            args[3] = coord.getZ();
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                SimDataHolder simDataHolder = dataSetList.elementAt(j);
                if (simDataHolder.getVariableType().equals(VariableType.VOLUME) || simDataHolder.getVariableType().equals(VariableType.POSTPROCESSING)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[i];
                } else if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION)) {
                    int volumeIndex = mesh.getVolumeRegionIndex(i);
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[volumeIndex];
                } else if (simDataHolder.getVariableType().equals(VariableType.POINT_VARIABLE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[0];
                }
            }
            if (isGrad) {
                getSpatialNeighborData(mesh, i, varIndex, time, dataSetList, args);
            }
        } else if (variableType.equals(VariableType.VOLUME_REGION)) {
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                SimDataHolder simDataHolder = dataSetList.elementAt(j);
                if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[i];
                } else if (simDataHolder.getVariableType().equals(VariableType.POINT_VARIABLE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[0];
                }
            }
        } else if (variableType.equals(VariableType.MEMBRANE)) {
            Coordinate coord = mesh.getCoordinateFromMembraneIndex(i);
            args[1] = coord.getX();
            args[2] = coord.getY();
            args[3] = coord.getZ();
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
                SimDataHolder simDataHolder = dataSetList.elementAt(j);
                if (simDataHolder.getVariableType().equals(VariableType.VOLUME)) {
                    if (mesh.isChomboMesh()) {
                        String varName = dsi.getName();
                        if (dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                            varName = varName.substring(0, varName.lastIndexOf(InsideVariable.INSIDE_VARIABLE_SUFFIX));
                        } else if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                            varName = varName.substring(0, varName.lastIndexOf(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX));
                        }
                        args[TXYZ_OFFSET + j] = getChomboExtrapolatedValues(vcdID, varName, time).getData()[i];
                    } else {
                        if (dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, true, false);
                        } else if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, false, false);
                        } else {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, dsi.getDomain(), i, simDataHolder, false);
                        }
                    }
                } else if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION)) {
                    if (dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                        args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, true, true);
                    } else if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                        args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, false, true);
                    } else {
                        args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, dsi.getDomain(), i, simDataHolder, true);
                    }
                } else if (simDataHolder.getVariableType().equals(VariableType.MEMBRANE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[i];
                } else if (simDataHolder.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
                    int memRegionIndex = mesh.getMembraneRegionIndex(i);
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[memRegionIndex];
                } else if (simDataHolder.getVariableType().equals(VariableType.POINT_VARIABLE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[0];
                }
            }
        } else if (variableType.equals(VariableType.MEMBRANE_REGION)) {
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
                SimDataHolder simDataHolder = dataSetList.elementAt(j);
                if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                    // 
                    for (int k = 0; k < mesh.getMembraneElements().length; k++) {
                        if (mesh.getMembraneRegionIndex(k) == i) {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, true, true);
                            break;
                        }
                    }
                } else if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    // 
                    for (int k = 0; k < mesh.getMembraneElements().length; k++) {
                        if (mesh.getMembraneRegionIndex(k) == i) {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, false, true);
                            break;
                        }
                    }
                } else if (simDataHolder.getVariableType().equals(VariableType.MEMBRANE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[i];
                } else if (simDataHolder.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
                    int memRegionIndex = i;
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[memRegionIndex];
                } else if (simDataHolder.getVariableType().equals(VariableType.POINT_VARIABLE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[0];
                }
            }
        }
        try {
            data[i] = exp.evaluateVector(args);
        // if(time ==0){
        // System.out.print("non-multi evalFunction ");
        // for (int m = 0; m < args.length; m++) {
        // System.out.print(args[m]);
        // }
        // System.out.println(" "+(args[args.length-2]/args[args.length-1]));
        // }
        } catch (DivideByZeroException e) {
            dividedByZeroMsg = e.getMessage();
            data[i] = Double.POSITIVE_INFINITY;
        }
    }
    if (dividedByZeroMsg.length() != 0) {
        System.out.println("DataSetControllerImpl.evaluateFunction(): DivideByZero " + dividedByZeroMsg);
    }
    PDEDataInfo pdeDataInfo = new PDEDataInfo(vcdID.getOwner(), vcdID.getID(), function.getName(), time, lastModified);
    return new SimDataBlock(pdeDataInfo, data, variableType);
}
Also used : VariableType(cbit.vcell.math.VariableType) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) Expression(cbit.vcell.parser.Expression) Coordinate(org.vcell.util.Coordinate) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException) FieldDataParameterVariable(cbit.vcell.field.FieldDataParameterVariable)

Aggregations

Coordinate (org.vcell.util.Coordinate)81 CoordinateIndex (org.vcell.util.CoordinateIndex)16 SampledCurve (cbit.vcell.geometry.SampledCurve)11 SinglePoint (cbit.vcell.geometry.SinglePoint)11 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)10 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)6 Expression (cbit.vcell.parser.Expression)6 CartesianMesh (cbit.vcell.solvers.CartesianMesh)6 Vector (java.util.Vector)6 Extent (org.vcell.util.Extent)6 VariableType (cbit.vcell.math.VariableType)5 ISize (org.vcell.util.ISize)5 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)4 Curve (cbit.vcell.geometry.Curve)4 SubVolume (cbit.vcell.geometry.SubVolume)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Origin (org.vcell.util.Origin)4 VCImageUncompressed (cbit.image.VCImageUncompressed)3 Line (cbit.vcell.geometry.Line)3