def generate_surface_dict(self, context): scene = context.scene surface_feature_dict = ReynoldsFoamDict('surfaceFeatureExtractDict.foam') for name, geometry_info in scene.geometries.items(): if geometry_info['has_features']: print('generate feature extract dict for ', name) file_path = geometry_info.get('file_path', None) if file_path: key = os.path.basename(file_path) else: key = name surface_feature_dict[key] = {} surface_feature_dict[key][ 'extractionMethod'] = 'extractFromSurface' surface_feature_dict[key]['writeObj'] = 'yes' coeffs = {'includedAngle': geometry_info['included_angle']} surface_feature_dict[key]['extractFromSurfaceCoeffs'] = coeffs print(surface_feature_dict[key]) print(surface_feature_dict) abs_case_dir_path = bpy.path.abspath(scene.case_dir_path) system_dir = os.path.join(abs_case_dir_path, "system") if not os.path.exists(system_dir): os.makedirs(system_dir) sfed_file_path = os.path.join(system_dir, "surfaceFeatureExtractDict") with open(sfed_file_path, "w") as f: f.write(str(surface_feature_dict)) return {'FINISHED'}
def execute(self, context): scene = context.scene # ------------------------- # Start the console operatorr # -------------------------- bpy.ops.reynolds.of_console_op() print('Generate decomposeParDict parallel config: ') decompose_par_dict = ReynoldsFoamDict('decomposeParDict.foam') # mandatory decompose_par_dict['numberOfSubdomains'] = scene.number_of_subdomains decompose_par_dict['method'] = scene.decompose_method # simpleCoeffs simple_nxyz = (str(scene.nSimpleCoeffsX), str(scene.nSimpleCoeffsY), str(scene.nSimpleCoeffsZ)) decompose_par_dict['simpleCoeffs']['n'] = '(' + ' '.join( simple_nxyz) + ')' decompose_par_dict['simpleCoeffs']['delta'] = scene.simpleCoeffDelta # hierarchicalCoeffs hierarchical_nxyz = (str(scene.nHierarchicalCoeffsX), str(scene.nHierarchicalCoeffsY), str(scene.nHierarchicalCoeffsZ)) decompose_par_dict['hierarchicalCoeffs']['n'] = '(' + ' '.join( hierarchical_nxyz) + ')' decompose_par_dict['hierarchicalCoeffs'][ 'delta'] = scene.hierarchicalCoeffDelta decompose_par_dict['hierarchicalCoeffs'][ 'order'] = scene.order_of_decomposition # metisCoeffs decompose_par_dict['metisCoeffs'][ 'processorWeights'] = scene.metisCoeffs_processor_weights decompose_par_dict['metisCoeffs'][ 'strategy'] = scene.metisCoeffs_strategy # manualCoeffs if scene.manual_datafile_path: data_file_path = bpy.path.abspath(scene.manual_datafile_path) decompose_par_dict['manualCoeffs'][ 'datafile'] = """ '"{}"' """.format(data_file_path) print("DECOMPOSE PAR DICT") print(decompose_par_dict) abs_case_dir_path = bpy.path.abspath(scene.case_dir_path) system_dir = os.path.join(abs_case_dir_path, "system") if not os.path.exists(system_dir): os.makedirs(system_dir) dpd_file_path = os.path.join(system_dir, "decomposeParDict") with open(dpd_file_path, "w") as f: f.write(str(decompose_par_dict)) return {'FINISHED'}
def generate_time_props(self, context): scene = context.scene print(' Generate time properties') print(scene.time_props) print(scene.time_props_dimensions) print(scene.time_props_internal_field) abs_case_dir_path = bpy.path.abspath(scene.case_dir_path) # Now loop through regions and generate distinct time properties in 0 dir for prop in scene.time_props: time_prop_dict = ReynoldsFoamDict(prop + '.foam') time_prop_dict['dimensions'] = scene.time_props_dimensions[prop] time_prop_dict['internalField'] = scene.time_props_internal_field[prop] patches = {} # these are block mesh patches print('------- Block mesh patches -------') for _, r in scene.regions.items(): name, patch_type, face_labels, time_prop_info = r print(' name: ' + name + ' time prop info: ') print(time_prop_info) patches[name] = {} if prop in time_prop_info: patches[name]['type'] = time_prop_info[prop]['type'] v = time_prop_info[prop]['value'] if v != "": patches[name]['value'] = v # these are geometry patches print('------- geometry patches -------') for name, time_prop_info in scene.geo_patches.items(): print(' name: ' + name + ' time prop info: ') print(time_prop_info) patches[name] = {} if prop in time_prop_info: patches[name]['type'] = time_prop_info[prop]['type'] v = time_prop_info[prop]['value'] if v != "": patches[name]['value'] = v print('Patches for time props : ') print(patches) time_prop_dict['boundaryField'] = patches zero_dir = os.path.join(abs_case_dir_path, "0") if not os.path.exists(zero_dir): os.makedirs(zero_dir) prop_file_path = os.path.join(zero_dir, prop) print('Write time property file for prop: ' + prop + ' to file ' + prop_file_path) with open(prop_file_path, "w+") as f: f.write(str(time_prop_dict)) return {'FINISHED'}
def execute(self, context): scene = context.scene print('Generate fvsolution for solver: ' + scene.solver_name) abs_case_dir_path = bpy.path.abspath(scene.case_dir_path) fvsolution = ReynoldsFoamDict('fvSolution.foam', solver_name=scene.solver_name) if scene.solver_name == 'laplacianFoam': generate_laplacianFoam_fvsolution(fvsolution, scene) elif scene.solver_name == 'icoFoam': generate_icoFoam_fvsolution(fvsolution, scene) system_dir = os.path.join(abs_case_dir_path, "system") if not os.path.exists(system_dir): os.makedirs(system_dir) fvsolution_file_path = os.path.join(system_dir, "fvSolution") with open(fvsolution_file_path, "w+") as f: f.write(str(fvsolution)) return {'FINISHED'}
def execute(self, context): scene = context.scene print('Generate transport props for solver: ' + scene.solver_name) abs_case_dir_path = bpy.path.abspath(scene.case_dir_path) transport = ReynoldsFoamDict('transportProperties.foam', solver_name=scene.solver_name) if scene.solver_name == 'laplacianFoam': generate_laplacianFoam_transport(transport, scene) elif scene.solver_name == 'icoFoam': generate_icoFoam_transport(transport, scene) constant_dir = os.path.join(abs_case_dir_path, "constant") if not os.path.exists(constant_dir): os.makedirs(constant_dir) transport_file_path = os.path.join(constant_dir, "transportProperties") with open(transport_file_path, "w+") as f: f.write(str(transport)) return {'FINISHED'}
def generate_snappyhexmeshdict(self, context): scene = context.scene snappy_dict = ReynoldsFoamDict('snappyHexMeshDict.foam') # ------------------------- # Start the console operatorr # -------------------------- bpy.ops.reynolds.of_console_op() abs_case_dir_path = bpy.path.abspath(scene.case_dir_path) if abs_case_dir_path is None or abs_case_dir_path == '': self.report({'ERROR'}, 'Please select a case directory') return {'FINISHED'} if not scene.foam_started: self.report({'ERROR'}, 'Please start open foam') return {'FINISHED'} if (not scene.castellated_mesh_step and not scene.snap_step and not scene.add_layers_step): self.report({'ERROR'}, 'Please select the snappyhexmesh steps') return {'FINISHED'} if len(scene.geometries) == 0: self.report({'ERROR'}, 'Please add geometries') return {'FINISHED'} bmd_file_path = os.path.join(abs_case_dir_path, "system", "blockMeshDict") if not os.path.exists(bmd_file_path): self.report({'ERROR'}, 'Please generate block mesh dict') return {'FINISHED'} if not scene.blockmesh_executed: self.report({'ERROR'}, 'Please run blockMesh') return {'FINISHED'} sfed_file_path = os.path.join(abs_case_dir_path, "system", "surfaceFeatureExtractDict") if not os.path.exists(sfed_file_path): self.report({'ERROR'}, 'Please generate surface feature dict') return {'FINISHED'} if not scene.features_extracted: self.report({'ERROR'}, 'Please run extract surface features') return {'FINISHED'} # steps to run snappy_dict['castellatedMesh'] = scene.castellated_mesh_step snappy_dict['snap'] = scene.snap_step snappy_dict['addLayers'] = scene.add_layers_step for name, geometry_info in scene.geometries.items(): print('generate feature extract dict for ', name) # geometry file_path = geometry_info.get('file_path', None) if file_path: key = os.path.basename(file_path) key_without_ext = os.path.splitext(key)[0] else: key = name key_without_ext = name print('key : key without ext' , key, ' : ', key_without_ext) if geometry_info['type'] == 'triSurfaceMesh': snappy_dict['geometry'][key] = {'type': geometry_info['type'], 'name': key_without_ext } if geometry_info['type'] == 'searchableSphere': centre = geometry_info['centre'] snappy_dict['geometry'][key] = {'type': geometry_info['type'], 'centre': [centre.x, centre.z, centre.y], 'radius': geometry_info['radius']} if geometry_info['type'] == 'searchableBox': level_min = geometry_info['min'] level_max = geometry_info['max'] snappy_dict['geometry'][key] = {'type': geometry_info['type'], 'min': [level_min[0], level_min[2], level_min[1]], 'max': [level_max[0], level_max[2], level_max[1]]} # features features = [] if geometry_info['has_features']: features.append({'file': '"' + key_without_ext + '.eMesh' + '"', 'level': geometry_info['feature_level']}) snappy_dict['castellatedMeshControls']['features'] = features # refinement surface if geometry_info['refinement_type'] == 'Surface': surface = {'level': [geometry_info['refinementSurface']['min'], geometry_info['refinementSurface']['max']]} snappy_dict['castellatedMeshControls']['refinementSurfaces'][key_without_ext] = surface # refinement region if geometry_info['refinement_type'] == 'Region': region = {'mode': geometry_info['refinementRegion']['mode'], 'levels': [[geometry_info['refinementRegion']['dist'], geometry_info['refinementRegion']['level']]]} snappy_dict['castellatedMeshControls']['refinementRegions'][key_without_ext] = region # castellatedMeshControls snappy_dict['castellatedMeshControls']['maxLocalCells'] = scene.max_local_cells snappy_dict['castellatedMeshControls']['maxGlobalCells'] = scene.max_global_cells snappy_dict['castellatedMeshControls']['minRefinementCells'] = scene.min_refinement_cells snappy_dict['castellatedMeshControls']['maxLoadUnbalance'] = scene.max_load_unbalance snappy_dict['castellatedMeshControls']['resolveFeatureAngle'] = scene.resolve_feature_angle location_in_mesh = scene.location_in_mesh if location_in_mesh[0] != 0 and location_in_mesh[1] != 0 and location_in_mesh[2] != 0: snappy_dict['castellatedMeshControls']['locationInMesh'] = [location_in_mesh[0], location_in_mesh[2], location_in_mesh[1]] snappy_dict['castellatedMeshControls']['allowFreeStandingZoneFaces'] = scene.allow_free_standing_zones # snapControls snappy_dict['snapControls']['nSmoothPatch'] = scene.n_smooth_patch_iter snappy_dict['snapControls']['tolerance'] = scene.tolerance snappy_dict['snapControls']['nSolveIter'] = scene.disp_relax_iter snappy_dict['snapControls']['nRelaxIter'] = scene.snapping_relax_iter snappy_dict['snapControls']['nFeatureSnapIter'] = scene.feature_edge_snapping_iter snappy_dict['snapControls']['implicitFeatureSanp'] = scene.implicit_feature_snap snappy_dict['snapControls']['explicitFeatureSnap'] = scene.explicit_feature_snap snappy_dict['snapControls']['multiRegionFeatureSnap'] = scene.multi_region_feature_snap # addLayersControls for name, layers in scene.add_layers.items(): snappy_dict['addLayersControls']['layers'][name] = {'nSurfaceLayers': layers} snappy_dict['addLayersControls']['relativeSizes'] = scene.relative_sizes snappy_dict['addLayersControls']['expansionRatio'] = scene.expansion_ratio snappy_dict['addLayersControls']['finalLayerThickness'] = scene.final_layer_thickness snappy_dict['addLayersControls']['minThickness'] = scene.min_layer_thickness snappy_dict['addLayersControls']['nGrow'] = scene.n_grow_layers snappy_dict['addLayersControls']['featureAngle'] = scene.layer_feature_angle snappy_dict['addLayersControls']['nRelaxIter'] = scene.layer_n_relax_iter snappy_dict['addLayersControls']['nSmoothSurfaceNormals'] = scene.layer_n_smooth_normal_iter snappy_dict['addLayersControls']['nSmoothNormals'] = scene.layer_n_smooth_iter snappy_dict['addLayersControls']['nSmoothThickness'] = scene.smooth_layer_thickness snappy_dict['addLayersControls']['maxFaceThicknessRatio'] = scene.max_face_thickness_ratio snappy_dict['addLayersControls']['maxThicknessToMedialRatio'] = scene.max_thickness_to_medial_ratio snappy_dict['addLayersControls']['minMedianAxisAngle'] = scene.min_median_axis_angle snappy_dict['addLayersControls']['nBufferCellsNoExtrude'] = scene.n_buffer_cells_no_extrude snappy_dict['addLayersControls']['nLayerIter'] = scene.layer_n_add_iter snappy_dict['addLayersControls']['nRelaxedIter'] = scene.layer_n_mesh_quality_iter #meshQualityControls snappy_dict['meshQualityControls']['maxNonOrtho'] = scene.max_non_ortho snappy_dict['meshQualityControls']['maxBoundarySkewness'] = scene.max_boundary_skewness snappy_dict['meshQualityControls']['maxInternalFaceSkewness'] = scene.max_internal_face_skewness snappy_dict['meshQualityControls']['maxConcave'] = scene.max_concaveness if scene.min_pyramid_vol != 0: snappy_dict['meshQualityControls']['minVol'] = scene.min_pyramid_vol if scene.min_tetrahedral_quality != 0: snappy_dict['meshQualityControls']['minTetQuality'] = scene.min_tetrahedral_quality snappy_dict['meshQualityControls']['minArea'] = scene.min_face_area snappy_dict['meshQualityControls']['minTwist'] = scene.min_face_twist snappy_dict['meshQualityControls']['minDeterminant'] = scene.min_cell_det snappy_dict['meshQualityControls']['minFaceWeight'] = scene.min_face_weight snappy_dict['meshQualityControls']['minVolRatio'] = scene.min_vol_ratio snappy_dict['meshQualityControls']['minTriangleTwist'] = scene.min_tri_twist snappy_dict['meshQualityControls']['nSmoothScale'] = scene.n_smooth_scale snappy_dict['meshQualityControls']['errorReduction'] = scene.error_reduction print('--------------------') print('SNAPPY HEX MESH DICT') print('--------------------') print(snappy_dict) print('--------------------') system_dir = os.path.join(abs_case_dir_path, "system") if not os.path.exists(system_dir): os.makedirs(system_dir) shmd_file_path = os.path.join(system_dir, "snappyHexMeshDict") with open(shmd_file_path, "w") as f: f.write(str(snappy_dict)) return {'FINISHED'}
def generate_blockmeshdict(self, context): scene = context.scene obj = context.active_object # ------------------------- # Start the console operatorr # -------------------------- bpy.ops.reynolds.of_console_op() print("Select dir for generated blockmeshdict file") abs_case_dir_path = bpy.path.abspath(scene.case_dir_path) if abs_case_dir_path is None or abs_case_dir_path == '': self.report({'ERROR'}, 'Please select a case directory') return {'FINISHED'} if not scene.foam_started: self.report({'ERROR'}, 'Please start open foam') return {'FINISHED'} print(" ABSOLUTE CASE DIR PATH: ", abs_case_dir_path) if obj is None: self.report({'ERROR'}, 'Please select a block object') return {'FINISHED'} bbox = obj.bound_box x = [v[0] for v in obj.bound_box] x.sort() y = [v[2] for v in obj.bound_box] y.sort() z = [v[1] for v in obj.bound_box] z.sort() block_mesh_dict = ReynoldsFoamDict('blockMeshDict.foam') # generate bmd vertices bmd_vertices = [] bmd_vertices.append([x[0], y[0], z[0]]) bmd_vertices.append([x[7], y[0], z[0]]) bmd_vertices.append([x[7], y[7], z[0]]) bmd_vertices.append([x[0], y[7], z[0]]) bmd_vertices.append([x[0], y[0], z[7]]) bmd_vertices.append([x[7], y[0], z[7]]) bmd_vertices.append([x[7], y[7], z[7]]) bmd_vertices.append([x[0], y[7], z[7]]) block_mesh_dict['vertices'] = bmd_vertices # generate bmd blocks bmd_blocks = [] bmd_blocks.append('hex') bmd_blocks.append([0, 1, 2, 3, 4, 5, 6, 7]) bmd_blocks.append([ scene.block_cells_pg.n_cells[0], scene.block_cells_pg.n_cells[1], scene.block_cells_pg.n_cells[2] ]) bmd_blocks.append('simpleGrading') grading_x = [[1, 1, scene.block_cells_pg.n_grading[0]]] grading_y = [[1, 1, scene.block_cells_pg.n_grading[1]]] grading_z = [[1, 1, scene.block_cells_pg.n_grading[2]]] grading = [grading_x, grading_y, grading_z] bmd_blocks.append(grading) print(bmd_blocks) block_mesh_dict['blocks'] = bmd_blocks # generate bmd regions bmd_boundary = [] for name, r in scene.regions.items(): name, patch_type, face_labels, _ = r bmd_boundary.append(name) br = {} br['type'] = patch_type faces = [] for f in face_labels: if f == 'Front': faces.append([0, 3, 2, 1]) if f == 'Back': faces.append([4, 5, 6, 7]) if f == 'Top': faces.append([3, 7, 6, 2]) if f == 'Bottom': faces.append([0, 1, 5, 4]) if f == 'Left': faces.append([0, 4, 7, 3]) if f == 'Right': faces.append([1, 2, 6, 5]) br['faces'] = faces bmd_boundary.append(br) print(bmd_boundary) if len(bmd_boundary) == 0: self.report({'ERROR'}, 'Please select regions/boundary conditions') return {'FINISHED'} block_mesh_dict['boundary'] = bmd_boundary # set convert to meters block_mesh_dict['convertToMeters'] = scene.block_cells_pg.convert_to_meters print("BLOCK MESH DICT") print(block_mesh_dict) system_dir = os.path.join(abs_case_dir_path, "system") if not os.path.exists(system_dir): os.makedirs(system_dir) bmd_file_path = os.path.join(system_dir, "blockMeshDict") with open(bmd_file_path, "w") as f: f.write(str(block_mesh_dict)) return {'FINISHED'}
def test_blockmesh_dict(self): block_mesh_dict = ReynoldsFoamDict('blockMeshDict.foam') self.assertIsNotNone(block_mesh_dict) # check vertices self.assertEqual(block_mesh_dict['vertices'], []) vertices = [] vertices.append([0, 0, 0]) vertices.append([1, 0, 0]) vertices.append([1, 1, 0]) vertices.append([0, 1, 0]) vertices.append([0, 0, 0.1]) vertices.append([1, 0, 0.1]) vertices.append([1, 1, 0.1]) vertices.append([0, 1, 0.1]) # check blocks block_mesh_dict['vertices'] = vertices self.assertEqual(block_mesh_dict['vertices'], ['(0 0 0)', '(1 0 0)', '(1 1 0)', '(0 1 0)', '(0 0 0.1)', '(1 0 0.1)', '(1 1 0.1)', '(0 1 0.1)']) self.assertEqual(block_mesh_dict['blocks'], []) blocks = [] blocks.append('hex') blocks.append([0, 1, 2, 3, 4, 5, 6, 7]) blocks.append([20, 20, 1]) blocks.append('simpleGrading') blocks.append([1, 1, 1]) block_mesh_dict['blocks'] = blocks self.assertEqual(block_mesh_dict['blocks'], ['hex', [0, 1, 2, 3, 4, 5, 6, 7], '(20 20 1)', 'simpleGrading', '(1 1 1)']) # check edges self.assertEqual(block_mesh_dict['edges'], []) edges = [] edges.append('arc') edges.append(1) edges.append(5) edges.append([1.1, 0.0, 0.5]) block_mesh_dict['edges'] = edges self.assertEqual(block_mesh_dict['edges'], ['arc', 1, 5, '(1.1 0.0 0.5)']) # check boundary self.assertEqual(block_mesh_dict['boundary'], []) boundary = [] # add moving wall boundary.append('movingWall') moving_wall = {} moving_wall['faces'] = [[3, 7, 6, 2]] moving_wall['type'] = 'wall' boundary.append(moving_wall) # add fixed walls boundary.append('fixedWalls') fixed_walls = {} fixed_walls['faces'] = [[0, 4, 7, 3], [2, 6, 5, 1], [1, 5, 4, 0]] fixed_walls['type'] = 'wall' boundary.append(fixed_walls) # add front and back boundary.append('frontAndBack') front_and_back = {} front_and_back['faces'] = [[0, 3, 2, 1], [4, 5, 6, 7]] front_and_back['type'] = 'empty' boundary.append(front_and_back) block_mesh_dict['boundary'] = boundary self.assertEqual(block_mesh_dict['boundary'], boundary) # check mergePatchPairs self.assertEqual(block_mesh_dict['mergePatchPairs'], []) mergePatchPairs = [] mergePatchPairs.append(['inlet1', 'outlet1']) mergePatchPairs.append(['inlet2', 'outlet2']) block_mesh_dict['mergePatchPairs'] = mergePatchPairs self.assertEqual(block_mesh_dict['mergePatchPairs'], mergePatchPairs) print(block_mesh_dict)