Skip to content

Commit

Permalink
Merge branch 'develop' into feature/add-srf-option
Browse files Browse the repository at this point in the history
# Conflicts:
#	Data/Templates/mesh/system/createPatchDict
  • Loading branch information
Jonathan Bergh committed Jul 29, 2022
2 parents 877d6a4 + fe4d7c1 commit fb741f3
Show file tree
Hide file tree
Showing 44 changed files with 587 additions and 312 deletions.
4 changes: 2 additions & 2 deletions CfdOF/CfdPreferencePage.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@

# Constants
OPENFOAM_URL = \
"https://sourceforge.net/projects/openfoam/files/v2012/OpenCFD-OpenFOAM-v2012-DP-mingw-crosscompiled-WindowsInstaller.exe/download"
"https://sourceforge.net/projects/openfoam/files/v2206/OpenFOAM-v2206-windows-mingw.exe/download"
OPENFOAM_FILE_EXT = ".exe"
PARAVIEW_URL = \
"https://www.paraview.org/paraview-downloads/download.php?submit=Download&version=v5.5&type=binary&os=Windows&downloadFile=ParaView-5.5.2-Qt5-Windows-64bit.exe"
"https://www.paraview.org/paraview-downloads/download.php?submit=Download&version=v5.10&type=binary&os=Windows&downloadFile=ParaView-5.10.1-Windows-Python3.9-msvc2017-AMD64.exe"
PARAVIEW_FILE_EXT = ".exe"
CFMESH_URL = \
"https://sourceforge.net/projects/cfmesh-cfdof/files/cfmesh-cfdof.zip/download"
Expand Down
16 changes: 11 additions & 5 deletions CfdOF/CfdTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ def makeRunCommand(cmd, dir, source_env=True):
if installation_path is None:
raise IOError("OpenFOAM installation directory not found")

FreeCAD.Console.PrintMessage('Executing: {} in {}\n'.format(cmd, dir))

source = ""
if source_env and len(installation_path):
env_setup_script = "{}/etc/bashrc".format(installation_path)
Expand Down Expand Up @@ -981,9 +983,9 @@ def checkCfdDependencies():
foam_ver = foam_ver.lstrip('v')
foam_ver = int(foam_ver.split('.')[0])
if getFoamRuntime() == "MinGW":
if foam_ver != 2012:
vermsg = "OpenFOAM version " + str(foam_ver) + " is not supported:\n" + \
"Only version 2012 supported for MinGW installation"
if foam_ver < 2012 or foam_ver > 2206:
vermsg = "OpenFOAM version " + str(foam_ver) + \
" is not currently supported with MinGW installation"
message += vermsg + "\n"
print(vermsg)
if foam_ver >= 1000: # Plus version
Expand All @@ -992,9 +994,9 @@ def checkCfdDependencies():
"Minimum version 1706 or 5 required"
message += vermsg + "\n"
print(vermsg)
if foam_ver > 2112:
if foam_ver > 2206:
vermsg = "OpenFOAM version " + str(foam_ver) + " is not yet supported:\n" + \
"Last tested version is 2112"
"Last tested version is 2206"
message += vermsg + "\n"
print(vermsg)
else: # Foundation version
Expand Down Expand Up @@ -1633,6 +1635,7 @@ def enableLayoutRows(layout, selected_rows):
if isinstance(item, QtGui.QWidgetItem):
item.widget().setVisible(selected_rows is None or rowi in selected_rows)


