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:
#	_TaskPanelCfdFluidBoundary.py
#	_TaskPanelCfdPhysicsSelection.py
  • Loading branch information
Jonathan Bergh committed May 12, 2022
2 parents b61b5b8 + 4e6f741 commit 5e1ce41
Show file tree
Hide file tree
Showing 35 changed files with 1,461 additions and 1,409 deletions.
20 changes: 17 additions & 3 deletions CfdAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# * Copyright (c) 2017 Johan Heyns (CSIR) <jheyns@csir.co.za> *
# * Copyright (c) 2017 Oliver Oxtoby (CSIR) <ooxtoby@csir.co.za> *
# * Copyright (c) 2017 Alfred Bogaers (CSIR) <abogaers@csir.co.za> *
# * Copyright (c) 2019 Oliver Oxtoby <oliveroxtoby@gmail.com> *
# * Copyright (c) 2019-2022 Oliver Oxtoby <oliveroxtoby@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
Expand Down Expand Up @@ -48,17 +48,26 @@ class _CfdAnalysis:
def __init__(self, obj):
obj.Proxy = self
self.Type = "CfdAnalysis"
self.loading = False
self.initProperties(obj)

def initProperties(self, obj):
addObjectProperty(obj, "OutputPath", "", "App::PropertyPath", "",
"Path to which cases are written (blank to use system default)")
addObjectProperty(obj, "IsActiveAnalysis", False, "App::PropertyBool", "", "Active analysis object in document")
obj.setEditorMode("IsActiveAnalysis", 1) # Make read-only (2 = hidden)
addObjectProperty(obj, 'NeedsMeshRewrite', True, "App::PropertyBool", "", "Mesh setup needs to be re-written")
addObjectProperty(obj, 'NeedsCaseRewrite', True, "App::PropertyBool", "", "Case setup needs to be re-written")
addObjectProperty(obj, 'NeedsMeshRerun', True, "App::PropertyBool", "", "Mesher needs to be re-run before running solver")

def onDocumentRestored(self, obj):
self.loading = False
self.initProperties(obj)

def __setstate__(self, state_dict):
self.__dict__ = state_dict
# Set while we are loading from file
self.loading = True

class _CommandCfdAnalysis:
""" The Cfd_Analysis command definition """
Expand Down Expand Up @@ -113,10 +122,15 @@ def getIcon(self):
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
self.bubbles = None

def updateData(self, obj, prop):
return
if not obj.Proxy.loading:
if prop == 'OutputPath':
obj.NeedsMeshRewrite = True
obj.NeedsCaseRewrite = True
elif prop == 'Group':
# Something was added or deleted
obj.NeedsCaseRewrite = True

def onChanged(self, vobj, prop):
self.makePartTransparent(vobj)
Expand Down
25 changes: 8 additions & 17 deletions CfdCaseWriterFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,6 @@ def processInitialConditions(self):
if initial_values['BoundaryTurb']:
inlet_bc = settings['boundaries'][initial_values['BoundaryTurb'].Label]

# Initialise everything to zero to start with.
initial_values['k'] = 0
initial_values['omega'] = 0
initial_values['epsilon'] = 0
initial_values['nuTilda'] = 0
initial_values['gammaInt'] = 0
initial_values['ReThetat'] = 0
initial_values['nut'] = 0
initial_values['kEqnk'] = 0
initial_values['kEqnNut'] = 0

if inlet_bc['TurbulenceInletSpecification'] == 'TKEAndSpecDissipationRate':
initial_values['k'] = inlet_bc['TurbulentKineticEnergy']
initial_values['omega'] = inlet_bc['SpecificDissipationRate']
Expand Down Expand Up @@ -546,6 +535,7 @@ def processInitialConditions(self):
"Turbulence inlet specification currently unsupported for copying turbulence initial conditions")
else:
raise RuntimeError("No boundary selected to copy initial turbulence values from.")
#TODO: Check that the required values have actually been set for each turbulent model

