def test_cut_shell_model_1(self): """ tests: - cut_edge_model_by_coord - cut_face_model_by_coord """ model, nodal_result = _cut_shell_model_quads() coord = CORD2R(1, rid=0, origin=[0.5, 0., 0.], zaxis=[0.5, 0., 1], xzplane=[1.5, 0., 0.], comment='') model.coords[1] = coord tol = 2. #------------------------------------------------------------------------- title = 'result' p1 = None p2 = None zaxis = None cut_and_plot_model(title, p1, p2, zaxis, model, coord, nodal_result, model.log, tol, plane_atol=1e-5, csv_filename=None, invert_yaxis=False, cut_type='edge', plot=IS_MATPLOTLIB, show=False) #========================================================================= out = cut_edge_model_by_coord(model, coord, tol, nodal_result, plane_atol=1e-5) unused_local_points_array, unused_global_points_array, result_array = out assert len(result_array) == 16, len(result_array) unused_geometry_array, result_array, unused_rods = cut_face_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5) result_array = np.array(result_array) assert result_array.shape == (1, 8, 7), result_array.shape os.remove('plane_edge.bdf') os.remove('plane_face.bdf')
def test_cut_shell_model_1(self): """ tests: - cut_edge_model_by_coord - cut_face_model_by_coord """ model, nodal_result = _cut_shell_model_quads() coord = CORD2R(1, rid=0, origin=[0.5, 0., 0.], zaxis=[0.5, 0., 1], xzplane=[1.5, 0., 0.], comment='') model.coords[1] = coord tol = 2. #------------------------------------------------------------------------- title = 'result' p1 = None p2 = None zaxis = None cut_and_plot_model(title, p1, p2, zaxis, model, coord, nodal_result, model.log, tol, plane_atol=1e-5, csv_filename=None, invert_yaxis=False, cut_type='edge', show=False) #========================================================================= local_points_array, global_points_array, result_array = cut_edge_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5) assert len(result_array) == 16, len(result_array) geometry_array, result_array = cut_face_model_by_coord(model, coord, tol, nodal_result, plane_atol=1e-5) assert result_array is None, len(result_array) # no quad support os.remove('plane_edge.bdf') os.remove('plane_face.bdf')
def test_cut_shell_model_2(self): """ tests: - cut_edge_model_by_coord - cut_face_model_by_coord """ tol = 2. coord = CORD2R(1, rid=0, origin=[0.5, 0., 0.], zaxis=[0.5, 0., 1], xzplane=[1.5, 0., 0.], comment='') model, nodal_result = _cut_shell_model_quads() #------------------------------------------------------------------------- # triangles split_to_trias(model) model.coords[1] = coord model.write_bdf('tris.bdf') #print('----------------------------') title = 'result' p1 = None p2 = None zaxis = None cut_and_plot_model(title, p1, p2, zaxis, model, coord, nodal_result, model.log, tol, plane_atol=1e-5, csv_filename=None, invert_yaxis=False, cut_type='edge', plot=IS_MATPLOTLIB, show=False) out = cut_edge_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5, csv_filename='cut_edge_2.csv') unused_local_points_array, unused_global_points_array, result_array = out assert len(result_array) == 20, len(result_array) unused_geometry_arrays, result_arrays, unused_rods = cut_face_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5, csv_filename='cut_face_2.csv') assert len(result_arrays[0]) == 8, len(result_arrays) os.remove('tris.bdf') os.remove('cut_edge_2.csv') os.remove('cut_face_2.csv') os.remove('plane_edge.bdf') os.remove('plane_face.bdf')
def test_cut_shell_model_2(self): """tests pierce_shell_model""" tol = 2. coord = CORD2R(1, rid=0, origin=[0.5, 0., 0.], zaxis=[0.5, 0., 1], xzplane=[1.5, 0., 0.], comment='') model, nodal_result = _cut_shell_model_quads() #------------------------------------------------------------------------- # triangles elements2 = {} neids = len(model.elements) for eid, elem in iteritems(model.elements): elem_a, elem_b = elem.split_to_ctria3(eid, eid + neids) elements2[elem_a.eid] = elem_a elements2[elem_b.eid] = elem_b model.elements = elements2 print(elements2) model.coords[1] = coord model.write_bdf('tris.bdf') print('----------------------------') local_points_array, global_points_array, result_array = cut_edge_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5, csv_filename='cut_edge_2.csv') assert len(result_array) == 20, len(result_array) geometry_arrays, result_arrays = cut_face_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5, csv_filename='cut_face_2.csv') assert len(result_arrays[0]) == 8, len(result_arrays)
def test_cut_shell_model_1(self): """tests pierce_shell_model""" model, nodal_result = _cut_shell_model_quads() coord = CORD2R(1, rid=0, origin=[0.5, 0., 0.], zaxis=[0.5, 0., 1], xzplane=[1.5, 0., 0.], comment='') model.coords[1] = coord tol = 2. #------------------------------------------------------------------------- local_points_array, global_points_array, result_array = cut_edge_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5) assert len(result_array) == 16, len(result_array) geometry_array, result_array = cut_face_model_by_coord(model, coord, tol, nodal_result, plane_atol=1e-5) assert result_array is None, len(result_array) # no quad support
def cut_and_plot_model(title, p1, p2, zaxis, model, coord, nodal_result, log, ytol, plane_atol=1e-5, csv_filename=None, invert_yaxis=False, cut_type='edge', show=True): """ Cuts a Nastran model with a cutting plane Parameters ---------- title : str the title for the plot p1 : ??? ??? p2 : ??? ??? zaxis : ??? ??? model : str / BDF str : the bdf filename model : a properly configurated BDF object coord : Coord the coordinate system to cut the model with nodal_result : (nelements, ) float np.ndarray the result to cut the model with log : logger a logging object ytol : float the tolerance to filter edges (using some large value) to prevent excessive computations plane_atol : float; default=1e-5 the tolerance for a line that's located on the y=0 local plane csv_filename : str; default=None None : don't write a csv str : write a csv """ assert cut_type.lower() in ['edge' ], 'cut_type=%r and must be edge' % cut_type cut_type = cut_type.lower() if cut_type == 'edge': # bar cutting version csv_filename_edge = None #if csv_filename: #csv_filename_edge = csv_filename + '_edge.csv' local_points_array, global_points_array, result_array = cut_edge_model_by_coord( model, coord, ytol, nodal_result, plane_atol=plane_atol, csv_filename=csv_filename_edge) if len(local_points_array) == 0: log.error('No elements were piereced. Check your cutting plane.') return plot_cutting_plane_edges(title, p1, p2, zaxis, local_points_array, global_points_array, result_array, csv_filename=csv_filename, invert_yaxis=invert_yaxis, show=show) elif cut_type == 'face': csv_filename_face = None if csv_filename: csv_filename_face = csv_filename + '_face.csv' geometry_arrays, results_arrays = cut_face_model_by_coord( model, coord, ytol, nodal_result, plane_atol=plane_atol, csv_filename=csv_filename_face) plot_cutting_plane_faces(title, p1, p2, zaxis, geometry_arrays, results_arrays, csv_filename=csv_filename, invert_yaxis=invert_yaxis, show=show) else: # pragma: no cover raise NotImplementedError('cut_type=%r' % cut_type)
def test_cut_shell_model(self): """tests pierce_shell_model""" pid = 10 mid1 = 100 model = BDF(log=log) # intersects (min) model.add_grid(1, [0., 0., 0.]) model.add_grid(2, [1., 0., 0.]) model.add_grid(3, [1., 1., 0.]) model.add_grid(4, [0., 1., 0.]) model.add_cquad4(1, pid, [1, 2, 3, 4]) # intersects (max) model.add_grid(5, [0., 0., 1.]) model.add_grid(6, [1., 0., 1.]) model.add_grid(7, [1., 1., 1.]) model.add_grid(8, [0., 1., 1.]) model.add_cquad4(2, pid, [5, 6, 7, 8]) # intersects (mid) model.add_grid(9, [0., 0., 0.5]) model.add_grid(10, [1., 0., 0.5]) model.add_grid(11, [1., 1., 0.5]) model.add_grid(12, [0., 1., 0.5]) model.add_cquad4(3, pid, [9, 10, 11, 12]) # doesn't intersect model.add_grid(13, [10., 0., 0.]) model.add_grid(14, [11., 0., 0.]) model.add_grid(15, [11., 1., 0.]) model.add_grid(16, [10., 1., 0.]) model.add_cquad4(4, pid, [13, 14, 15, 16]) model.add_pshell(pid, mid1=mid1, t=2.) E = 1.0 G = None nu = 0.3 model.add_mat1(mid1, E, G, nu, rho=1.0) model.validate() model.cross_reference() xyz_points = [ [0.4, 0.6, 0.], [-1., -1, 0.], ] tol = 2. coord = CORD2R(1, rid=0, origin=[0.5, 0., 0.], zaxis=[0.5, 0., 1], xzplane=[1.5, 0., 0.], comment='') nodal_result = np.linspace(0., 1., num=16) local_points_array, global_points_array, result_array = cut_edge_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5) assert len(result_array) == 16, len(result_array) local_points_array, global_points_array, result_array = cut_face_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5) assert len(result_array) == 0, len(result_array) # no quad support
def test_cut_shell_model_2(self): """ tests: - cut_edge_model_by_coord - cut_face_model_by_coord """ tol = 2. coord = CORD2R(1, rid=0, origin=[0.5, 0., 0.], zaxis=[0.5, 0., 1], xzplane=[1.5, 0., 0.], comment='') model, nodal_result = _cut_shell_model_quads() #------------------------------------------------------------------------- # triangles elements2 = {} neids = len(model.elements) for eid, elem in model.elements.items(): elem_a, elem_b = elem.split_to_ctria3(eid, eid + neids) elements2[elem_a.eid] = elem_a elements2[elem_b.eid] = elem_b model.elements = elements2 model.coords[1] = coord model.write_bdf('tris.bdf') #print('----------------------------') title = 'result' p1 = None p2 = None zaxis = None cut_and_plot_model(title, p1, p2, zaxis, model, coord, nodal_result, model.log, tol, plane_atol=1e-5, csv_filename=None, invert_yaxis=False, cut_type='edge', show=False) local_points_array, global_points_array, result_array = cut_edge_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5, csv_filename='cut_edge_2.csv') assert len(result_array) == 20, len(result_array) geometry_arrays, result_arrays = cut_face_model_by_coord( model, coord, tol, nodal_result, plane_atol=1e-5, csv_filename='cut_face_2.csv') assert len(result_arrays[0]) == 8, len(result_arrays) os.remove('tris.bdf') os.remove('cut_edge_2.csv') os.remove('cut_face_2.csv') os.remove('plane_edge.bdf') os.remove('plane_face.bdf')