Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
    def writeMesh(self):
        """ Convert or copy mesh files """
        if self.mesh_obj.Proxy.Type == "FemMeshGmsh":  # GMSH
            # Convert GMSH created UNV file to OpenFoam
            print("Writing GMSH")
            unvMeshFile = self.case_folder + os.path.sep + self.solver_obj.InputCaseName + u".unv"
            self.mesh_generated = CfdTools.write_unv_mesh(
                self.mesh_obj, self.bc_group, unvMeshFile)
            # FreeCAD always stores the CAD geometry in mm, while FOAM by default uses SI units. This is independent
            # of the user selected unit preferences.
            self.setupMesh(unvMeshFile, scale=0.001)
        elif self.mesh_obj.Proxy.Type == "CfdMeshCart":  # Cut-cell Cartesian
            import CfdCartTools
            ## Move Cartesian mesh files from temporary mesh directory to case directory
            if self.mesh_obj.MeshUtility == "cfMesh":
                print("Writing Cartesian mesh\n")
                #import CfdCartTools
                self.cart_mesh = CfdCartTools.CfdCartTools(self.mesh_obj)
                cart_mesh = self.cart_mesh
                # cart_mesh.get_tmp_file_paths("cfMesh")  # Update tmp file locations
                cart_mesh.get_tmp_file_paths()  # Update tmp file locations
                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")
                self.cart_mesh = CfdCartTools.CfdCartTools(self.mesh_obj)
                cart_mesh = self.cart_mesh
                # cart_mesh.get_tmp_file_paths("snappyHexMesh")  # Update tmp file locations
                cart_mesh.get_tmp_file_paths()  # Update tmp file locations
                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)
        else:
            raise RuntimeError("Unrecognised mesh type")