# Function objects (reporting functions, probes)
def processReportingFunctions(self):
Expand All @@ -572,13 +562,14 @@ def processReportingFunctions(self):

def processScalarTransportFunctions(self):
settings = self.settings
# Copy keys so that we can delete while iterating
settings['scalarTransportFunctionsEnabled'] = True
tf_name = list(settings['scalarTransportFunctions'].keys())

for name in tf_name:
settings['scalarTransportFunctions'][name]['InjectionPoint'] = \
tuple(p for p in settings['scalarTransportFunctions'][name]['InjectionPoint'])
for name in settings['scalarTransportFunctions']:
stf = settings['scalarTransportFunctions'][name]
if settings['solver']['SolverName'] in ['simpleFoam', 'porousSimpleFoam', 'pimpleFoam']:
stf['InjectionRate'] = stf['InjectionRate']/settings['fluidProperties'][0]['Density']
stf['DiffusivityFixedValue'] = stf['DiffusivityFixedValue']/settings['fluidProperties'][0]['Density']
stf['InjectionPoint'] = tuple(
Units.Quantity(p, Units.Length).getValueAs('m') for p in stf['InjectionPoint'])

# Mesh related
def processDynamicMeshRefinement(self):
Expand Down
40 changes: 25 additions & 15 deletions CfdFluidBoundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ def execute(self, obj):
""" Create compound part at recompute. """
shape = CfdTools.makeShapeFromReferences(obj.ShapeRefs, False)
if shape is None:
obj.Shape = Part.Shape()
else:
shape = Part.Shape()
if shape != obj.Shape:
obj.Shape = shape
self.updateBoundaryColors(obj)

Expand Down Expand Up @@ -448,23 +448,22 @@ def getDisplayModes(self, obj):
def getDefaultDisplayMode(self):
return "Shaded"

def setDisplayMode(self,mode):
def setDisplayMode(self, mode):
return mode

def updateData(self, obj, prop):
return
analysis_obj = CfdTools.getParentAnalysisObject(obj)
if prop == 'ShapeRefs' or prop == 'Shape':
# Only a change to the shape allocation or geometry affects mesh
if analysis_obj and not analysis_obj.Proxy.loading:
analysis_obj.NeedsMeshRewrite = True
else:
# Else mark case itself as needing updating
if analysis_obj and not analysis_obj.Proxy.loading:
analysis_obj.NeedsCaseRewrite = True

def onChanged(self, vobj, prop):
CfdTools.setCompSolid(vobj)
return

def doubleClicked(self, vobj):
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Task dialog already active\n')
return True

def setEdit(self, vobj, mode):
analysis_object = CfdTools.getParentAnalysisObject(self.Object)
Expand All @@ -477,6 +476,7 @@ def setEdit(self, vobj, mode):
return False
material_objs = CfdTools.getMaterials(analysis_object)

import _TaskPanelCfdFluidBoundary
import importlib
importlib.reload(_TaskPanelCfdFluidBoundary)
self.taskd = _TaskPanelCfdFluidBoundary.TaskPanelCfdFluidBoundary(self.Object, physics_model, material_objs)
Expand All @@ -485,10 +485,20 @@ def setEdit(self, vobj, mode):
FreeCADGui.Control.showDialog(self.taskd)
return True

def doubleClicked(self, vobj):
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Task dialog already active\n')
FreeCADGui.Control.showDialog(self.taskd)
return True

def unsetEdit(self, vobj, mode):
if self.taskd:
self.taskd.closing()
self.taskd = None
FreeCADGui.Control.closeDialog()
self.taskd = None
return

