/** * Sets a thermal boundary condition for an edge of the polygon. * * @param edgeId The ID of the edge that will have the new BoundaryCondition. * @param condition The new BoundaryCondition. */ public void setThermalBoundaryCondition(int edgeId, BoundaryCondition condition) { // First, check that the edgeId is valid by performing a map lookup. EdgeProperties properties = edgeProperties.get(edgeId); if (condition != null && properties != null) { // If the edgeId is valid, try to set the new condition. If the new // condition is set, we need to register with the new condition and // notify listeners of the change. BoundaryCondition oldCondition = properties.getThermalBoundaryCondition(); if (properties.setThermalBoundaryCondition(condition)) { // Unregister from the old condition and register with the new. oldCondition.unregister(this); condition.register(this); // Notify listeners of the change. notifyListeners(); } } return; }
/** * Sets a passive scalar boundary condition for an edge of the polygon. * * @param edgeId The ID of the edge that will have the new BoundaryCondition. * @param otherId The ID or index of the set of passive scalar boundary conditions. * @param condition The new BoundaryCondition. */ public void setOtherBoundaryCondition(int edgeId, int otherId, BoundaryCondition condition) { // First, check that the edgeId is valid by performing a map lookup. EdgeProperties properties = edgeProperties.get(edgeId); if (condition != null && properties != null) { // If the edgeId is valid, try to set the new condition. If the new // condition is set, we need to register with the new condition and // notify listeners of the change. BoundaryCondition oldCondition = properties.getOtherBoundaryCondition(otherId); if (properties.setOtherBoundaryCondition(otherId, condition)) { // Unregister from the old condition and register with the new. // We need a null check because the scalar index ID may be new. if (oldCondition != null) { oldCondition.unregister(this); } condition.register(this); // Notify listeners of the change. notifyListeners(); } } return; }
/** * This operation copies the contents of a Polygon into the current object using a deep copy. * * @param polygon * <p>The Object from which the values should be copied. */ public void copy(Polygon polygon) { // Check the parameters. if (polygon == null) { return; } // Copy the super's data. super.copy(polygon); // Deep copy the vertices. vertices.clear(); for (Vertex vertex : polygon.getVertices()) { vertices.add((Vertex) vertex.clone()); } // Deep copy the edges. edges.clear(); ArrayList<Edge> otherEdges = polygon.getEdges(); int size = otherEdges.size(); for (int i = 0; i < size; i++) { // Clone the edge. This deep copies the other edge's vertices, so we // must hook the clone up to our vertex instances. Edge clone = (Edge) otherEdges.get(i).clone(); // Add the clone to the list of edges. edges.add(clone); // Get the new start and end vertices for this edge. Vertex start = vertices.get(i); Vertex end = vertices.get((i + 1) % size); // Register the clone with the start and end. start.register(clone); end.register(clone); // Send the start and end vertices to the clone. clone.update(start); clone.update(end); } /* ---- Deep copy the edge properties. ---- */ // Unregister from any of the current boundary conditions. for (Entry<Integer, EdgeProperties> entry : edgeProperties.entrySet()) { EdgeProperties properties = entry.getValue(); // Unregister from the fluid and thermal boundary conditions. properties.getFluidBoundaryCondition().unregister(this); properties.getThermalBoundaryCondition().unregister(this); // Unregister from all passive scalar boundary conditions. for (BoundaryCondition condition : properties.getOtherBoundaryConditions()) { condition.unregister(this); } } // Clone all of the edge properties from the other polygon and register // with their boundary conditions. for (Entry<Integer, EdgeProperties> entry : polygon.edgeProperties.entrySet()) { // Clone and add the edge's properties. EdgeProperties properties = (EdgeProperties) entry.getValue().clone(); edgeProperties.put(entry.getKey(), properties); // Unregister from the fluid and thermal boundary conditions. properties.getFluidBoundaryCondition().register(this); properties.getThermalBoundaryCondition().register(this); // Unregister from all passive scalar boundary conditions. for (BoundaryCondition condition : properties.getOtherBoundaryConditions()) { condition.register(this); } } /* ---------------------------------------- */ // Copy the PolygonProperties polygonProperties = (PolygonProperties) polygon.getPolygonProperties().clone(); return; }