def nastran_to_abaqus(nastran_model, abqaqus_filename_out): """ Handles CTRIA3, CQUAD4 TODO: doesn't renumber TDOO: completely ignores properties TODO: assuming constant property """ log = nastran_model.log model = Abaqus(log=log, debug=True) node_sets = None element_sets = None solid_sections = None ctria3s = [] cquad4s = [] for eid, elem in iteritems(nastran_model.elements): if elem.type == 'CTRIA3': node_ids = elem.nodes ctria3 = [eid] + node_ids ctria3s.append(ctria3) elif elem.type == 'CQUAD4': node_ids = elem.nodes cquad4 = [eid] + node_ids cquad4s.append(cquad4) else: pass #log.warning('skipping:\n%s' % elem) element_types = { 'cpe3' : ctria3s, 'cpe4' : cquad4s, } name = 'model' icd_transform, icp_transform, xyz_cp, nid_cp_cd = nastran_model.get_displacement_index_xyz_cp_cd( fdtype='float64', sort_ids=True) nids = nid_cp_cd[:, 0] xyz_cid0 = nastran_model.transform_xyzcp_to_xyz_cid( xyz_cp, nids, icp_transform, cid=0, in_place=False) nodes = xyz_cid0 part = Part(name, nids, nodes, element_types, node_sets, element_sets, solid_sections, log) model.parts[name] = part model.write(abqaqus_filename_out) return model
def load_abaqus_geometry(self, abaqus_filename, name='main', plot=True): """loads abaqus input files into the gui""" skip_reading = self._remove_old_geometry(abaqus_filename) if skip_reading: return self.eid_maps[name] = {} self.nid_maps[name] = {} model = Abaqus(log=self.log, debug=False) self.model_type = 'abaqus' #self.model_type = model.model_type model.read_abaqus_inp(abaqus_filename) n_r2d2 = 0 n_cpe3 = 0 n_cpe4 = 0 n_cpe4r = 0 n_coh2d4 = 0 n_c3d10h = 0 n_cohax4 = 0 n_cax3 = 0 n_cax4r = 0 nnodes = 0 nelements = 0 all_nodes = [] for part_name, part in iteritems(model.parts): nids = part.nids - 1 nodes = part.nodes nnodes += nodes.shape[0] if part.r2d2 is not None: n_r2d2 += part.r2d2.shape[0] if part.cpe3 is not None: n_cpe3 += part.cpe3.shape[0] if part.cpe4 is not None: n_cpe4 += part.cpe4.shape[0] if part.cpe4r is not None: n_cpe4r += part.cpe4r.shape[0] if part.coh2d4 is not None: n_coh2d4 += part.coh2d4.shape[0] if part.cohax4 is not None: n_cohax4 += part.cohax4.shape[0] if part.cax3 is not None: n_cax3 += part.cax3.shape[0] if part.cax4r is not None: n_cax4r += part.cax4r.shape[0] if part.c3d10h is not None: n_c3d10h += part.c3d10h.shape[0] all_nodes.append(nodes) nelements += n_r2d2 + n_cpe3 + n_cpe4 + n_cpe4r + n_coh2d4 + n_c3d10h + n_cohax4 + n_cax3 + n_cax4r assert nelements > 0, nelements #nodes = model.nodes #elements = model.elements self.nNodes = nnodes self.nElements = nelements self.grid.Allocate(self.nElements, 1000) points = vtk.vtkPoints() points.SetNumberOfPoints(self.nNodes) self.nid_map = {} assert nodes is not None nnodes = nodes.shape[0] if len(all_nodes) == 1: nodes = all_nodes[0] else: nodes = np.vstack(all_nodes) mmax = np.amax(nodes, axis=0) mmin = np.amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.create_global_axes(dim_max) data_type = vtk.VTK_FLOAT points_array = numpy_to_vtk(num_array=nodes, deep=True, array_type=data_type) points.SetData(points_array) grid = self.grid nid_offset = -1 for part_name, part in iteritems(model.parts): nnodesi = part.nodes.shape[0] n_r2d2 = 0 n_cpe3 = 0 n_cpe4 = 0 n_cpe4r = 0 n_coh2d4 = 0 n_c3d10h = 0 n_cohax4 = 0 n_cax3 = 0 n_cax4r = 0 if part.r2d2 is not None: n_r2d2 += part.r2d2.shape[0] if part.cpe3 is not None: n_cpe3 += part.cpe3.shape[0] if part.cpe4 is not None: n_cpe4 += part.cpe4.shape[0] if part.cpe4r is not None: n_cpe4r += part.cpe4r.shape[0] if part.coh2d4 is not None: n_coh2d4 += part.coh2d4.shape[0] if part.cohax4 is not None: n_cohax4 += part.cohax4.shape[0] if part.cax3 is not None: n_cax3 += part.cax3.shape[0] if part.cax4r is not None: n_cax4r += part.cax4r.shape[0] # solids if part.c3d10h is not None: n_c3d10h += part.c3d10h.shape[0] if n_r2d2: eids = part.r2d2[:, 0] node_ids = part.r2d2[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): elem = vtkLine() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) if n_cpe3: eids = part.cpe3[:, 0] node_ids = part.cpe3[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): elem = vtkTriangle() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) elem.GetPointIds().SetId(2, node_ids[2]) grid.InsertNextCell(5, elem.GetPointIds()) if n_cpe4: eids = part.cpe4[:, 0] node_ids = part.cpe4[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): elem = vtkQuad() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) elem.GetPointIds().SetId(2, node_ids[2]) elem.GetPointIds().SetId(3, node_ids[3]) grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) if n_cpe4r: eids = part.cpe4r[:, 0] node_ids = part.cpe4r[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): elem = vtkQuad() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) elem.GetPointIds().SetId(2, node_ids[2]) elem.GetPointIds().SetId(3, node_ids[3]) grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) if n_coh2d4: eids = part.coh2d4[:, 0] node_ids = part.coh2d4[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): elem = vtkQuad() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) elem.GetPointIds().SetId(2, node_ids[2]) elem.GetPointIds().SetId(3, node_ids[3]) grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) if n_cohax4: eids = part.cohax4[:, 0] node_ids = part.cohax4[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): elem = vtkQuad() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) elem.GetPointIds().SetId(2, node_ids[2]) elem.GetPointIds().SetId(3, node_ids[3]) grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) if n_cax3: eids = part.cax3[:, 0] node_ids = part.cax3[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): elem = vtkTriangle() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) elem.GetPointIds().SetId(2, node_ids[2]) grid.InsertNextCell(5, elem.GetPointIds()) if n_cax4r: eids = part.cax4r[:, 0] node_ids = part.cax4r[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): elem = vtkQuad() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) elem.GetPointIds().SetId(2, node_ids[2]) elem.GetPointIds().SetId(3, node_ids[3]) grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) # solids if n_c3d10h: eids = part.c3d10h[:, 0] node_ids = part.c3d10h[:, 1:] + nid_offset for eid, node_ids in zip(eids, node_ids): #for eid, node_ids in part.c3d10h: elem = vtkTetra() elem.GetPointIds().SetId(0, node_ids[0]) elem.GetPointIds().SetId(1, node_ids[1]) elem.GetPointIds().SetId(2, node_ids[2]) elem.GetPointIds().SetId(3, node_ids[3]) grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) nid_offset += nnodesi grid.SetPoints(points) grid.Modified() if hasattr(grid, 'Update'): grid.Update() # loadCart3dResults - regions/loads self.scalarBar.VisibilityOn() self.scalarBar.Modified() note = '' self.iSubcaseNameMap = {1: ['Abaqus%s' % note, '']} #form = [] cases = {} ID = 1 form, cases, icase = self._fill_abaqus_case(cases, ID, nodes, nelements, model) #self._fill_cart3d_results(cases, form, icase, ID, model) self._finish_results_io2(form, cases)
def load_abaqus_geometry(self, abaqus_filename, name='main', plot=True): """loads abaqus input files into the gui""" model_name = name skip_reading = self.gui._remove_old_geometry(abaqus_filename) if skip_reading: return self.gui.eid_maps[name] = {} self.gui.nid_maps[name] = {} model = Abaqus(log=self.gui.log, debug=False) self.gui.model_type = 'abaqus' #self.model_type = model.model_type model.read_abaqus_inp(abaqus_filename) self.gui.nid_map = {} nnodes, all_nodes, nelements = get_nodes_nnodes_nelements(model) self.gui.log.info('nnodes=%s nelements=%s' % (nnodes, nelements)) assert nelements > 0, nelements #nodes = model.nodes #elements = model.elements self.gui.nnodes = nnodes self.gui.nelements = nelements grid = self.gui.grid grid.Allocate(self.gui.nelements, 1000) assert len(all_nodes) > 0 is not None, len(all_nodes) if len(all_nodes) == 1: nodes = all_nodes[0] else: nodes = np.vstack(all_nodes) mmax = np.amax(nodes, axis=0) mmin = np.amin(nodes, axis=0) dim_max = (mmax - mmin).max() self.gui.create_global_axes(dim_max) points = vtk.vtkPoints() points.SetNumberOfPoints(self.gui.nnodes) data_type = vtk.VTK_FLOAT points_array = numpy_to_vtk( num_array=nodes, deep=True, array_type=data_type ) points.SetData(points_array) nid_offset = -1 nids = [] for unused_part_name, part in model.parts.items(): self.gui.log.info('part_name = %r' % unused_part_name) nnodesi = part.nodes.shape[0] nidsi = part.nids nids.append(nidsi) add_lines(grid, nidsi, part.r2d2, nid_offset) add_tris(grid, nidsi, part.cps3, nid_offset) add_tris(grid, nidsi, part.cpe3, nid_offset) add_quads(grid, nidsi, part.cpe4, nid_offset) add_quads(grid, nidsi, part.cpe4r, nid_offset) add_quads(grid, nidsi, part.cps4, nid_offset) add_quads(grid, nidsi, part.cps4r, nid_offset) add_quads(grid, nidsi, part.coh2d4, nid_offset) add_quads(grid, nidsi, part.cohax4, nid_offset) add_tris(grid, nidsi, part.cax3, nid_offset) #add_quads(grid, nidsi, part.cax4, nid_offset) add_quads(grid, nidsi, part.cax4r, nid_offset) # solids add_tetras(grid, nidsi, part.c3d10h, nid_offset) add_hexas(grid, nidsi, part.c3d8r, nid_offset) nid_offset += nnodesi nids = np.hstack(nids) grid.SetPoints(points) grid.Modified() # loadCart3dResults - regions/loads self.gui.scalar_bar_actor.VisibilityOn() self.gui.scalar_bar_actor.Modified() note = '' self.gui.isubcase_name_map = {1: ['Abaqus%s' % note, '']} #form = [] cases = OrderedDict() ID = 1 form, cases, unused_icase, node_ids, element_ids = self._fill_abaqus_case( cases, ID, nids, nodes, nelements, model) #self._fill_cart3d_results(cases, form, icase, ID, model) self.gui.node_ids = node_ids self.gui.element_ids = element_ids self.gui._finish_results_io2(model_name, form, cases)
def nastran_to_abaqus_filename(bdf_filename: str, abaqus_inp_filename: str): nastran_model = read_bdf(bdf_filename) log = nastran_model.log model = Abaqus(log=None, debug=True) name = 'model' nids = [] nodes = [] for nid, node in nastran_model.nodes.items(): xyz = node.get_position() nids.append(nid) nodes.append(xyz) nodes = np.array(nodes, dtype='float32') node_sets = {} element_sets = {} ctria3s = [] cquad4s = [] ctetra4s = [] ctetra10s = [] chexa8s = [] chexa20s = [] element_types = { 'cpe3': ctria3s, # CTRIA3 'cpe4': cquad4s, 'c3d10h': ctetra10s, 'c3d4r': ctetra4s, 'c3d8r': chexa8s, 'c3d20r': chexa20s, } pid_to_name_map = {} element_sets_temp = {} shell_sections = [] for pid, prop in nastran_model.properties.items(): pid_to_name_map[pid] = f'{prop.type}_{pid}' # PSHELL_20 element_sets_temp[pid] = [] # 20 if prop.type == 'PSHELL': mid = prop.mid1 material_name = f'{prop.mid1_ref.type}_{mid}' thickness = prop.t shell_section = ShellSection(material_name, thickness, log) shell_sections.append(shell_section) elif prop.type == 'PSOLID': material_name = f'{prop.mid_ref.type}_{mid}' elset = None thickness = None solid_section = SolidSection(material_name, elset, thickness, log) solid_sections.append(solid_section) else: print(prop) #elif prop.type == 'PSHELL': for eid, elem in nastran_model.elements.items(): pid = elem.pid nidsi = elem.nodes if elem.type in ['CTRIA3']: ctria3s.append([eid] + nidsi) elif elem.type in ['CQUAD4']: cquad4s.append([eid] + nidsi) elif elem.type in ['CTETRA4']: ctetra4s.append([eid] + nidsi) elif elem.type in ['CTETRA10']: ctetra10s.append([eid] + nidsi) elif elem.type in ['CHEXA8']: chexa8s.append([eid] + nidsi) elif elem.type in ['CHEXA20']: chexa20s.append([eid] + nidsi) else: print(elem) element_sets_temp[pid].append(eid) for pid, pid_str in pid_to_name_map.items(): eids = element_sets_temp[pid] element_sets[pid_str] = np.array(eids, dtype='int32') del pid_to_name_map del element_sets_temp cloads = _process_constraints(nastran_model, node_sets) solid_sections = [] shell_sections = [] part = Part(name, nids, nodes, element_types, node_sets, element_sets, solid_sections, shell_sections, log=log) model.parts = { 'model': part, } for mid, mat in nastran_model.materials.items(): name = f'{mat.type}_mid{mid}' density = mat.rho if mat.rho else 0.0 sections = { 'elastic': 'cat', } material = Material(name, sections, density=density, is_elastic=True, ndepvars=None, ndelete=None) model.materials[name] = material name = 'static_step' boundaries = [] outputs = [] static_step = Step(name, boundaries, outputs, cloads=cloads, is_nlgeom=False) model.steps = [static_step] model.write(abaqus_inp_filename, is_2d=False)