def __getstate__(self):
return None
Expand Down
46 changes: 27 additions & 19 deletions CfdFluidMaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# * Copyright (c) 2017-2018 Oliver Oxtoby (CSIR) <ooxtoby@csir.co.za> *
# * Copyright (c) 2017-2018 Alfred Bogaers (CSIR) <abogaers@csir.co.za> *
# * Copyright (c) 2017-2018 Johan Heyns (CSIR) <jheyns@csir.co.za> *
# * Copyright (c) 2019-2021 Oliver Oxtoby <oliveroxtoby@gmail.com> *
# * Copyright (c) 2019-2022 Oliver Oxtoby <oliveroxtoby@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
Expand All @@ -25,12 +25,13 @@
# ***************************************************************************


import FreeCAD
import CfdTools
import os
from CfdTools import addObjectProperty
import FreeCAD
if FreeCAD.GuiUp:
import FreeCADGui
import CfdTools
from CfdTools import addObjectProperty
import _TaskPanelCfdFluidProperties


def makeCfdFluidMaterial(name):
Expand Down Expand Up @@ -85,7 +86,7 @@ def __init__(self, obj):
self.initProperties(obj)

def initProperties(self, obj):
# Not currently used
# Not currently used, but required for parent class
addObjectProperty(obj, "References", [], "App::PropertyLinkSubList", "Material", "List of material shapes")

# Compatibility with FEM material object
Expand Down Expand Up @@ -113,6 +114,7 @@ def execute(self, obj):
class _ViewProviderCfdFluidMaterial:
def __init__(self, vobj):
vobj.Proxy = self
self.taskd = None

def getIcon(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "material.svg")
Expand All @@ -123,19 +125,13 @@ def attach(self, vobj):
self.Object = vobj.Object

def updateData(self, obj, prop):
return
analysis_obj = CfdTools.getParentAnalysisObject(obj)
if analysis_obj and not analysis_obj.Proxy.loading:
analysis_obj.NeedsCaseRewrite = True

def onChanged(self, vobj, prop):
return

def doubleClicked(self, vobj):
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Existing task dialog already open\n')
return True

def setEdit(self, vobj, mode):
analysis_object = CfdTools.getParentAnalysisObject(self.Object)
if analysis_object is None:
Expand All @@ -145,15 +141,27 @@ def setEdit(self, vobj, mode):
if not physics_model:
CfdTools.cfdErrorBox("Analysis object must have a physics object")
return False
import _TaskPanelCfdFluidProperties
taskd = _TaskPanelCfdFluidProperties.TaskPanelCfdFluidProperties(self.Object, physics_model)
taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(taskd)
import importlib
importlib.reload(_TaskPanelCfdFluidProperties)
self.taskd = _TaskPanelCfdFluidProperties.TaskPanelCfdFluidProperties(self.Object, physics_model)
self.taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(self.taskd)
return True

def doubleClicked(self, vobj):
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Task dialog already open\n')
FreeCADGui.Control.showDialog(self.taskd)
return True

def unsetEdit(self, vobj, mode):
if self.taskd:
self.taskd.closing()
self.taskd = None
FreeCADGui.Control.closeDialog()
return

def __getstate__(self):
return None
Expand Down
53 changes: 28 additions & 25 deletions CfdInitialiseFlowField.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# * Copyright (c) 2017 Alfred Bogaers (CSIR) <abogaers@csir.co.za> *
# * Copyright (c) 2017 Oliver Oxtoby (CSIR) <ooxtoby@csir.co.za> *
# * Copyright (c) 2017 Johan Heyns (CSIR) <jheyns@csir.co.za> *
# * Copyright (c) 2019-2021 Oliver Oxtoby <oliveroxtoby@gmail.com> *
# * Copyright (c) 2019-2022 Oliver Oxtoby <oliveroxtoby@gmail.com> *
# * Copyright (c) 2022 Jonathan Bergh <bergh.jonathan@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
Expand All @@ -25,14 +25,15 @@
# * *
# ***************************************************************************

