def modal(geom_file, num_modes, path): # add shell elements from mesh --------------------------------------------- with open(geom_file, 'rb') as fh: geom_data = json.load(fh) mesh = Mesh.from_data(geom_data['mesh']) s = structure.Structure() s.add_nodes_elements_from_mesh(mesh, element_type='ShellElement') # add displacements -------------------------------------------------------- pts = geom_data['pts'] nkeys = [] for pt in pts: nkeys.append(s.check_node_exists(pt)) s.add_set(name='support_nodes', type='NODE', selection=nkeys) supppots = FixedDisplacement(name='supports', nodes='support_nodes') s.add_displacement(supppots) # add materials and sections ----------------------------------------------- E35 = 35 * 10**9 concrete = ElasticIsotropic(name='MAT_CONCRETE', E=E35, v=0.2, p=2400) s.add_material(concrete) section = ShellSection(name='SEC_CONCRETE', t=0.020) s.add_section(section) prop = ElementProperties(type='SHELL', material='MAT_CONCRETE', section='SEC_CONCRETE', elsets=['ELSET_ALL']) s.add_element_properties(prop) # add modal step ----------------------------------------------------------- step = ModalStep(name='modal_analysis', displacements=['supports'], num_modes=num_modes) s.add_step(step) fnm = path + 'modal.inp' ansys.inp_generate(s, filename=fnm) # temp = path + '_Temp/' s.analyse(path=path, name='modal.inp', temp=None, software='ansys') return s
def harmonic(geom_file, freq_range, freq_steps, damping): # add shell elements from mesh --------------------------------------------- with open(geom_file, 'rb') as fh: geom_data = json.load(fh) mesh = Mesh.from_data(geom_data['mesh']) s = structure.Structure() s.add_nodes_elements_from_mesh(mesh, element_type='ShellElement') # add displacements -------------------------------------------------------- pts = geom_data['pts'] nkeys = [] for pt in pts: nkeys.append(s.check_node_exists(pt)) s.add_set(name='support_nodes', type='NODE', selection=nkeys) supppots = FixedDisplacement(name='supports', nodes='support_nodes') s.add_displacement(supppots) # add materials and sections ----------------------------------------------- E35 = 35 * 10**9 concrete = ElasticIsotropic(name='MAT_CONCRETE', E=E35, v=0.2, p=2400) s.add_material(concrete) section = ShellSection(name='SEC_CONCRETE', t=0.020) s.add_section(section) prop = ElementProperties(type='SHELL', material='MAT_CONCRETE', section='SEC_CONCRETE', elsets=['ELSET_ALL']) s.add_element_properties(prop) # add loads ---------------------------------------------------------------- f_pts = geom_data['f_pts'] nodes = [s.check_node_exists(pt) for pt in f_pts] s.add_set(name='load_nodes', type='NODE', selection=nodes) load = PointLoad(name='hload', nodes='load_nodes', x=0, y=0, z=1, xx=0, yy=0, zz=0) s.add_load(load) # add modal step ----------------------------------------------------------- step = HarmonicStep(name='harmonic_analysis', displacements=['supports'], loads=['hload'], freq_range=freq_range, freq_steps=freq_steps, damping=damping) s.add_step(step) fnm = path + 'harmonic.inp' ansys.inp_generate(s, filename=fnm) # temp = path+'_Temp/' s.analyse(path=path, name='harmonic.inp', temp=None, software='ansys') return s
import traceback from json import encoder ipath = sys.argv[1] opath = sys.argv[2] with open(ipath, 'rb') as f: idict = json.load(f) try: profile = cProfile.Profile() profile.enable() # ---------------------------------------------------------------------- # profiler enabled # ---------------------------------------------------------------------- mesh = Mesh.from_data(idict['mesh']) main(mesh) data = {'mesh': mesh.to_data()} # ---------------------------------------------------------------------- # profiler disabled # ---------------------------------------------------------------------- profile.disable() stream = cStringIO.StringIO() stats = pstats.Stats(profile, stream=stream) stats.strip_dirs() stats.sort_stats(1) stats.print_stats(20) odict = {} odict['data'] = data odict['error'] = None odict['profile'] = stream.getvalue()
faces.append(face) mesh = Mesh.from_vertices_and_faces(vertices, faces) return mesh def ansys_remesh(mesh, output_path, filename, size=None): s = Structure() s.add_nodes_elements_from_mesh(mesh, 'ShellElement') s = areas_from_mesh(s, mesh) write_preprocess(output_path, filename) write_request_mesh_areas(s, output_path, filename, size=size, smart_size=None, div=None) ansys_launch_process(s, output_path, filename) mesh = mesh_from_ansys_results(output_path) return mesh if __name__ == '__main__': name = 'remesh.txt' path = '//Mac/Home/Desktop/ok/' mesh = Mesh.from_obj(compas.get_data('faces.obj')) mesh = Mesh.from_data(mesh.to_data()) mesh = ansys_remesh(mesh, path, name, 0.5) mesh.plot()
s.add_step(step) s.set_steps_order(['harmonic_analysis']) # analysis ----------------------------------------------------------------- s.path = path s.name = name fields = ['all'] s.write_input_file('ansys', fields=fields) s.analyse(software='ansys', cpus=4) s.extract_data(software='ansys', fields=fields, steps='last') return s if __name__ == '__main__': import compas_fea with open(compas_fea.get('flat20x20.json'), 'r') as fp: data = json.load(fp) mesh = Mesh.from_data(data['mesh']) pts = data['pts'] freq_list = [50, 51, 52, 55] thick = 0.02 damping = 0.003 path = compas_fea.TEMP name = 'harmonic_pressure' harmonic_pressure(mesh, pts, freq_list, path, name, damping=damping)