Skip to content

Commit

Permalink
CFD: add Fenics 3D CFD test case file and bugfix for case writting
Browse files Browse the repository at this point in the history
  • Loading branch information
qingfengxia committed Nov 23, 2017
1 parent f5c659e commit eb39080
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
42 changes: 25 additions & 17 deletions CaeCaseWriterFenics.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

"""
A general fenics case writer for Fenics solver (URL at github)
FenicsSolver is developed in another repo, as a submodule for Cfd workbench
git submodule update --recursive --remote
"""

__title__ = "Fenics Case Writer"
Expand All @@ -37,11 +39,7 @@
import CfdTools

"""
from FemCaseWriterFenics import FemCaseWriterFenics
w = FemCaseWriterFenics(App.getDocument("TestCfdCubePipe").CfdAnalysis)
w.write_case()
CfdTools functions should be merged inte FemTools.py before this class can be integrated into Fem workbench
CfdTools functions should be merged into FemTools.py before this class can be integrated into Fem workbench
"""

## write FEM analysis setup into Fenics case file
Expand Down Expand Up @@ -102,6 +100,7 @@ def write_case(self, updating=False):
#self.case_settings['turbulence_settings'] = {"name": self.solver_obj.TurbulenceModel} # not supported yet
self.write_transient_control()
self.write_output_control()
self.write_thermal_settings()

## debug output
print("\n debug output of case setting dict\n")
Expand Down Expand Up @@ -234,15 +233,16 @@ def _from_fluidic_to_fenics_boundary(self, bcs):
zero_vector = (0,0,0)
else:
zero_vector = (0,0)
bcs_n['default_wall'] = {'name': 'default_wall', 'boundary_id': 0, \
'values':[{'variable':'velocity', 'type':'Dirichlet', 'value': self.zero_vector}]}
if self.solver_obj.HeatTransfering:
bcs_n['default_wall'] ['values'].append({'variable':'temperature', 'type':'Neumann', 'value': self.zero_vector})
# default wall should be identified by gmsh mesher
#bcs_n['default_wall'] = {'name': 'default_wall', 'boundary_id': 0, \
# 'values':[{'variable':'velocity', 'type':'Dirichlet', 'value': zero_vector}]}
#if self.solver_obj.HeatTransfering:
# bcs_n['default_wall'] ['values'].append({'variable':'temperature', 'type':'Neumann', 'value': self.zero_vector})

for bc in bcs:
bc_n = {'boundary_id': bc['boundary_id'], 'values': []}
bc_n = {'boundary_id': bc['boundary_id'], 'values': {}}
bc_n_v = {}
if bc['subtype'].lower().find('velocity') > 0:
if bc['subtype'].lower().find('velocity') >= 0:
bc_n_v['variable'] = 'velocity'
bc_n_v['type'] = 'Dirichlet'
bc_n_v['value'] = bc['value']
Expand All @@ -253,9 +253,9 @@ def _from_fluidic_to_fenics_boundary(self, bcs):
elif bc['type'].lower() == 'wall':
bc_n_v['variable'] = 'velocity'
bc_n_v['type'] = 'Dirichlet'
if bc['type'].lower() == "fixed":
if bc['subtype'].lower() == "fixed":
bc_n_v['value'] = zero_vector
elif bc['type'].lower() == "moving":
elif bc['subtype'].lower() == "moving":
bc_n_v['value'] = bc['value']
else:
print('Error: Wall of subtype {} is not not supported by Fencis yet'.format(bc['subtype']))
Expand All @@ -266,9 +266,9 @@ def _from_fluidic_to_fenics_boundary(self, bcs):
print('Error: interfce of subtype {} is not supported by Fencis yet'.format(bc['usbtype']))
else:
print('Error: Boundary type {} and subtype {} is not supported by Fencis yet'.format(bc['type'], bc['usbtype']))
bc_n['values'].append(bc_n_v)
bc_n['values'][bc_n_v['variable']] = bc_n_v
if self.solver_obj.HeatTransfering:
bc_n['values'].append(_from_fluidic_thermal_to_fenics_boundary(bc))
bc_n['values']['temperature'] = _from_fluidic_thermal_to_fenics_boundary(bc)
bcs_n[bc['name']] = bc_n
return bcs_n