import FreeCAD
import CfdTools
from CfdTools import addObjectProperty
import os
import os.path
import FreeCAD
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore
import CfdTools
from CfdTools import addObjectProperty
import _TaskPanelCfdInitialiseInternalFlowField


def makeCfdInitialFlowField(name="InitialiseFields"):
Expand Down Expand Up @@ -121,10 +122,10 @@ def initProperties(self, obj):
"Turbulent viscosity")

addObjectProperty(obj, 'VolumeFractions', {}, "App::PropertyMap", "Volume Fraction", "Volume fraction values")
addObjectProperty(obj, 'BoundaryU', None, "App::PropertyLink", "", "U boundary name")
addObjectProperty(obj, 'BoundaryP', None, "App::PropertyLink", "", "P boundary name")
addObjectProperty(obj, 'BoundaryT', None, "App::PropertyLink", "", "T boundary name")
addObjectProperty(obj, 'BoundaryTurb', None, "App::PropertyLink", "", "Turbulence boundary name")
addObjectProperty(obj, 'BoundaryU', None, "App::PropertyLink", "", "U boundary")
addObjectProperty(obj, 'BoundaryP', None, "App::PropertyLink", "", "P boundary")
addObjectProperty(obj, 'BoundaryT', None, "App::PropertyLink", "", "T boundary")
addObjectProperty(obj, 'BoundaryTurb', None, "App::PropertyLink", "", "Turbulence boundary")

def onDocumentRestored(self, obj):
self.initProperties(obj)
Expand All @@ -134,6 +135,7 @@ class _ViewProviderCfdInitialseInternalFlowField:

def __init__(self, vobj):
vobj.Proxy = self
self.taskd = None

def getIcon(self):
icon_path = os.path.join(CfdTools.get_module_path(), "Gui", "Resources", "icons", "initialise.svg")
Expand All @@ -144,7 +146,11 @@ def attach(self, vobj):
self.Object = vobj.Object

def updateData(self, obj, prop):
return
analysis_obj = CfdTools.getParentAnalysisObject(obj)
# Ignore Shape updates as these relate to linked patches
if prop != 'Shape':
if analysis_obj and not analysis_obj.Proxy.loading:
analysis_obj.NeedsCaseRewrite = True

def onChanged(self, vobj, prop):
return
Expand All @@ -161,32 +167,29 @@ def setEdit(self, vobj, mode):
boundaries = CfdTools.getCfdBoundaryGroup(analysis_object)
material_objs = CfdTools.getMaterials(analysis_object)

import _TaskPanelCfdInitialiseInternalFlowField
taskd = _TaskPanelCfdInitialiseInternalFlowField._TaskPanelCfdInitialiseInternalFlowField(
import importlib
importlib.reload(_TaskPanelCfdInitialiseInternalFlowField)
self.taskd = _TaskPanelCfdInitialiseInternalFlowField._TaskPanelCfdInitialiseInternalFlowField(
self.Object, physics_model, boundaries, material_objs)
taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(taskd)
self.taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(self.taskd)
return True

def unsetEdit(self, vobj, mode):
FreeCADGui.Control.closeDialog()
return

# Override doubleClicked to make sure no other Material taskd (and thus no selection observer) is still active
def doubleClicked(self, vobj):
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not CfdTools.getActiveAnalysis():
analysis_obj = CfdTools.getParentAnalysisObject(self.Object)
if analysis_obj:
CfdTools.setActiveAnalysis(analysis_obj)
else:
CfdTools.cfdErrorBox('No parent analysis object detected')
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Active Task Dialog found! Please close this one first!\n')
FreeCAD.Console.PrintError('Task dialog already active\n')
FreeCADGui.Control.showDialog(self.taskd)
return True

def unsetEdit(self, vobj, mode):
if self.taskd:
self.taskd.closing()
self.taskd = None
FreeCADGui.Control.closeDialog()

def __getstate__(self):
return None

Expand Down
Loading

0 comments on commit 5e1ce41

Please sign in to comment.