def test_p1_p2_zaxis_to_cord2r_cord2r(self): p1 = np.array([1., 1., 1.]) p2 = np.array([2., 1., 1.5]) # xzplane zaxis = np.array([1., 1., 2.]) model = BDF(debug=False) model.cross_reference() xyz1, xyz2, z_global, i, k, origin, zaxis2, xzplane = _p1_p2_zaxis_to_cord2r( model, p1, p2, zaxis, method='CORD2R', cid_p1=0, cid_p2=0, cid_zaxis=0) assert np.array_equal(xyz1, p1), xyz1 assert np.array_equal(xyz2, p2), xyz2 assert np.array_equal(z_global, zaxis), z_global assert np.array_equal(i, [1., 0., 0.]), i assert np.array_equal(k, [0., 0., 1.]), k assert np.array_equal(origin, [1., 1., 1.]), origin assert np.array_equal(zaxis2, [1., 1., 2.]), zaxis2 assert np.array_equal(xzplane, [2., 1., 1.5]), xzplane
def test_cutting_plane_bwb(self): model = BDF(debug=False) model.cross_reference() p1 = np.array([1388.9, 1262.0, 86.3471]) p2 = p1 + np.array([1., 0., 0.]) # xz-plane zaxis = np.array([0., 0., 1.]) xyz1, xyz2, z_global, i, k, origin, zaxis2, xzplane = _p1_p2_zaxis_to_cord2r( model, p1, p2, zaxis, method='Z-Axis Projection', cid_p1=0, cid_p2=0, cid_zaxis=0) assert np.array_equal(xyz1, p1), xyz1 assert np.array_equal(xyz2, p2), xyz2 assert np.array_equal(z_global, zaxis), z_global assert np.array_equal(i, [1., 0., 0.]), i assert np.array_equal(k, [0., 0., 1.]), k assert np.array_equal(origin, p1), origin assert np.array_equal(zaxis2, p1+zaxis), zaxis2 assert np.array_equal(xzplane, p2), xzplane
def plot_shear_moment_torque(self, model_name, gpforce, p1, p2, p3, zaxis, method='Z-Axis Projection', cid_p1=0, cid_p2=0, cid_p3=0, cid_zaxis=0, nplanes=20, plane_color=None, plane_opacity=0.5, csv_filename=None, show=True): """Creates a shear moment torque plot for the active plot result""" log = self.gui.log if plane_color is None: plane_color = PURPLE_FLOAT assert len(plane_color) == 3, plane_color model = self.gui.models[model_name] out = model.get_displacement_index_xyz_cp_cd() icd_transform, icp_transform, xyz_cp, nid_cp_cd = out nids = nid_cp_cd[:, 0] nid_cd = nid_cp_cd[:, [0, 2]] xyz_cid0 = model.transform_xyzcp_to_xyz_cid(xyz_cp, nids, icp_transform, cid=0) #xyz_min, xyz_max = model.xyz_limits xyz_min = xyz_cid0.min(axis=0) xyz_max = xyz_cid0.max(axis=0) assert len(xyz_min) == 3, xyz_min dxyz = np.abs(xyz_max - xyz_min) dim_max = dxyz.max() izero = np.where(dxyz == 0) dxyz[izero] = dim_max xyz1, xyz2, unused_z_global, i, k, origin, zaxis, xzplane = _p1_p2_zaxis_to_cord2r( model, p1, p2, zaxis, cid_p1=cid_p1, cid_p2=cid_p2, cid_zaxis=cid_zaxis, method=method) xyz3 = model.coords[cid_p3].transform_node_to_global(p3) dx = xyz3[0] - xyz1[0] stations = np.linspace(0., dx, num=nplanes, endpoint=True) x = stations try: # i/j/k vector is nan coord = CORD2R(1, rid=0, origin=origin, zaxis=zaxis, xzplane=xzplane, comment='') except: log.error( 'The coordinate system is invalid; check your cutting plane.') return None, None origin = coord.origin beta = coord.beta().T cid = '' self.gui.create_coordinate_system(cid, dim_max, label='%s' % cid, origin=origin, matrix_3x3=beta, coord_type='xyz') plane_actor = self.gui._create_plane_actor_from_points( xyz1, xyz2, i, k, dim_max, actor_name='smt_plane') props = self.gui.geometry_properties['smt_plane'] props.set_color(plane_color) props.opacity = plane_opacity prop = plane_actor.GetProperty() prop.SetColor(*plane_color) prop.SetOpacity(plane_opacity) # 0=transparent, 1=solid plane_actor.VisibilityOn() if 0: point_actor = self.gui.create_point_actor_from_points( [xyz1, xyz3], point_size=8, actor_name='smt_points') prop = point_actor.GetProperty() prop.SetColor(*plane_color) prop.SetOpacity(plane_opacity) # 0=transparent, 1=solid point_actor.VisibilityOn() self.gui.rend.Render() self.gui.Render() eids, element_centroids_cid0 = get_element_centriods(model) force_sum, moment_sum = gpforce.shear_moment_diagram( xyz_cid0, eids, nids, icd_transform, element_centroids_cid0, model.coords, nid_cd, stations, coord, idir=0, itime=0, debug=False, logger=log) plot_smt(x, force_sum, moment_sum, show=show) return force_sum, moment_sum
def make_cutting_plane(self, model_name, p1, p2, zaxis, method='Z-Axis Projection', cid_p1=0, cid_p2=0, cid_zaxis=0, ytol=1., plane_atol=1e-5, plane_color=None, plane_opacity=0.5, csv_filename=None, show=True): """Creates a cutting plane of the aero_model for the active plot result""" if plane_color is None: plane_color = PURPLE_FLOAT assert len(plane_color) == 3, plane_color log = self.gui.log model = self.gui.models[model_name] class_name = model.__class__.__name__ if class_name in ['BDF', 'OP2Geom']: out = model.get_displacement_index_xyz_cp_cd() unused_icd_transform, icp_transform, xyz_cp, nid_cp_cd = out nids = nid_cp_cd[:, 0] nid_cd = nid_cp_cd[:, [0, 2]] xyz_cid0 = model.transform_xyzcp_to_xyz_cid(xyz_cp, nids, icp_transform, cid=0) else: log.error('%r is not supported' % class_name) return #xyz_min, xyz_max = model.xyz_limits xyz_min = xyz_cid0.min(axis=0) xyz_max = xyz_cid0.max(axis=0) assert len(xyz_min) == 3, xyz_min dxyz = np.abs(xyz_max - xyz_min) dim_max = dxyz.max() izero = np.where(dxyz == 0) dxyz[izero] = dim_max xyz1, xyz2, unused_z_global, i, k, origin, zaxis, xzplane = _p1_p2_zaxis_to_cord2r( model, p1, p2, zaxis, cid_p1=cid_p1, cid_p2=cid_p2, cid_zaxis=cid_zaxis, method=method) plane_actor = self.gui._create_plane_actor_from_points( xyz1, xyz2, i, k, dim_max, actor_name='plane') prop = plane_actor.GetProperty() prop.SetColor(*plane_color) prop.SetOpacity(plane_opacity) # 0=transparent, 1=solid self.gui.rend.Render() try: # i/j/k vector is nan coord = CORD2R(1, rid=0, origin=origin, zaxis=zaxis, xzplane=xzplane, comment='') except: log.error( 'The coordinate system is invalid; check your cutting plane.') return #print(coord) origin = coord.origin beta = coord.beta().T cid = '' self.gui.create_coordinate_system(cid, dim_max, label='%s' % cid, origin=origin, matrix_3x3=beta, coord_type='xyz') nnodes = xyz_cid0.shape[0] #nodal_result = np.linspace(0., 1., num=nnodes) #case = self.result_cases[self.icase_aero] #res_scalars, location = model.aero_raw_plot_result() (obj, (i, name)) = self.gui.result_cases[self.gui.icase_fringe] res_scalars = obj.get_scalar(i, name) location = obj.get_location(i, name) if res_scalars is None: if plane_actor is not None: plane_actor.VisibilityOn() #print(self.model_frame.plane_actor) #print(dir(self.model_frame.plane_actor)) #plane_actor.VisibilityOff() log.error('No result is selected.') return if hasattr(obj, 'titles'): title = obj.titles[0] elif hasattr(obj, 'title'): title = obj.title else: raise NotImplementedError(obj) plane_actor.VisibilityOn() if location == 'centroid': if hasattr(model, 'map_centroidal_result'): nodal_result = model.map_centroidal_result(res_scalars) else: log.error('Centroidal results are not supported.') return #np.savetxt('Cp_centroid.csv', res_scalars, header='# Cp') #np.savetxt('Cp_nodal.csv', nodal_result, header='# Cp') else: nodal_result = res_scalars assert len(nodal_result) == nnodes invert_yaxis = False if title in ['Cp']: invert_yaxis = True cut_and_plot_model(title, p1, p2, zaxis, model, coord, nodal_result, log, ytol, plane_atol=plane_atol, csv_filename=csv_filename, invert_yaxis=invert_yaxis, cut_type='edge', show=show)