def clearCase(case_path, backup_path=None):
"""
Remove and recreate contents of the case directory, optionally backing up
Expand All @@ -1648,9 +1651,12 @@ def clearCase(case_path, backup_path=None):
else:
if entry.is_dir():
shutil.rmtree(entry.path)
else:
os.remove(entry.path)
else:
os.makedirs(case_path) # mkdir -p


def executeMacro(macro_name):
macro_contents = "import FreeCAD\nimport FreeCADGui\nimport FreeCAD as App\nimport FreeCADGui as Gui\n"
macro_contents += open(macro_name).read()
Expand Down
2 changes: 1 addition & 1 deletion CfdOF/Mesh/CfdMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def initProperties(self, obj):
"Name of directory in which the mesh is created")

# Setup and utility
addObjectProperty(obj, 'STLRelativeLinearDeflection', 1, "App::PropertyFloat", "Surface triangulation",
addObjectProperty(obj, 'STLRelativeLinearDeflection', 0.001, "App::PropertyFloat", "Surface triangulation",
"Maximum relative linear deflection for built-in surface triangulation")
addObjectProperty(obj, 'STLAngularMeshDensity', 100, "App::PropertyFloat", "Surface triangulation",
"Mesh elements per 360 degrees for surface triangulation with GMSH")
Expand Down
2 changes: 1 addition & 1 deletion CfdOF/Mesh/CfdMeshTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def processExtrusions(self):
raise RuntimeError("Extrusion patch for '{}' could not be found in the shape being meshed.".format(
extrusion_obj.Label))
this_extrusion_settings['FrontFaceList'] = tuple(efl)
this_extrusion_settings['BackFace'] = efl[0]+'_back'
this_extrusion_settings['BackFace'] = efl[0]

this_extrusion_settings['Distance'] = extrusion_obj.ExtrusionThickness.getValueAs('m')
this_extrusion_settings['Angle'] = extrusion_obj.ExtrusionAngle.getValueAs('deg')
Expand Down
2 changes: 0 additions & 2 deletions CfdOF/Mesh/TaskPanelCfdMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def checkMeshClicked(self):
FreeCADGui.doCommand("proxy.cart_mesh = cart_mesh")
FreeCADGui.doCommand("cart_mesh.error = False")
FreeCADGui.doCommand("cmd = CfdTools.makeRunCommand('checkMesh', cart_mesh.meshCaseDir)")
FreeCADGui.doCommand("FreeCAD.Console.PrintMessage('Executing: ' + ' '.join(cmd) + '\\n')")
FreeCADGui.doCommand("env_vars = CfdTools.getRunEnvironment()")
FreeCADGui.doCommand("proxy.running_from_macro = True")
self.mesh_obj.Proxy.running_from_macro = False
Expand Down Expand Up @@ -313,7 +312,6 @@ def runMesh(self):
FreeCADGui.doCommand("proxy.cart_mesh = cart_mesh")
FreeCADGui.doCommand("cart_mesh.error = False")
FreeCADGui.doCommand("cmd = CfdTools.makeRunCommand('./Allmesh', cart_mesh.meshCaseDir, source_env=False)")
FreeCADGui.doCommand("FreeCAD.Console.PrintMessage('Executing: ' + ' '.join(cmd) + '\\n')")
FreeCADGui.doCommand("env_vars = CfdTools.getRunEnvironment()")
FreeCADGui.doCommand("proxy.running_from_macro = True")
self.mesh_obj.Proxy.running_from_macro = False
Expand Down
14 changes: 3 additions & 11 deletions CfdOF/Solve/CfdCaseWriterFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ def writeCase(self):
self.processInitialisationZoneProperties()

if self.reporting_functions:
cfdMessage(f'Reporting functions present')
cfdMessage('Reporting functions present')
self.processReportingFunctions()

if self.scalar_transport_objs:
cfdMessage(f'Scalar transport functions present')
cfdMessage('Scalar transport functions present')
self.processScalarTransportFunctions()

if self.dynamic_mesh_refinement_obj:
cfdMessage(f'Dynamic mesh adaptation rule present')
cfdMessage('Dynamic mesh adaptation rule present')
self.processDynamicMeshRefinement()

self.settings['createPatchesFromSnappyBaffles'] = False
Expand Down Expand Up @@ -745,19 +745,11 @@ def setupPatchNames(self):
'PatchNamesList': '"patch_.*_'+str(mr_id+1)+'"',
'PatchType': "empty"
}
settings['createPatches'][mr_obj.Label+'BackFace'] = {
'PatchNamesList': '"patch_.*_'+str(mr_id+1)+'_back"',
'PatchType': "empty"
}
elif mr_obj.Extrusion and mr_obj.ExtrusionType == "2DWedge":
settings['createPatches'][mr_obj.Label] = {
'PatchNamesList': '"patch_.*_'+str(mr_id+1)+'"',
'PatchType': "symmetry"
}
settings['createPatches'][mr_obj.Label+'BackFace'] = {
'PatchNamesList': '"patch_.*_'+str(mr_id+1)+'_back"',
'PatchType': "symmetry"
}
else:
# Add others to default faces list
settings['createPatches']['defaultFaces']['PatchNamesList'] += ' "patch_0_'+str(mr_id+1) + '"'
5 changes: 2 additions & 3 deletions CfdOF/Solve/CfdRunnableFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def get_solver_cmd(self, case_dir):

# Environment is sourced in run script, so no need to include in run command
cmd = CfdTools.makeRunCommand('./Allrun', case_dir, source_env=False)
FreeCAD.Console.PrintMessage("Solver run command: " + ' '.join(cmd) + "\n")
return cmd

def getRunEnvironment(self):
Expand Down Expand Up @@ -273,9 +272,9 @@ def process_output(self, text):
# Force coefficient monitors
if self.in_forcecoeffs_section:
fc = self.force_coeffs[self.in_forcecoeffs_section]
if "Cd" in split and self.niter-1 > len(fc['cdCoeffs']):
if (("Cd" in split) or ("Cd:" in split)) and self.niter-1 > len(fc['cdCoeffs']):
fc['cdCoeffs'].append(float(split[2]))
if "Cl" in split and self.niter-1 > len(fc['clCoeffs']):
if (("Cl" in split) or ("Cl:" in split)) and self.niter-1 > len(fc['clCoeffs']):
fc['clCoeffs'].append(float(split[2]))

# Update plots
Expand Down
3 changes: 0 additions & 3 deletions CfdOF/Solve/TaskPanelCfdSolverControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ def runSolverProcess(self):

cart_mesh.error = False
cmd = CfdTools.makeRunCommand('./Allmesh', cart_mesh.meshCaseDir, source_env=False)
FreeCAD.Console.PrintMessage('Executing: ' + ' '.join(cmd) + '\\n')
env_vars = CfdTools.getRunEnvironment()
self.solver_object.Proxy.solver_process.start(cmd, env_vars=env_vars)
if self.solver_object.Proxy.solver_process.waitForStarted():
Expand Down Expand Up @@ -233,7 +232,6 @@ def runSolverProcess(self):
" import CfdRunnableFoam\n" +
" solver_runner = CfdRunnableFoam.CfdRunnableFoam(analysis_object, solver_object)\n" +
" cmd = solver_runner.get_solver_cmd(solver_directory)\n" +
" FreeCAD.Console.PrintMessage(' '.join(cmd) + '\\n')\n" +
" env_vars = solver_runner.getRunEnvironment()\n" +
" solver_process = CfdConsoleProcess.CfdConsoleProcess(stdout_hook=solver_runner.process_output)\n" +
" solver_process.start(cmd, env_vars=env_vars)\n" +
Expand All @@ -242,7 +240,6 @@ def runSolverProcess(self):
case_name = self.solver_object.InputCaseName
solver_directory = os.path.abspath(os.path.join(working_dir, case_name))
cmd = self.solver_runner.get_solver_cmd(solver_directory)
FreeCAD.Console.PrintMessage(' '.join(cmd) + '\\n')
env_vars = self.solver_runner.getRunEnvironment()
self.solver_object.Proxy.solver_process = CfdConsoleProcess(finished_hook=self.solverFinished,
stdout_hook=self.gotOutputLines,
Expand Down
36 changes: 26 additions & 10 deletions Data/Templates/case/Allrun
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/bin/bash

runParallel()
{
nproc="$1"
shift
exe="$(which $1)"
sol=$(basename -- "$1")
sol="${sol%.*}"
shift
if [ -f log."$sol" ]; then rm log."$sol"; fi
mpiexec -np $nproc "$exe" -parallel "$@" 1> >(tee -a log."$sol") 2> >(tee -a log."$sol" >&2)
err=$?
if [ ! $err -eq 0 ]; then exit $err; fi
}

runCommand()
{
if [ "$1" == "mpiexec" ]; then sol="$4"; else sol="$1"; fi
sol=$(basename -- "$sol")
sol=$(basename -- "$1")
sol="${sol%.*}"
if [ -f log."$sol" ]; then rm log."$sol"; fi
"$@" 1> >(tee -a log."$sol") 2> >(tee -a log."$sol" >&2)
Expand All @@ -26,7 +39,7 @@ fi
MESHDIR="%(meshDir%)"
if [ -f "$MESHDIR"/constant/polyMesh/faces ]
then
rm -r constant/polyMesh 2> /dev/null
rm -rf constant/polyMesh
cp -r "$MESHDIR"/constant/polyMesh constant/polyMesh
elif [ ! -f constant/polyMesh/faces ]
then
Expand Down Expand Up @@ -90,33 +103,36 @@ PNAME=p
# Parallel decomposition
runCommand decomposePar -force

# Pick up number of parallel processes
NPROC=$(foamDictionary -entry "numberOfSubdomains" -value system/decomposeParDict)

# Mesh renumbering
runCommand mpiexec -np %(solver/ParallelCores%) renumberMesh -parallel -overwrite
runParallel $NPROC renumberMesh -overwrite

%{%(initialValues/PotentialFlow%)
%:True
# Initialise flow
%{%(bafflesPresent%)
%:True
# Baffle BC does not work with potentialFoam; do not initialise p
runCommand mpiexec -np %(solver/ParallelCores%) potentialFoam -parallel -initialiseUBCs -pName $PNAME
runParallel $NPROC potentialFoam -initialiseUBCs -pName $PNAME
%:default
%{%(initialValues/PotentialFlowP%)
%:True
runCommand mpiexec -np %(solver/ParallelCores%) potentialFoam -parallel -initialiseUBCs -pName $PNAME -writep
runParallel $NPROC potentialFoam -initialiseUBCs -pName $PNAME -writep
%:default
runCommand mpiexec -np %(solver/ParallelCores%) potentialFoam -parallel -initialiseUBCs -pName $PNAME
runParallel $NPROC potentialFoam -initialiseUBCs -pName $PNAME
%}
%}
%{%(solver/SolverName%)
%:buoyantSimpleFoam buoyantPimpleFoam interFoam multiphaseInterFoam
# Remove phi with wrong units
rm processor*/0/phi
rm -f processor*/0/phi
%}

%}
# Run application in parallel
runCommand mpiexec -np %(solver/ParallelCores%) %(solver/SolverName%) -parallel
runParallel $NPROC %(solver/SolverName%)
%:False
# Mesh renumbering
runCommand renumberMesh -overwrite
Expand All @@ -139,7 +155,7 @@ runCommand potentialFoam -initialiseUBCs -pName $PNAME
%{%(solver/SolverName%)
%:buoyantSimpleFoam buoyantPimpleFoam interFoam multiphaseInterFoam
# Remove phi with wrong units
rm 0/phi
rm -f 0/phi
%}

%}
Expand Down
35 changes: 23 additions & 12 deletions Data/Templates/case/pvScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')

# get color transfer function/color map for 'p'
ULUT = GetColorTransferFunction('U')
# reset view to fit data
renderView1.ResetCamera()

# create a new 'Clean to Grid'
cleantoGrid1 = CleantoGrid(Input=pfoam)

# show data in view
pfoamDisplay = Show(pfoam, renderView1)
# trace defaults for the display properties.
pfoamDisplay.ColorArrayName = ['POINTS', 'U']
pfoamDisplay.LookupTable = ULUT
pfoamDisplay.EdgeColor = [0.0, 0.0, 0.5]
pfoamDisplay.ScalarOpacityUnitDistance = 0.05
cleantoGrid1Display = Show(cleantoGrid1, renderView1)

# reset view to fit data
renderView1.ResetCamera()
# hide data in view
Hide(pfoam, renderView1)

# get color transfer function/color map for 'U'
ULUT = GetColorTransferFunction('U')

# trace defaults for the display properties.
cleantoGrid1Display.ColorArrayName = ['POINTS', 'U']
cleantoGrid1Display.LookupTable = ULUT
cleantoGrid1Display.EdgeColor = [0.0, 0.0, 0.5]
cleantoGrid1Display.ScalarOpacityUnitDistance = 0.05

# get animation scene
animationScene1 = GetAnimationScene()
Expand All @@ -42,7 +49,11 @@
animationScene1.AnimationTime = finalTime

# rescale color and/or opacity maps used to exactly fit the current data range
pfoamDisplay.RescaleTransferFunctionToDataRange(False, True)
cleantoGrid1Display.RescaleTransferFunctionToDataRange(False, True)

# update the view to ensure updated data information
renderView1.Update()
renderView1.Update()

# reset view to fit data
renderView1.ResetCamera(False)

2 changes: 1 addition & 1 deletion Data/Templates/case/system/fvSchemes
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ divSchemes
%{%(physics/Turbulence%)
%:DES LES
div(phi,U) Gauss LUST grad(U);
div(phi,h) Gauss LUST grad(U);
div(phi,h) Gauss LUST grad(h);
div(phi,K) Gauss LUST grad(K);
%:default
div(phi,U) Gauss linearUpwindV grad(U);
Expand Down

0 comments on commit fb741f3

Please sign in to comment.