def _write_boundary(ugrid, boundary_filename, tag_filename): """writes an OpenFOAM boundary file""" with open(boundary_filename, 'wb') as boundary_file: boundary_file.write('\n\n') #f.write('%i\n' % (nnodes)) boundary_file.write('(\n') uboundaries = unique(ugrid.pids) nboundaries = len(uboundaries) boundary_file.write('%i\n' % nboundaries) boundary_file.write('(\n') tagger = TagReader() tag_data = tagger.read_tag_filename(tag_filename) isort = argsort(ugrid.pids) ugrid.pids.sort() #print(isort) pids = ugrid.pids for iboundary in uboundaries: data = tag_data[iboundary] #name, is_visc, is_recon, is_rebuild, is_fixed, is_source, #is_trans, is_delete, bl_spacing, bl_thickness, nlayers = data name = data[0] i = where(iboundary == pids)[0] nfaces = i.max() - i.min() + 1 startface = i.min() if len(i) != nfaces: msg = 'The data is unsorted...len(i)=%s nfaces=%s' % (len(i), nfaces) raise RuntimeError(msg) boundary_file.write(' %s\n' % name) boundary_file.write(' {\n') boundary_file.write(' type patch;\n') #f.write(' type 1(wall);\n') # create a new group boundary_file.write(' nFaces %i;\n' % nfaces) boundary_file.write(' startFace %i;\n' % startface) boundary_file.write(' }\n') boundary_file.write(')\n') ugrid.isort = isort
def _fill_ugrid3d_case(self, base, cases, ID, nnodes, nelements, model): tag_filename = base + '.tags' mapbc_filename = base.split('.')[0] + '.mapbc' print('mapbc_filename = %r' % mapbc_filename) cases_new = [] has_tag_data = False has_mapbc_data = False results_form = [] mapbc_form = [] geometry_form = [ #('Region', 0, []), ('ElementID', 0, []), ('NodeID', 1, []), ('SurfaceID', 2, []), #('normSpacing', 3, []), #('BL_thick', 4, []), #('ReconFlag', 5, []), #('GridBC', 6, []), ] ntris = model.tris.shape[0] nquads = model.quads.shape[0] #nelements = ntris + nquads eids = arange(1, nelements + 1) nids = arange(1, nnodes + 1) #grid_bcs = element_props[:, 2] #npids = len(model.pids) pids = model.pids cases[(ID, 0, 'ElementID', 1, 'centroid', '%i', '')] = eids cases[(ID, 1, 'NodeID', 1, 'node', '%i', '')] = nids cases[(ID, 2, 'SurfaceID', 1, 'centroid', '%i', '')] = pids n = 3 if os.path.exists(tag_filename): #surf_ids = element_props[:, 0] #recon_flags = element_props[:, 1] #cases[(ID, 2, 'ReconFlag', 1, 'centroid', '%i')] = recon_flags #cases[(ID, 3, 'GridBC', 1, 'centroid', '%i')] = grid_bcs tagger = TagReader() data = tagger.read_tag_filename(tag_filename) int_data = ones((nelements, 8), dtype='int32') * -10. float_data = zeros((nelements, 2), dtype='float64') for key, datai in sorted(iteritems(data)): #self.log.info(datai) [name, is_visc, is_recon, is_rebuild, is_fixed, is_source, is_trans, is_delete, bl_spacing, bl_thickness, nlayers] = datai i = where(pids == key)[0] int_data[i, :] = [is_visc, is_recon, is_rebuild, is_fixed, is_source, is_trans, is_delete, nlayers] float_data[i, :] = [bl_spacing, bl_thickness] self.log.info('data[%i] = %s' % (key, name)) has_tag_data = True tag_form = [] tag_form.append( ('is_visc', n, []) ) tag_form.append( ('is_recon', n+1, []) ) tag_form.append( ('is_rebuild', n+2, []) ) tag_form.append( ('is_fixed', n+3, []) ) tag_form.append( ('is_source', n+4, []) ) tag_form.append( ('is_trans', n+5, []) ) tag_form.append( ('is_delete', n+6, []) ) tag_form.append( ('nlayers', n+7, []) ) tag_form.append( ('bl_spacing', n+8, []) ) tag_form.append( ('bl_thickness', n+9, []) ) cases[(ID, n, 'is_visc', 1, 'centroid', '%i', '')] = int_data[:, 0] cases[(ID, n + 1, 'is_recon', 1, 'centroid', '%i', '')] = int_data[:, 1] cases[(ID, n + 2, 'is_rebuild', 1, 'centroid', '%i', '')] = int_data[:, 2] cases[(ID, n + 3, 'is_fixed', 1, 'centroid', '%i', '')] = int_data[:, 3] cases[(ID, n + 4, 'is_source', 1, 'centroid', '%i', '')] = int_data[:, 4] cases[(ID, n + 5, 'is_trans', 1, 'centroid', '%i', '')] = int_data[:, 5] cases[(ID, n + 6, 'is_delete', 1, 'centroid', '%i', '')] = int_data[:, 6] cases[(ID, n + 7, 'nlayers', 1, 'centroid', '%i', '')] = int_data[:, 7] cases[(ID, n + 8, 'bl_spacing', 1, 'centroid', '%.3e', '')] = float_data[:, 0] cases[(ID, n + 9, 'bl_thickness', 1, 'centroid', '%.3e', '')] = float_data[:, 1] n += 10 else: self.log_info('tag_filename=%r could not be found' % tag_filename) if os.path.exists(mapbc_filename): has_mapbc_data = True mapbc = open(mapbc_filename, 'r') lines = mapbc.readlines() lines = [line.strip() for line in lines if not line.strip().startswith('#') and line.strip()] npatches = int(lines[0]) mapbcs = zeros(pids.shape, dtype='int32') for ipatch in range(npatches): line = lines[ipatch + 1] iline, bc_num, name = line.split() iline = int(iline) bc_num = int(bc_num) assert ipatch + 1 == iline, 'line=%r; ipatch=%s iline=%s' % (line, ipatch + 1, iline) islot = where(pids == ipatch + 1)[0] if len(islot) == 0: upids = unique(pids) msg = 'ipatch=%s not found in pids=%s' % (ipatch + 1, upids) raise RuntimeError(msg) mapbcs[islot] = bc_num print(line) mapbc_form.append(('Map BC', n, [])) cases[(ID, n, 'Map BC', 1, 'centroid', '%i', '')] = mapbcs else: self.log_info('mapbc_filename=%r could not be found' % mapbc_filename) #norm_spacing = model.node_props[:, 0] #bl_thickness = model.node_props[:, 1] #cases[(ID, 1, 'normSpacing', 1, 'node', '%.3e', '')] = norm_spacing #cases[(ID, 2, 'BL_thick', 1, 'node', '%.3e', '')] = bl_thickness form = [ ('Geometry', None, geometry_form), ] if has_tag_data: form.append(('Tag Data', None, tag_form),) if has_mapbc_data: form.append(('Map BC Data', None, mapbc_form),) results_form = [] if len(results_form): form.append(('Results', None, results_form)) print(form) return form, cases
def _fill_surf_case(self, surf_filename, cases, ID, nnodes, nelements, model): base, ext = os.path.splitext(surf_filename) assert ext == '.surf', surf_filename tag_filename = base + '.tags' cases_new = [] has_tag_data = False results_form = [] geometry_form = [ #('Region', 0, []), ('ElementID', 0, []), ('NodeID', 1, []), ('SurfaceID', 2, []), ('ReconFlag', 3, []), ('GridBC', 4, []), ('NormalX', 5, []), ('NormalY', 6, []), ('NormalZ', 7, []), ('normSpacing', 8, []), ('BL_thick', 9, []), ] nids = arange(1, nnodes + 1) norm_spacing = model.node_props[:, 0] bl_thickness = model.node_props[:, 1] ntris = model.tris.shape[0] nquads = model.quads.shape[0] #nelements = ntris + nquads eids = arange(1, nelements + 1) if ntris and nquads: element_props = vstack([model.tri_props, model.quad_props]) elif ntris: element_props = model.tri_props elif nquads: element_props = model.quad_props surf_ids = element_props[:, 0] recon_flags = element_props[:, 1] grid_bcs = element_props[:, 2] print(unique(grid_bcs)) normals = model.get_normals() cases[(ID, 0, 'ElementID', 1, 'centroid', '%i', '')] = eids cases[(ID, 1, 'NodeID', 1, 'node', '%i', '')] = nids cases[(ID, 2, 'SurfaceID', 1, 'centroid', '%i', '')] = surf_ids cases[(ID, 3, 'ReconFlag', 1, 'centroid', '%i', '')] = recon_flags cases[(ID, 4, 'GridBC', 1, 'centroid', '%i', '')] = grid_bcs cases[(ID, 5, 'NormalX', 1, 'centroid', '%.3f', '')] = normals[:, 0] cases[(ID, 6, 'NormalY', 1, 'centroid', '%.3f', '')] = normals[:, 1] cases[(ID, 7, 'NormalZ', 1, 'centroid', '%.3f', '')] = normals[:, 2] cases[(ID, 8, 'normSpacing', 1, 'node', '%.3e', '')] = norm_spacing cases[(ID, 9, 'BL_thick', 1, 'node', '%.3e', '')] = bl_thickness if os.path.exists(tag_filename): tagger = TagReader() data = tagger.read_tag_filename(tag_filename) int_data = ones((nelements, 8), dtype='int32') * -10. float_data = zeros((nelements, 2), dtype='float64') for key, datai in sorted(iteritems(data)): #self.log.info(datai) [name, is_visc, is_recon, is_rebuild, is_fixed, is_source, is_trans, is_delete, bl_spacing, bl_thickness, nlayers] = datai i = where(surf_ids == key)[0] int_data[i, :] = [is_visc, is_recon, is_rebuild, is_fixed, is_source, is_trans, is_delete, nlayers] float_data[i, :] = [bl_spacing, bl_thickness] self.log.info('data[%i] = %s' % (key, name)) has_tag_data = True tag_form = [] i = 10 tag_form.append( ('is_visc', i, []) ) tag_form.append( ('is_recon', i + 1, []) ) tag_form.append( ('is_rebuild', i + 2, []) ) tag_form.append( ('is_fixed', i + 3, []) ) tag_form.append( ('is_source', i + 4, []) ) tag_form.append( ('is_trans', i + 5, []) ) tag_form.append( ('is_delete', i + 6, []) ) tag_form.append( ('nlayers', i + 7, []) ) tag_form.append( ('bl_spacing', i + 8, []) ) tag_form.append( ('bl_thickness', i + 9, []) ) cases[(ID, i, 'is_visc', 1, 'centroid', '%i', '')] = int_data[:, 0] cases[(ID, i + 1, 'is_recon', 1, 'centroid', '%i', '')] = int_data[:, 1] cases[(ID, i + 2, 'is_rebuild', 1, 'centroid', '%i', '')] = int_data[:, 2] cases[(ID, i + 3, 'is_fixed', 1, 'centroid', '%i', '')] = int_data[:, 3] cases[(ID, i + 4, 'is_source', 1, 'centroid', '%i', '')] = int_data[:, 4] cases[(ID, i + 5, 'is_trans', 1, 'centroid', '%i', '')] = int_data[:, 5] cases[(ID, i + 6, 'is_delete', 1, 'centroid', '%i', '')] = int_data[:, 6] cases[(ID, i + 7, 'nlayers', 1, 'centroid', '%i', '')] = int_data[:, 7] cases[(ID, i + 8, 'bl_spacing', 1, 'centroid', '%.3e', '')] = float_data[:, 0] cases[(ID, i + 9, 'bl_thickness', 1, 'centroid', '%.3e', '')] = float_data[:, 1] form = [ ('Geometry', None, geometry_form), ] if has_tag_data: form.append(('Tag Data', None, tag_form),) results_form = [] if len(results_form): form.append(('Results', None, results_form)) return form, cases
def _fill_surf_case(self, surf_filename, cases, ID, nnodes, nelements, model): base, ext = os.path.splitext(surf_filename) assert ext == '.surf', surf_filename tag_filename = base + '.tags' cases_new = [] has_tag_data = False results_form = [] geometry_form = [ #('Region', 0, []), ('ElementID', 0, []), ('NodeID', 1, []), ('SurfaceID', 2, []), ('ReconFlag', 3, []), ('GridBC', 4, []), ('NormalX', 5, []), ('NormalY', 6, []), ('NormalZ', 7, []), ('normSpacing', 8, []), ('BL_thick', 9, []), ] nids = arange(1, nnodes + 1) norm_spacing = model.node_props[:, 0] bl_thickness = model.node_props[:, 1] ntris = model.tris.shape[0] nquads = model.quads.shape[0] #nelements = ntris + nquads eids = arange(1, nelements + 1) if ntris and nquads: element_props = vstack([model.tri_props, model.quad_props]) elif ntris: element_props = model.tri_props elif nquads: element_props = model.quad_props surf_ids = element_props[:, 0] recon_flags = element_props[:, 1] grid_bcs = element_props[:, 2] #print(unique(grid_bcs)) normals = model.get_normals() eid_res = GuiResult(0, header='ElementID', title='ElementID', location='centroid', scalar=eids) nid_res = GuiResult(0, header='NodeID', title='NodeID', location='node', scalar=nids) surface_res = GuiResult(0, header='SurfaceID', title='SurfaceID', location='centroid', scalar=surf_ids) recon_res = GuiResult(0, header='ReconFlag', title='ReconFlag', location='centroid', scalar=recon_flags) gridbc_res = GuiResult(0, header='GridBC', title='GridBC', location='centroid', scalar=grid_bcs) normalx_res = GuiResult(0, header='NormalX', title='NormalX', location='centroid', scalar=normals[:, 0]) normaly_res = GuiResult(0, header='NormalY', title='NormalY', location='centroid', scalar=normals[:, 1]) normalz_res = GuiResult(0, header='NormalZ', title='NormalZ', location='centroid', scalar=normals[:, 2]) normspacing_res = GuiResult(0, header='NormSpacing', title='NormSpacing', location='node', scalar=norm_spacing) blthick_res = GuiResult(0, header='BL_thick', title='BL_thick', location='node', scalar=bl_thickness) icase = 0 cases[icase] = (eid_res, (0, 'ElementID')) cases[icase + 1] = (nid_res, (0, 'NodeID')) cases[icase + 2] = (surface_res, (0, 'SurfaceID')) cases[icase + 3] = (recon_res, (0, 'ReconFlag')) cases[icase + 4] = (gridbc_res, (0, 'GridBC')) cases[icase + 5] = (normalx_res, (0, 'NormalX')) cases[icase + 6] = (normaly_res, (0, 'NormalY')) cases[icase + 7] = (normalz_res, (0, 'NormalZ')) cases[icase + 8] = (normspacing_res, (0, 'NormSpacing')) cases[icase + 9] = (blthick_res, (0, 'BL_thick')) icase += 10 if os.path.exists(tag_filename): tagger = TagReader() data = tagger.read_tag_filename(tag_filename) int_data = ones((nelements, 8), dtype='int32') * -10. float_data = zeros((nelements, 2), dtype='float64') for key, datai in sorted(iteritems(data)): #self.log.info(datai) [name, is_visc, is_recon, is_rebuild, is_fixed, is_source, is_trans, is_delete, bl_spacing, bl_thickness, nlayers] = datai i = where(surf_ids == key)[0] int_data[i, :] = [is_visc, is_recon, is_rebuild, is_fixed, is_source, is_trans, is_delete, nlayers] float_data[i, :] = [bl_spacing, bl_thickness] self.log.info('data[%i] = %s' % (key, name)) has_tag_data = True tag_form = [] tag_form.append(('is_visc', icase, [])) tag_form.append(('is_recon', icase + 1, [])) tag_form.append(('is_rebuild', icase + 2, [])) tag_form.append(('is_fixed', icase + 3, [])) tag_form.append(('is_source', icase + 4, [])) tag_form.append(('is_trans', icase + 5, [])) tag_form.append(('is_delete', icase + 6, [])) tag_form.append(('nlayers', icase + 7, [])) tag_form.append(('bl_spacing', icase + 8, [])) tag_form.append(('bl_thickness', icase + 9, [])) visc_res = GuiResult(0, header='is_visc', title='is_visc', location='centroid', scalar=int_data[:, 0]) recon_res = GuiResult(0, header='is_recon', title='is_recon', location='centroid', scalar=int_data[:, 1]) rebuild_res = GuiResult(0, header='is_rebuild', title='is_rebuild', location='centroid', scalar=int_data[:, 2]) fixed_res = GuiResult(0, header='is_fixed', title='is_fixed', location='centroid', scalar=int_data[:, 3]) source_res = GuiResult(0, header='is_source', title='is_source', location='centroid', scalar=int_data[:, 4]) trans_res = GuiResult(0, header='is_trans', title='is_trans', location='centroid', scalar=int_data[:, 5]) delete_res = GuiResult(0, header='is_delete', title='is_delete', location='centroid', scalar=int_data[:, 6]) nlayers_res = GuiResult(0, header='nlayers', title='nlayers', location='centroid', scalar=int_data[:, 7]) spacing_res = GuiResult(0, header='bl_spacing', title='bl_spacing', location='centroid', scalar=float_data[:, 0]) blthickness_res = GuiResult(0, header='bl_thickness', title='bl_thickness', location='centroid', scalar=float_data[:, 1]) cases[icase] = (visc_res, (0, 'is_visc')) cases[icase + 1] = (recon_res, (0, 'is_recon')) cases[icase + 2] = (rebuild_res, (0, 'is_rebuild')) cases[icase + 3] = (fixed_res, (0, 'is_fixed')) cases[icase + 4] = (source_res, (0, 'is_source')) cases[icase + 5] = (trans_res, (0, 'is_trans')) cases[icase + 6] = (delete_res, (0, 'is_delete')) cases[icase + 7] = (nlayers_res, (0, 'nlayers')) cases[icase + 8] = (spacing_res, (0, 'bl_spacing')) cases[icase + 9] = (blthickness_res, (0, 'bl_thickness')) form = [ ('Geometry', None, geometry_form), ] if has_tag_data: form.append(('Tag Data', None, tag_form),) results_form = [] if len(results_form): form.append(('Results', None, results_form)) return form, cases
def _fill_ugrid3d_case(self, base, cases, ID, nnodes, nelements, model): tag_filename = base + '.tags' mapbc_filename = base.split('.')[0] + '.mapbc' self.log.info('mapbc_filename = %r' % mapbc_filename) cases_new = [] has_tag_data = False has_mapbc_data = False results_form = [] mapbc_form = [] geometry_form = [ #('Region', 0, []), ('ElementID', 0, []), ('NodeID', 1, []), ('SurfaceID', 2, []), #('normSpacing', 3, []), #('BL_thick', 4, []), #('ReconFlag', 5, []), #('GridBC', 6, []), ] ntris = model.tris.shape[0] nquads = model.quads.shape[0] #nelements = ntris + nquads eids = arange(1, nelements + 1) nids = arange(1, nnodes + 1) #grid_bcs = element_props[:, 2] #npids = len(model.pids) pids = model.pids eid_res = GuiResult(0, header='ElementID', title='ElementID', location='centroid', scalar=eids) nid_res = GuiResult(0, header='NodeID', title='NodeID', location='node', scalar=nids) surface_res = GuiResult(0, header='SurfaceID', title='SurfaceID', location='centroid', scalar=pids) icase = 0 cases[icase] = (eid_res, (0, 'ElementID')) cases[icase + 1] = (nid_res, (0, 'NodeID')) cases[icase + 2] = (surface_res, (0, 'SurfaceID')) icase = 3 if os.path.exists(tag_filename): #surf_ids = element_props[:, 0] #recon_flags = element_props[:, 1] #cases[(ID, 2, 'ReconFlag', 1, 'centroid', '%i')] = recon_flags #cases[(ID, 3, 'GridBC', 1, 'centroid', '%i')] = grid_bcs tagger = TagReader() data = tagger.read_tag_filename(tag_filename) int_data = ones((nelements, 8), dtype='int32') * -10. float_data = zeros((nelements, 2), dtype='float64') for key, datai in sorted(iteritems(data)): #self.log.info(datai) [name, is_visc, is_recon, is_rebuild, is_fixed, is_source, is_trans, is_delete, bl_spacing, bl_thickness, nlayers] = datai i = where(pids == key)[0] int_data[i, :] = [is_visc, is_recon, is_rebuild, is_fixed, is_source, is_trans, is_delete, nlayers] float_data[i, :] = [bl_spacing, bl_thickness] self.log.info('data[%i] = %s' % (key, name)) has_tag_data = True tag_form = [] tag_form.append(('is_visc', icase, [])) tag_form.append(('is_recon', icase+1, [])) tag_form.append(('is_rebuild', icase+2, [])) tag_form.append(('is_fixed', icase+3, [])) tag_form.append(('is_source', icase+4, [])) tag_form.append(('is_trans', icase+5, [])) tag_form.append(('is_delete', icase+6, [])) tag_form.append(('nlayers', icase+7, [])) tag_form.append(('bl_spacing', icase+8, [])) tag_form.append(('bl_thickness', icase+9, [])) visc_res = GuiResult(0, header='is_visc', title='is_visc', location='node', scalar=int_data[:, 0]) recon_res = GuiResult(0, header='is_recon', title='is_recon', location='node', scalar=int_data[:, 1]) rebuild_res = GuiResult(0, header='is_rebuild', title='is_rebuild', location='node', scalar=int_data[:, 2]) fixed_res = GuiResult(0, header='is_fixed', title='is_fixed', location='node', scalar=int_data[:, 3]) source_res = GuiResult(0, header='is_source', title='is_source', location='node', scalar=int_data[:, 4]) trans_res = GuiResult(0, header='is_trans', title='is_trans', location='node', scalar=int_data[:, 5]) delete_res = GuiResult(0, header='is_delete', title='is_delete', location='node', scalar=int_data[:, 6]) nlayers_res = GuiResult(0, header='nlayers', title='nlayers', location='node', scalar=int_data[:, 7]) spacing_res = GuiResult(0, header='bl_spacing', title='bl_spacing', location='centroid', scalar=float_data[:, 0]) blthickness_res = GuiResult(0, header='bl_thickness', title='bl_thickness', location='centroid', scalar=float_data[:, 1]) cases[icase] = (visc_res, (0, 'is_visc')) cases[icase + 1] = (recon_res, (0, 'is_recon')) cases[icase + 2] = (rebuild_res, (0, 'is_rebuild')) cases[icase + 3] = (fixed_res, (0, 'is_fixed')) cases[icase + 4] = (source_res, (0, 'is_source')) cases[icase + 5] = (trans_res, (0, 'is_trans')) cases[icase + 6] = (delete_res, (0, 'is_delete')) cases[icase + 7] = (nlayers_res, (0, 'nlayers')) cases[icase + 8] = (spacing_res, (0, 'bl_spacing')) cases[icase + 9] = (blthickness_res, (0, 'bl_thickness')) icase += 10 else: self.log.warning('tag_filename=%r could not be found' % tag_filename) if os.path.exists(mapbc_filename): has_mapbc_data = True mapbc = open(mapbc_filename, 'r') lines = mapbc.readlines() lines = [line.strip() for line in lines if not line.strip().startswith('#') and line.strip()] npatches = int(lines[0]) mapbcs = zeros(pids.shape, dtype='int32') for ipatch in range(npatches): line = lines[ipatch + 1] iline, bc_num, name = line.split() iline = int(iline) bc_num = int(bc_num) assert ipatch + 1 == iline, 'line=%r; ipatch=%s iline=%s' % (line, ipatch + 1, iline) islot = where(pids == ipatch + 1)[0] if len(islot) == 0: upids = unique(pids) msg = 'ipatch=%s not found in pids=%s' % (ipatch + 1, upids) raise RuntimeError(msg) mapbcs[islot] = bc_num self.log.info(line) mapbc_form.append(('Map BC', icase, [])) mapbc_res = GuiResult(0, header='Map BC', title='Map BC', location='centroid', scalar=mapbcs) cases[icase + 9] = (mapbc_res, (0, 'Map BC')) else: self.log.warning('mapbc_filename=%r could not be found' % mapbc_filename) #norm_spacing = model.node_props[:, 0] #bl_thickness = model.node_props[:, 1] #cases[(ID, 1, 'normSpacing', 1, 'node', '%.3e', '')] = norm_spacing #cases[(ID, 2, 'BL_thick', 1, 'node', '%.3e', '')] = bl_thickness form = [ ('Geometry', None, geometry_form), ] if has_tag_data: form.append(('Tag Data', None, tag_form),) if has_mapbc_data: form.append(('Map BC Data', None, mapbc_form),) results_form = [] if len(results_form): form.append(('Results', None, results_form)) self.log.info(form) return form, cases