def getRunEnvironment(): """ Return native environment settings necessary for running on relevant platform """ if getFoamRuntime() == "BashWSL": return {} elif getFoamRuntime() == "BlueCFD": return {"MSYSTEM": "MINGW64", "USERNAME": "******", "USER": "******", "HOME": "/home/ofuser"} else: return {}
def checkCfdDependencies(term_print=True): import os import subprocess import platform message = "" # check openfoam if term_print: print("Checking for OpenFOAM:") try: foam_dir = getFoamDir() except IOError as e: ofmsg = "Could not find OpenFOAM installation: " + e.message if term_print: print(ofmsg) message += ofmsg + '\n' else: if not foam_dir: ofmsg = "OpenFOAM installation path not set and OpenFOAM environment neither pre-loaded before " + \ "running FreeCAD nor detected in standard locations" if term_print: print(ofmsg) message += ofmsg + '\n' else: try: foam_ver = runFoamCommand("echo $WM_PROJECT_VERSION") except Exception as e: runmsg = "OpenFOAM installation found, but unable to run command: " + e.message message += runmsg + '\n' if term_print: print(runmsg) else: foam_ver = foam_ver.rstrip().split('\n')[-1] if int(foam_ver.split('.')[0]) < 4: vermsg = "OpenFOAM version " + foam_ver + " pre-loaded is outdated: " \ + "The CFD workbench requires at least OpenFOAM 4.0" message += vermsg + "\n" if term_print: print(vermsg) else: # Check for cfMesh try: runFoamCommand("cartesianMesh -help") except subprocess.CalledProcessError: cfmesh_msg = "cfMesh not found" message += cfmesh_msg + '\n' if term_print: print(cfmesh_msg) # check for gnuplot python module, this can be removed now, since plotting is done by matplotlib if term_print: print("Checking for gnuplot:") try: import Gnuplot except ImportError: gnuplotpy_msg = "gnuplot python module not installed" message += gnuplotpy_msg + '\n' if term_print: print(gnuplotpy_msg) gnuplot_cmd = "gnuplot" # For blueCFD, use the supplied Gnuplot if getFoamRuntime() == 'BlueCFD': gnuplot_cmd = '{}\\..\\AddOns\\gnuplot\\bin\\gnuplot.exe'.format(getFoamDir()) # Otherwise, the command must be in the path - test to see if it exists import distutils.spawn if distutils.spawn.find_executable(gnuplot_cmd) is None: gnuplot_msg = "Gnuplot executable " + gnuplot_cmd + " not found in path." message += gnuplot_msg + '\n' if term_print: print(gnuplot_msg) if term_print: print("Checking for gmsh:") # check that gmsh version 2.13 or greater is installed gmshversion = "" try: gmshversion = subprocess.check_output(["gmsh", "-version"], stderr=subprocess.STDOUT) except subprocess.CalledProcessError: gmsh_msg = "gmsh is not installed" message += gmsh_msg + '\n' if term_print: print(gmsh_msg) if len(gmshversion) > 1: # Only the last line contains gmsh version number gmshversion = gmshversion.rstrip().split() gmshversion = gmshversion[-1] versionlist = gmshversion.split(".") if int(versionlist[0]) < 2 or (int(versionlist[0]) == 2 and int(versionlist[1]) < 13): gmsh_ver_msg = "gmsh version is older than minimum required (2.13)" message += gmsh_ver_msg + '\n' if term_print: print(gmsh_ver_msg) paraview_cmd = "paraview" # If using blueCFD, use paraview supplied if getFoamRuntime() == 'BlueCFD': paraview_cmd = '{}\\..\\AddOns\\ParaView\\bin\\paraview.exe'.format(getFoamDir()) # Otherwise, the command 'paraview' must be in the path - test to see if it exists import distutils.spawn if distutils.spawn.find_executable(paraview_cmd) is None: pv_msg = "Paraview executable " + paraview_cmd + " not found in path." message += pv_msg + '\n' if term_print: print(pv_msg) if term_print: print("Completed CFD dependency check") return message