def show_image_plane(self, ele_coord=0): """ Args: ele_coord: (Default value = 0) Returns: """ from fem.mesh import fem_mesh import numpy as np import matplotlib.pyplot as plt # -1 on next to move to 0 start indexing planeNodeIDs = fem_mesh.extractPlane(self.snic, self.axes, (0, ele_coord)) image_plane_loads = np.zeros(planeNodeIDs.shape) for m, a in enumerate(planeNodeIDs): for n, nid in enumerate(a): b = np.where(self.pt_loads['NID'] == nid) try: image_plane_loads[m][n] = self.pt_loads['Magnitude'][b[0]] except: pass plt.imshow(np.flipud(image_plane_loads.transpose())) plt.show()
def constrain_sym_pml_nodes(bcdict, snic, axes, pml_elems, edge_constraints): """make sure that all "side" nodes for the PML elements are fully constrained, instead of being assigned the symmetry constraints THIS FUNCTION IS NOT NEEDED!! :param bcdict: :param snic: :param axes: :param pml_elems: :param edge_constraints: :return: bcdict """ from fem.mesh.fem_mesh import extractPlane from numpy import ndenumerate # look for x symmetry face for axis in range(0, 2): if edge_constraints[0][axis][0]: axis_limit = axes[axis].min() elif edge_constraints[0][axis][1]: axis_limit = axes[axis].max() if axis_limit is not None: planeNodeIDs = extractPlane(snic, axes, (axis, axis_limit)) pml_node_ids_zmin = planeNodeIDs[:, 0:(pml_elems[2][0] + 1)] pml_node_ids_zmax = planeNodeIDs[:, -(pml_elems[2][1] + 1):] for i, id in ndenumerate(pml_node_ids_zmin): bcdict[id] = "%s" % '1,1,1,1,1,1' for i, id in ndenumerate(pml_node_ids_zmax): bcdict[id] = "%s" % '1,1,1,1,1,1' axis_limit = None return bcdict
def assign_node_constraints(snic, axes, face_constraints): """assign node constraints to prescribed node planes Nodes shared on multiple faces have are assigned with the following order of precedence: z, y, x Args: snic: sorted node IDs and coordinates from nodes.dyn axes: mesh axes [x, y, z] face_constraints: list of DOF strings ordered by ((xmin, max), (ymin, ...) (e.g., (('1,1,1,1,1,1' , '0,1,0,0,1,0'),...) Returns: bcdict - dictionary of node BC to be written to bc.dyn """ from fem.mesh.fem_mesh import extractPlane from numpy import ndenumerate bcdict = {} for axis in range(0, 3): for axlim in range(0, 2): if axlim == 0: axis_limit = axes[axis].min() else: axis_limit = axes[axis].max() planeNodeIDs = extractPlane(snic, axes, (axis, axis_limit)) for i, id in ndenumerate(planeNodeIDs): bcdict[id] = face_constraints[axis][axlim] return bcdict
def extract_top_plane_nodes(nodefile, top_face): """ Args: nodefile: param top_face: top_face: Returns: planeNodeIDs """ import numpy as np from fem.mesh import fem_mesh top_face = np.array(top_face) nodeIDcoords = fem_mesh.load_nodeIDs_coords(nodefile) [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords) # extract spatially-sorted node IDs on a the top z plane axis = int(np.floor(np.divide(top_face.nonzero(), 2))) if np.mod(top_face.nonzero(), 2) == 1: plane = (axis, axes[axis].max()) else: plane = (axis, axes[axis].min()) planeNodeIDs = fem_mesh.extractPlane(snic, axes, plane) return planeNodeIDs
def assign_edge_sym_constraints(bcdict, snic, axes, edge_constraints): """modify/create node BCs for quarter-symmetry edge Args: bcdict: dict of nodal BCs snic: sorted node IDs and coordinates axes: spatial axis vectors edge_constraints: list with vector indicating edge & constraint (e.g., to specify the edge shared by the xmax and ymin faces to allow just z translation: (((0,1),(1,0),(0,0)),'1,1,0,1,1,1') Returns: bcdict (updated from face assignment) """ from fem.mesh.fem_mesh import extractPlane # look for edge shared with an x face axis = 0 if edge_constraints[0][axis][0]: axis_limit = axes[axis].min() elif edge_constraints[0][axis][1]: axis_limit = axes[axis].max() else: logger.warning('Symmetry edge not shared by an x-face specified;' 'no edge BCs defined') return 1 planeNodeIDs = extractPlane(snic, axes, (axis, axis_limit)) # restrict nodes to those on specified edge ortho_axis = 1 if edge_constraints[0][ortho_axis][0]: edge_nodes = planeNodeIDs[0, :] elif edge_constraints[0][ortho_axis][1]: edge_nodes = planeNodeIDs[-1, :] else: logger.warning( 'Orthogonal plane to x-face is not a y-face; no edge BCs defined') return 1 # do not assign BCs to nodes associated with zmin/zmax faces edge_nodes = edge_nodes[1:-1] for i in edge_nodes: bcdict[i] = f"{edge_constraints[1]}" return bcdict
def apply_nonreflect(face_constraints, edge_constraints, nodefile="nodes.dyn", bcfile="bc.dyn", segfile="nonreflect_segs.dyn"): """driver function to generate non-reflecting boundaries Args: face_constraints (str): vector of face constraints, ordered xmin to zmax edge_constraints (str): vector of edge constraints, ordered xmin to zmax nodefile (str): default - 'nodes.dyn' bcfile (str): default - 'bc.dyn' segfile (str): default - 'nonreflect_segs.dyn' Returns: 0 on success """ import fem.mesh.fem_mesh as fem_mesh nodeIDcoords = fem_mesh.load_nodeIDs_coords(nodefile) [snic, axes] = fem_mesh.SortNodeIDs(nodeIDcoords) segID = 1 seg_names = [['XMIN', 'XMAX'], ['YMIN', 'YMAX'], ['ZMIN', 'ZMAX']] SEGBCFILE = open(segfile, 'w') for a in range(0, 3): for m in range(0, 2): if face_constraints[a][m] == '1,1,1,1,1,1': if m == 0: axis_limit = axes[a][0] else: axis_limit = axes[a][-1] planeNodeIDs = fem_mesh.extractPlane(snic, axes, (a, axis_limit)) segID = writeSeg(SEGBCFILE, seg_names[a][m], segID, planeNodeIDs) write_nonreflecting(SEGBCFILE, segID) SEGBCFILE.close() bcdict = assign_node_constraints(snic, axes, face_constraints) bcdict = assign_edge_sym_constraints(bcdict, snic, axes, edge_constraints) write_bc(bcdict, bcfile) return 0
def show_image_plane(self, ele_coord=0): """ Args: ele_coord: (Default value = 0) Returns: """ from fem.mesh import fem_mesh import numpy as np import matplotlib.pyplot as plt # -1 on next to move to 0 start indexing planeNodeIDs = fem_mesh.extractPlane(self.snic, self.axes, (0, ele_coord)) - 1 image_plane_intensity = np.take(self.intensity, planeNodeIDs) plt.imshow(np.flipud(image_plane_intensity.transpose())) plt.show()
def show_image_plane(self, ele_coord=0): """ Args: ele_coord: (Default value = 0) Returns: """ from fem.mesh import fem_mesh import numpy as np import matplotlib.pyplot as plt # -1 on next to move to 0 start indexing planeNodeIDs = fem_mesh.extractPlane(self.snic, self.axes, (0, ele_coord)) image_plane_loads = np.zeros(planeNodeIDs.shape) for m, a in enumerate(planeNodeIDs): for n, nid in enumerate(a): b = np.where(self.pt_loads['NID'] == nid) try: image_plane_loads[m][n] = self.pt_loads['Magnitude'][b[0]] # TODO: raise more explicit exceptions except: pass # TODO: add colorbar fig, axes = plt.subplots() axes.pcolormesh(self.axes[1] * 10, -self.axes[2] * 10, image_plane_loads.transpose()) axes.set_aspect('equal') axes.set_xlabel('Lateral (mm)') axes.set_ylabel('Axial (mm)') axes.invert_yaxis() axes.set_title('Intensity Distribution') plt.show()