def __init__(self, cart_mesh_obj): self.mesh_obj = cart_mesh_obj self.analysis = CfdTools.getParentAnalysisObject(self.mesh_obj) self.part_obj = self.mesh_obj.Part # Part to mesh self.scale = 0.001 # Scale mm to m # Default to 2 % of bounding box characteristic length self.clmax = Units.Quantity(self.mesh_obj.CharacteristicLengthMax).Value if self.clmax <= 0.0: shape = self.part_obj.Shape cl_bound_box = math.sqrt(shape.BoundBox.XLength**2 + shape.BoundBox.YLength**2 + shape.BoundBox.ZLength**2) self.clmax = 0.02*cl_bound_box # Always in internal format, i.e. mm # Only used by gmsh - what purpose? self.clmin = 0.0 self.dimension = self.mesh_obj.ElementDimension shape_face_names = [] for (i, f) in enumerate(self.part_obj.Shape.Faces): face_name = ("face{}".format(i)) shape_face_names.append(face_name) self.mesh_obj.ShapeFaceNames = shape_face_names self.cf_settings = {} self.snappy_settings = {} self.gmsh_settings = {} self.two_d_settings = {} self.error = False output_path = CfdTools.getOutputPath(self.analysis) self.getFilePaths(output_path)
def edit_case(self): """ Open case folder externally in file browser. """ case_path = os.path.abspath(os.path.join(CfdTools.getOutputPath(self.analysis), self.solver.InputCaseName)) FreeCAD.Console.PrintMessage("Please edit the case input files externally at: {}\n".format(case_path)) if platform.system() == 'MacOS': self.edit_process = subprocess.Popen(['open', '--', case_path]) elif platform.system() == 'Linux': self.edit_process = subprocess.Popen(['xdg-open', case_path]) elif platform.system() == 'Windows': self.edit_process = subprocess.Popen(['explorer', case_path])
def __init__(self, analysis_obj): self.analysis_obj = analysis_obj self.solver_obj = CfdTools.getSolver(analysis_obj) self.physics_model = CfdTools.getPhysicsModel(analysis_obj) self.mesh_obj = CfdTools.getMesh(analysis_obj) self.material_objs = CfdTools.getMaterials(analysis_obj) self.bc_group = CfdTools.getCfdBoundaryGroup(analysis_obj) self.initial_conditions = CfdTools.getInitialConditions(analysis_obj) self.porousZone_objs = CfdTools.getPorousZoneObjects(analysis_obj) self.initialisationZone_objs = CfdTools.getInitialisationZoneObjects(analysis_obj) self.zone_objs = CfdTools.getZoneObjects(analysis_obj) self.mesh_generated = False self.working_dir = CfdTools.getOutputPath(self.analysis_obj)
def __init__(self, solver_runner_obj): ui_path = os.path.join(os.path.dirname(__file__), "TaskPanelCfdSolverControl.ui") self.form = FreeCADGui.PySideUic.loadUi(ui_path) self.analysis_object = FemGui.getActiveAnalysis() self.solver_runner = solver_runner_obj self.solver_object = solver_runner_obj.solver # update UI self.console_message = '' self.solver_run_process = CfdConsoleProcess( finishedHook=self.solverFinished, stdoutHook=self.gotOutputLines, stderrHook=self.gotErrorLines) self.Timer = QtCore.QTimer() self.Timer.start(100) self.form.terminateSolver.clicked.connect(self.killSolverProcess) self.form.terminateSolver.setEnabled(False) self.open_paraview = QtCore.QProcess() self.working_dir = CfdTools.getOutputPath(self.analysis_object) self.updateUI() # Connect Signals and Slots QtCore.QObject.connect(self.form.pb_write_inp, QtCore.SIGNAL("clicked()"), self.write_input_file_handler) QtCore.QObject.connect(self.form.pb_edit_inp, QtCore.SIGNAL("clicked()"), self.editSolverInputFile) QtCore.QObject.connect(self.form.pb_run_solver, QtCore.SIGNAL("clicked()"), self.runSolverProcess) # QtCore.QObject.connect(self.form.pb_show_result, QtCore.SIGNAL("clicked()"), self.showResult) QtCore.QObject.connect(self.form.pb_paraview, QtCore.SIGNAL("clicked()"), self.openParaview) # self.form.pb_show_result.setEnabled(False) QtCore.QObject.connect(self.Timer, QtCore.SIGNAL("timeout()"), self.updateText) self.Start = time.time()
def __init__(self, cart_mesh_obj): self.mesh_obj = cart_mesh_obj self.analysis = CfdTools.getParentAnalysisObject(self.mesh_obj) self.part_obj = self.mesh_obj.Part # Part to mesh self.scale = 0.001 # Scale mm to m # Default to 2 % of bounding box characteristic length self.clmax = Units.Quantity( self.mesh_obj.CharacteristicLengthMax).Value if self.clmax <= 0.0: shape = self.part_obj.Shape cl_bound_mag = math.sqrt(shape.BoundBox.XLength**2 + shape.BoundBox.YLength**2 + shape.BoundBox.ZLength**2) cl_bound_min = min( min(shape.BoundBox.XLength, shape.BoundBox.YLength), shape.BoundBox.ZLength) self.clmax = min( 0.02 * cl_bound_mag, 0.4 * cl_bound_min) # Always in internal format, i.e. mm # Only used by gmsh - what purpose? self.clmin = 0.0 self.dimension = self.mesh_obj.ElementDimension self.cf_settings = {} self.snappy_settings = {} self.gmsh_settings = {} self.two_d_settings = {} self.error = False output_path = CfdTools.getOutputPath(self.analysis) self.getFilePaths(output_path) # 2D array of list of faces (index into shape) in each patch, indexed by [bc_id+1][meshregion_id+1] self.patch_faces = [] # 2D array of names of each patch, indexed by [bc_id+1][meshregion_id+1] self.patch_names = []
def runMeshProcess(self): self.console_message_cart = '' self.Start = time.time() self.Timer.start() # Re-initialise CfdMeshTools with new parameters self.set_mesh_params() self.cart_mesh = CfdMeshTools.CfdMeshTools(self.mesh_obj) self.consoleMessage("Starting meshing ...") try: QApplication.setOverrideCursor(Qt.WaitCursor) self.get_active_analysis() self.set_mesh_params() cart_mesh = self.cart_mesh setInputFieldQuantity(self.form.if_max, str(cart_mesh.get_clmax())) print("\nStarting meshing ...\n") print(' Part to mesh: Name --> ' + cart_mesh.part_obj.Name + ', Label --> ' + cart_mesh.part_obj.Label + ', ShapeType --> ' + cart_mesh.part_obj.Shape.ShapeType) print(' CharacteristicLengthMax: ' + str(cart_mesh.clmax)) cart_mesh.get_dimension() cart_mesh.get_file_paths(CfdTools.getOutputPath(self.analysis)) cart_mesh.setup_mesh_case_dir() self.consoleMessage("Exporting mesh region data ...") cart_mesh.get_region_data( ) # Writes region stls so need file structure cart_mesh.write_mesh_case() self.consoleMessage("Exporting the part surfaces ...") cart_mesh.write_part_file() self.consoleMessage("Running {} ...".format(self.utility)) self.runCart(cart_mesh) except Exception as ex: self.consoleMessage("Error: " + str(ex), '#FF0000') self.Timer.stop() raise finally: QApplication.restoreOverrideCursor()
def writeMesh(self): """ Convert or copy mesh files """ if self.mesh_obj.Proxy.Type == "CfdMesh": import CfdMeshTools # Move Cartesian mesh files from temporary mesh directory to case directory self.cart_mesh = CfdMeshTools.CfdMeshTools(self.mesh_obj) cart_mesh = self.cart_mesh # Update output file locations cart_mesh.get_file_paths(CfdTools.getOutputPath(self.analysis_obj)) if self.mesh_obj.MeshUtility == "cfMesh": print("Writing Cartesian mesh\n") CfdTools.copyFilesRec( cart_mesh.polyMeshDir, os.path.join(self.case_folder, 'constant', 'polyMesh')) CfdTools.copyFilesRec( cart_mesh.triSurfaceDir, os.path.join(self.case_folder, 'constant', 'triSurface')) # shutil.copy2(cart_mesh.temp_file_meshDict, os.path.join(self.case_folder,'system')) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'system', 'meshDict'), os.path.join(self.case_folder, 'system')) shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'Allmesh'), self.case_folder) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'log.cartesianMesh'), self.case_folder) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'log.surfaceFeatureEdges'), self.case_folder) elif self.mesh_obj.MeshUtility == "snappyHexMesh": print("Writing snappyHexMesh generated Cartesian mesh\n") CfdTools.copyFilesRec( cart_mesh.polyMeshDir, os.path.join(self.case_folder, 'constant', 'polyMesh')) CfdTools.copyFilesRec( cart_mesh.triSurfaceDir, os.path.join(self.case_folder, 'constant', 'triSurface')) # shutil.copy2(cart_mesh.temp_file_blockMeshDict, os.path.join(self.case_folder,'system')) # shutil.copy2(cart_mesh.temp_file_snappyMeshDict, os.path.join(self.case_folder,'system')) # shutil.copy2(cart_mesh.temp_file_surfaceFeatureExtractDict, os.path.join(self.case_folder,'system')) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'system', 'blockMeshDict'), os.path.join(self.case_folder, 'system')) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'system', 'snappyHexMeshDict'), os.path.join(self.case_folder, 'system')) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'system', 'surfaceFeatureExtractDict'), os.path.join(self.case_folder, 'system')) shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'Allmesh'), self.case_folder) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'log.blockMesh'), self.case_folder) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'log.surfaceFeatureExtract'), self.case_folder) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'log.snappyHexMesh'), self.case_folder) elif self.mesh_obj.MeshUtility == "gmsh": print("Writing gmsh generated mesh\n") CfdTools.copyFilesRec( cart_mesh.polyMeshDir, os.path.join(self.case_folder, 'constant', 'polyMesh')) CfdTools.copyFilesRec( cart_mesh.triSurfaceDir, os.path.join(self.case_folder, 'constant', 'gmsh')) shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'Allmesh'), self.case_folder) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'log.gmshToFoam'), self.case_folder) if self.mesh_obj.ElementDimension == '2D': shutil.copy2( os.path.join(os.path.join(cart_mesh.meshCaseDir, 'system'), 'extrudeMeshDict'), os.path.join(self.case_folder, 'system')) shutil.copy2( os.path.join(cart_mesh.meshCaseDir, 'log.extrudeMesh'), self.case_folder) else: raise RuntimeError("Unrecognised mesh type")