def getIcon(self): if self.Object.Name.startswith('PorousZone'): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "porous.png") else: icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "alpha.png") return icon_path
def __init__(self): import os import CfdTools icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "cfd.png") self.__class__.Icon = icon_path self.__class__.MenuText = "CFDFoam" self.__class__.ToolTip = "CFD workbench" from PySide import QtCore from CfdPreferencePage import CfdPreferencePage ICONS_PATH = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons") QtCore.QDir.addSearchPath("icons", ICONS_PATH) FreeCADGui.addPreferencePage(CfdPreferencePage, "CFD")
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "boundary.png") return { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_FluidBoundary", "Fluid boundary"), 'Accel': "C, W", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_FluidBoundary", "Creates a CFD fluid boundary")}
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "alpha.svg") return {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_InitialisationZone", "Initialisation zone"), 'Accel': "", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_InitialisationZone", "Select and create an initialisation zone")}
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "material.png") return { 'Pixmap': icon_path, 'MenuText': 'Add fluid properties', 'ToolTip': 'Add fluid properties' }
def threadFinished(self, status): if self.thread.task == DOWNLOAD_CFMESH: if status: self.consoleMessage("Download completed") user_dir = self.thread.user_dir self.consoleMessage( "Building cfMesh. Lengthy process - please wait...") if CfdTools.getFoamRuntime() == "BlueCFD": script_name = "buildCfMeshOnBlueCFD.sh" self.consoleMessage("Log file: {}\\log.{}".format( user_dir, script_name)) TemplateBuilder.TemplateBuilder( user_dir, os.path.join(CfdTools.get_module_path(), 'data', 'foamUserDir'), {'cfMeshDirectory': CFMESH_FILE_BASE}) self.install_process = CfdTools.startFoamApplication( "./" + script_name, "$WM_PROJECT_USER_DIR", self.installFinished) else: self.consoleMessage("Log file: {}/{}/log.Allwmake".format( user_dir, CFMESH_FILE_BASE)) self.install_process = CfdTools.startFoamApplication( "./Allwmake", "$WM_PROJECT_USER_DIR/" + CFMESH_FILE_BASE, self.installFinished) # Reset foam dir for now in case the user presses 'Cancel' CfdTools.setFoamDir(self.initial_foam_dir) else: self.consoleMessage("Download unsuccessful") self.thread = None
def threadFinished(self, status): if self.thread.task == DEPENDENCY_CHECK: QApplication.restoreOverrideCursor() elif self.thread.task == DOWNLOAD_CFMESH: if status: self.consoleMessage("Download completed") user_dir = self.thread.user_dir self.consoleMessage( "Building cfMesh. Lengthy process - please wait...") if CfdTools.getFoamRuntime() == "BlueCFD": script_name = "buildCfMeshOnBlueCFD.sh" self.consoleMessage("Log file: {}\\log.{}".format( user_dir, script_name)) shutil.copy( os.path.join(CfdTools.get_module_path(), 'data', script_name), os.path.join(user_dir, script_name)) self.install_process = CfdTools.startFoamApplication( "./" + script_name, "$WM_PROJECT_USER_DIR", self.installFinished) else: self.consoleMessage("Log file: {}/{}/log.Allwmake".format( user_dir, CFMESH_FILE_BASE)) self.install_process = CfdTools.startFoamApplication( "./Allwmake", "$WM_PROJECT_USER_DIR/" + CFMESH_FILE_BASE, self.installFinished) else: self.consoleMessage("Download unsuccessful")
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "mesh.png") return {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshFromShape", "CFD mesh"), 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshFromShape", "Create a mesh using cfMesh, snappyHexMesh or gmsh")}
def get_tmp_file_paths(self, typeCart): tmpdir = tempfile.gettempdir() self.meshCaseDir = os.path.join(tmpdir, 'meshCase') self.constantDir = os.path.join(self.meshCaseDir, 'constant') if typeCart == "cfMesh": self.polyMeshDir = os.path.join(self.constantDir, 'polyMesh') elif typeCart == "snappyHexMesh": # surfaceTOPatch does not have an overwrite functionality. It therefore will always create a new time step # folder. However, if there is no changes to be made to the boundary then this time folder is not created. polyMeshDir = os.path.join(self.meshCaseDir, '1', 'polyMesh') if os.path.isfile(polyMeshDir): self.polyMeshDir = polyMeshDir else: self.polyMeshDir = os.path.join(self.constantDir, 'polyMesh') self.triSurfaceDir = os.path.join(self.constantDir, 'triSurface') self.systemDir = os.path.join(self.meshCaseDir, 'system') self.templatePath = os.path.join(CfdTools.get_module_path(), "data", "defaults") self.temp_file_geo = os.path.join(self.constantDir, 'triSurface', self.part_obj.Name + '_Geometry') # Rename self.temp_file_meshDict = os.path.join(self.systemDir, 'meshDict') self.temp_file_blockMeshDict = os.path.join(self.systemDir, 'blockMeshDict') self.temp_file_snappyMeshDict = os.path.join(self.systemDir, 'snappyHexMeshDict') self.temp_file_surfaceFeatureExtractDict = os.path.join( self.systemDir, 'surfaceFeatureExtractDict')
def __init__(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "3d-to-2d.png") self.resources = { 'Pixmap': icon_path, 'MenuText': 'Convert 3D mesh into a 2D OpenFOAM mesh', 'ToolTip': 'Convert 3D mesh into a 2D OpenFOAM mesh' } self.is_active = 'with_femmesh'
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "initialise.png") return {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_InitialiseInternal", "Initialise"), 'Accel': "", 'ToolTip': QtCore.QT_TRANSLATE_NOOP( "Cfd_InitialiseInternal", "Initialise internal flow variables based on the selected physics model")}
def __init__(self): super(_CommandCfdPhysicsSelection, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(),"Gui","Resources","icons","physics.png") self.resources = {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_PhysicsModel", "Select models"), 'Accel': "", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_PhysicsModel", "Select the physics model")} self.is_active = 'with_analysis'
def __init__(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "material.png") self.resources = { 'Pixmap': icon_path, 'MenuText': 'Add fluid properties', 'ToolTip': 'Add fluid properties' } self.is_active = 'with_analysis' # Only activate when analysis is active
def __init__(self): super(_CommandMeshRegion, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "meshRegion.png") self.resources = {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_MeshRegion", "Mesh region"), 'Accel': "M, R", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_MeshRegion", "Creates a mesh region")} self.is_active = 'with_femmesh'
def __init__(self): super(_CommandCfdSolverControl, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(),"Gui","Resources","icons","solver.png") self.resources = {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_SolverControl", "Solver job control"), 'Accel': "S, C", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_SolverControl", "Edit properties and run solver")} # self.is_active = 'with_solver' self.is_active = 'with_analysis'
def __init__(self): super(_CommandCfdAnalysis, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "cfd_analysis.png") self.resources = \ {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_Analysis", "Analysis container"), 'Accel': "N, C", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_Analysis", "Creates an analysis container with a CFD solver")} self.is_active = 'with_document'
def __init__(self): super(_CommandCfdMeshCartFromShape, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "mesh_c.png") self.resources = {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshCartFromShape", "Cut-cell Cartesian mesh from shape"), 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshCartFromShape", "Create a Cut-cell Cartesian mesh from a shape")} self.is_active = 'with_part_feature'
def __init__(self): super(_CommandCfdInitialiseInternalFlowField, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "initialise.png") self.resources = {'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_InitialiseInternal", "Initialise"), 'Accel': "", 'ToolTip': QtCore.QT_TRANSLATE_NOOP( "Cfd_InitialiseInternal", "Initialise internal flow variables based on the selected physics model")} self.is_active = 'with_analysis'
def import_materials(self): import CfdTools self.materials = {} self.pathList = [] self.form.PredefinedMaterialLibraryComboBox.clear() ''' Until module is integrated, store the defaults inside the module directory rather than the resource dir ''' # system_mat_dir = FreeCAD.getResourceDir() + "/Mod/Material/FluidMaterialProperties" system_mat_dir = os.path.join(CfdTools.get_module_path(), "data/CfdFluidMaterialProperties") self.add_mat_dir(system_mat_dir, ":/icons/freecad.svg")
def threadFinished(self, status): if self.thread.task == DEPENDENCY_CHECK: QApplication.restoreOverrideCursor() elif self.thread.task == DOWNLOAD_GNUPLOTPY: self.consoleMessage("Attempting to install Gnuplot-py package:") if platform.system() == 'Windows': python_exe = os.path.join(FreeCAD.getHomePath(), 'bin', 'python.exe') else: python_exe = 'python' cmd = [python_exe, '-u', 'setup.py', 'install'] working_dir = os.path.join(tempfile.gettempdir(), GNUPLOTPY_FILE_BASE) self.install_process = CfdConsoleProcess.CfdConsoleProcess( finishedHook=self.installFinished) print("Running {} in {}".format(' '.join(cmd), working_dir)) self.install_process.start(cmd, working_dir=working_dir) if not self.install_process.waitForStarted(): self.consoleMessage("Unable to run command " + ' '.join(cmd), '#FF0000') elif self.thread.task == DOWNLOAD_CFMESH: if status: self.consoleMessage("Download completed") user_dir = self.thread.user_dir self.consoleMessage( "Building cfMesh. Lengthy process - please wait...") if CfdTools.getFoamRuntime() == "BlueCFD": script_name = "buildCfMeshOnBlueCFD.sh" self.consoleMessage("Log file: {}\\log.{}".format( user_dir, script_name)) shutil.copy( os.path.join(CfdTools.get_module_path(), 'data', script_name), os.path.join(user_dir, script_name)) self.install_process = CfdTools.startFoamApplication( "./" + script_name, "$WM_PROJECT_USER_DIR", self.installFinished) else: self.consoleMessage("Log file: {}/{}/log.Allwmake".format( user_dir, CFMESH_FILE_BASE)) self.install_process = CfdTools.startFoamApplication( "./Allwmake", "$WM_PROJECT_USER_DIR/" + CFMESH_FILE_BASE, self.installFinished) else: self.consoleMessage("Download unsuccessful")
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Resources", "icons", "cfd-foam-boundary.svg") return { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_FluidBoundary", "fluid boundary"), 'Accel': "C, F", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_FluidBoundary", "Creates boundary condition for CFD") }
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "porous.png") return { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_PorousZone", "Porous zone"), 'Accel': "", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_PorousZone", "Select and create a porous zone") }
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "physics.png") return { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_PhysicsModel", "Select models"), 'Accel': "", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_PhysicsModel", "Select the physics model") }
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "meshRegion.png") return { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshRegion", "Mesh refinement"), 'Accel': "M, R", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshRegion", "Creates a mesh refinement") }
def __init__(self): super(_CommandCfdMeshGmshFromShape, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "mesh_g.png") self.resources = { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshGmshFromShape", "Tetrahedral meshing using GMSH"), 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshGmshFromShape", "Create a tetrahedral mesh using GMSH") } self.is_active = 'with_part_feature'
def __init__(self): super(_CommandCfdMeshFromShape, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "mesh.png") self.resources = { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_MeshFromShape", "CFD mesh"), 'ToolTip': QtCore.QT_TRANSLATE_NOOP( "Cfd_MeshFromShape", "Create a mesh using cfMesh, snappyHexMesh or gmsh") } self.is_active = 'with_part_feature'
def GetResources(self): icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "solver.png") return { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_SolverControl", "Solver job control"), 'Accel': "S, C", 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Cfd_SolverControl", "Edit properties and run solver") }
def __init__(self): super(_CommandCfdAlphaZone, self).__init__() icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "alpha.png") self.resources = { 'Pixmap': icon_path, 'MenuText': QtCore.QT_TRANSLATE_NOOP("Cfd_AlphaZone", "Phase fraction zone"), 'Accel': "", 'ToolTip': QtCore.QT_TRANSLATE_NOOP( "Cfd_AlphaZone", "Select and create a phase fraction zone") } self.is_active = 'with_analysis'
def writeMeshCase(self): """ Collect case settings, and finally build a runnable case. """ CfdTools.cfdMessage( "Populating mesh dictionaries in folder {}\n".format( self.meshCaseDir)) if self.mesh_obj.MeshUtility == "cfMesh": self.cf_settings['ClMax'] = self.clmax * self.scale if len(self.cf_settings['BoundaryLayers']) > 0: self.cf_settings['BoundaryLayerPresent'] = True else: self.cf_settings['BoundaryLayerPresent'] = False if len(self.cf_settings["InternalRegions"]) > 0: self.cf_settings['InternalRefinementRegionsPresent'] = True else: self.cf_settings['InternalRefinementRegionsPresent'] = False elif self.mesh_obj.MeshUtility == "snappyHexMesh": bound_box = self.part_obj.Shape.BoundBox bC = 5 # Number of background mesh buffer cells x_min = (bound_box.XMin - bC * self.clmax) * self.scale x_max = (bound_box.XMax + bC * self.clmax) * self.scale y_min = (bound_box.YMin - bC * self.clmax) * self.scale y_max = (bound_box.YMax + bC * self.clmax) * self.scale z_min = (bound_box.ZMin - bC * self.clmax) * self.scale z_max = (bound_box.ZMax + bC * self.clmax) * self.scale cells_x = int(math.ceil(bound_box.XLength / self.clmax) + 2 * bC) cells_y = int(math.ceil(bound_box.YLength / self.clmax) + 2 * bC) cells_z = int(math.ceil(bound_box.ZLength / self.clmax) + 2 * bC) snappy_settings = self.snappy_settings snappy_settings['BlockMesh'] = { "xMin": x_min, "xMax": x_max, "yMin": y_min, "yMax": y_max, "zMin": z_min, "zMax": z_max, "cellsX": cells_x, "cellsY": cells_y, "cellsZ": cells_z } inside_x = Units.Quantity( self.mesh_obj.PointInMesh.get('x')).Value * self.scale inside_y = Units.Quantity( self.mesh_obj.PointInMesh.get('y')).Value * self.scale inside_z = Units.Quantity( self.mesh_obj.PointInMesh.get('z')).Value * self.scale shape_face_names_list = [] for i in self.mesh_obj.ShapeFaceNames: shape_face_names_list.append(i) snappy_settings['ShapeFaceNames'] = tuple(shape_face_names_list) snappy_settings[ 'EdgeRefinementLevel'] = CfdTools.relLenToRefinementLevel( self.mesh_obj.EdgeRefinement) snappy_settings['PointInMesh'] = { "x": inside_x, "y": inside_y, "z": inside_z } snappy_settings[ 'CellsBetweenLevels'] = self.mesh_obj.CellsBetweenLevels if len(self.snappy_settings["InternalRegions"]) > 0: self.snappy_settings['InternalRefinementRegionsPresent'] = True else: self.snappy_settings[ 'InternalRefinementRegionsPresent'] = False elif self.mesh_obj.MeshUtility == "gmsh": if platform.system() == "Windows": exe = os.path.join(FreeCAD.getHomePath(), 'bin', 'gmsh.exe') else: exe = subprocess.check_output( ["which", "gmsh"], universal_newlines=True).rstrip('\n') self.gmsh_settings['Executable'] = CfdTools.translatePath(exe) self.gmsh_settings['ShapeFile'] = self.temp_file_shape self.gmsh_settings['HasLengthMap'] = False if self.ele_length_map: self.gmsh_settings['HasLengthMap'] = True self.gmsh_settings['LengthMap'] = self.ele_length_map self.gmsh_settings['NodeMap'] = {} for e in self.ele_length_map: ele_nodes = (''.join( (str(n + 1) + ', ') for n in self.ele_node_map[e])).rstrip(', ') self.gmsh_settings['NodeMap'][e] = ele_nodes self.gmsh_settings['ClMax'] = self.clmax self.gmsh_settings['ClMin'] = self.clmin sols = (''.join( (str(n + 1) + ', ') for n in range(len(self.mesh_obj.Part.Shape.Solids))) ).rstrip(', ') self.gmsh_settings['Solids'] = sols self.gmsh_settings['BoundaryFaceMap'] = {} # Write one boundary per face for i in range(len(self.mesh_obj.Part.Shape.Faces)): self.gmsh_settings['BoundaryFaceMap']['face' + str(i)] = i + 1 self.gmsh_settings['MeshFile'] = self.temp_file_mesh # Perform initialisation here rather than __init__ in case of path changes self.template_path = os.path.join(CfdTools.get_module_path(), "data", "defaultsMesh") mesh_region_present = False if self.mesh_obj.MeshUtility == "cfMesh" and len(self.cf_settings['MeshRegions']) > 0 or \ self.mesh_obj.MeshUtility == "snappyHexMesh" and len(self.snappy_settings['MeshRegions']) > 0: mesh_region_present = True self.settings = { 'Name': self.part_obj.Name, 'MeshPath': self.meshCaseDir, 'FoamRuntime': CfdTools.getFoamRuntime(), 'MeshUtility': self.mesh_obj.MeshUtility, 'MeshRegionPresent': mesh_region_present, 'CfSettings': self.cf_settings, 'SnappySettings': self.snappy_settings, 'GmshSettings': self.gmsh_settings, 'TwoDSettings': self.two_d_settings } if CfdTools.getFoamRuntime() != 'WindowsDocker': self.settings['TranslatedFoamPath'] = CfdTools.translatePath( CfdTools.getFoamDir()) if self.mesh_obj.NumberOfProcesses <= 1: self.mesh_obj.NumberOfProcesses = 1 self.settings['ParallelMesh'] = False else: self.settings['ParallelMesh'] = True self.settings['NumberOfProcesses'] = self.mesh_obj.NumberOfProcesses self.settings['NumberOfThreads'] = self.mesh_obj.NumberOfThreads TemplateBuilder.TemplateBuilder(self.meshCaseDir, self.template_path, self.settings) # Update Allmesh permission - will fail silently on Windows fname = os.path.join(self.meshCaseDir, "Allmesh") import stat s = os.stat(fname) os.chmod(fname, s.st_mode | stat.S_IEXEC) CfdTools.cfdMessage( "Successfully wrote meshCase to folder {}\n".format( self.meshCaseDir))
# *************************************************************************** # * # CFD WB unit tests * # * # Until included in Test Framework run the test in FreeCAD console: * # * # >>> import TestCfd * # >>> TestCfd.runCfdUnitTests() * # * # Current tests: * # * # * block - steady, incompressible flow * # * # *************************************************************************** home_path = CfdTools.get_module_path() temp_dir = tempfile.gettempdir() test_file_dir = os.path.join(home_path, 'testFiles') working_dir = '' if os.path.exists('/tmp/'): working_dir = '/tmp/' # Must exist for POSIX system. elif tempfile.tempdir: working_dir = tempfile.tempdir def fccPrint(message): FreeCAD.Console.PrintMessage('{} \n'.format(message)) class BlockTest(unittest.TestCase): __doc_name = 'block'