Expand Down Expand Up @@ -335,7 +335,7 @@ def write_fluidic_boundary_conditions(self):
bc_dict = {'name': bc.Label, "boundary_id":i+1, "type": bc.BoundaryType, # it is essential the first bounary with id=1
"subtype": bc.Subtype, "value": bc.BoundaryValue}
if bc_dict['type'] == 'inlet' and bc_dict['subtype'] == 'uniformVelocity':
# deal with 2D geometry
# deal with 2D geometry but 2D direction vector is reversed
bc_dict['value'] = list(v * bc_dict['value'] for v in tuple(bc.DirectionVector)[:self.dimension])
# fixme: App::PropertyVector should be normalized to unit length
if self.solver_obj.HeatTransfering:
Expand All @@ -362,6 +362,9 @@ def write_boundary_condition(self):
else:
print('Error: {} boundary is not supported by Fencis and FreeCAD yet'.format(self.solver_obj.PhysicalDomain))

def write_thermal_settings(self):
self.case_settings['solving_temperature'] = self.solver_obj.HeatTransfering

def write_initial_values(self):
if self.solver_obj.PhysicalDomain == u"Fluidic":
self.case_settings['initial_values'] = {'pressure': 0.0, 'velocity': (0,0,0)[:self.dimension]}
Expand All @@ -370,6 +373,8 @@ def write_initial_values(self):
# must set a nonzero for velocity field to srart withour regarded converged
elif self.solver_obj.PhysicalDomain == u"Thermal":
self.case_settings['initial_values'] = {'temperature': 300}
elif self.solver_obj.PhysicalDomain == u"Mechanical":
pass # init values are not necessary for displacement
else:
pass

Expand All @@ -382,7 +387,10 @@ def write_body_source(self):
def write_solver_control(self):
""" relaxRatio, reference values, residual contnrol, maximum_interation
"""
self.case_settings['solver_settings'] = {"solver_parameters": {},
self.case_settings['solver_settings'] = {"solver_parameters": {"relative_tolerance": 1e-5,
"maximum_iterations": 500,
"monitor_convergence": True # print to console
},
"reference_values": {'pressure': 1e5, 'velocity': (1, 1, 1)[:self.dimension]},
}

Expand Down
1 change: 1 addition & 0 deletions CfdRunnableFenics.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CfdRunnableFenics(_CfdRunnable):
def __init__(self, solver=None):
super(CfdRunnableFenics, self).__init__(solver)
self.writer = CaeCaseWriterFenics.CaeCaseWriterFenics(self.analysis)
self.case_file = self.writer.case_file_name

def check_prerequisites(self):
return ""
Expand Down
2 changes: 1 addition & 1 deletion CfdTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def getPartDimension(part_obj):
dimension = 3
elif shty == 'Face' or shty == 'Shell':
# print('Found: ' + shty)
dimension = 3
dimension = 2
elif shty == 'Edge' or shty == 'Wire':
# print('Found: ' + shty)
dimension = 1
Expand Down
2 changes: 1 addition & 1 deletion InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def Initialize(self):
cmdlst = ['Cfd_Analysis', 'Cfd_AnalysisFromMesh', 'Cfd_Solver', 'Cfd_SolverFenics','FEM_MaterialFluid', 'Separator', # superseded 'Cfd_FluidMaterial',
'FEM_ConstraintFluidBoundary', 'FEM_ConstraintSelfWeight', 'Separator',
'Cfd_MeshGmshFromShape', # add parameter adjustment for 'FEM_MeshGmshFromShape',
'FEM_MeshBoundaryLayer', 'FEM_MeshRegion', 'FEM_MeshPrintInfo', 'FEM_MeshClear', "Separator",
'FEM_MeshBoundaryLayer', 'FEM_MeshRegion', 'FEM_MeshGroup','FEM_MeshPrintInfo', 'FEM_MeshClear', "Separator",
'Cfd_SolverControl']
#"Separator", "FEM_PostPipelineFromResult", "FEM_PostCreateClipFilter",
#"FEM_PostCreateScalarClipFilter", "FEM_PostCreateCutFilter"]
Expand Down
Binary file added test_files/TestCfdFenics.fcstd
Binary file not shown.

0 comments on commit eb39080

Please sign in to comment.