Package: casefoam
This module is a addition toPyFoamand can automatically setup OpenFOAM
cases with varying conditions.Getting startedInstalling CaseFOAMIn order to use the Python module you need thePyFoampackage.install the package after cloning the repository with:$pipinstall.orviapypibyexecuting:$pipinstallcasefoamUser’s GuideFor a full documentation change intodocand build the documentation for
example as html.$cddoc/$makehtml$firefoxbuild/html/index.htmlExampleCaseFoam offers two main features: the easy generation of parameter studies
and the analysis of these. In the example, we want to change the intial height
of the column and perform a grid study for the damBreak test case:parameter studiesThe first step is the generation of the cases. We want to generate three
column heights where each case has three grids with a differnt cell size.catgenCases.py:importcasefoambaseCase='damBreak'caseStructure=[['height_02','height_03','height_04'],['grid1','grid2','grid3']]defupdate_grid(a,b,c,d,e):return{'system/blockMeshDict':{'#!stringManipulation':{'varA':'%s'%a,'varB':'%s'%b,'varC':'%s'%c,'varD':'%s'%d,'varE':'%s'%e}}}defupdate_height(height):return{'system/setFieldsDict':{'#!stringManipulation':{'var_height':'%s'%height}}}caseData={'height_02':update_height(0.2),'height_03':update_height(0.3),'height_04':update_height(0.4),'grid1':update_grid(23,8,19,42,4),'grid2':update_grid(23*2,8*2,19*2,42*2,4*2),'grid3':update_grid(23*3,8*3,19*3,42*3,4*3)}# generate casescasefoam.mkCases(baseCase,caseStructure,caseData,hierarchy='tree',writeDir='Cases')There a three different options how the cases can be manipulated:replacing a string inside the specified filesexecuting a bash scriptby specifying a dictionaryfor details please see the user manual.The script is executed by:pythongenCases.pyThis will the generate the following structure:The cases can be started by running the newly created Allrun script./AllrunpostProcessingThree functions are avaiable for the postProcessing:time_seriespositional_fieldposField_to_timeSeriesFor the damBreak test case we want to plot the freesurface position at a given time.
For that, we use the positional_field function and get a pandas dataframe which we plot with holoviewsimportcasefoamimportmatplotlib.pyplotaspltimportpandasaspdimportholoviewsashvhv.extension('bokeh')caseStructure=[['height_02','height_03','height_04'],['grid1','grid2','grid3']]baseCase='Cases'surfaceDir='freeSurface'surface=casefoam.positional_field(surfaceDir,'U_freeSurface.raw',0.3,caseStructure,baseCase)surface.columns=['x','y','z','Ux','Uy','Uz','col_height','res']surface_ds=hv.Dataset(surface,['col_height','res'],['x','y','z','Ux','Uy','Uz'])holoviews is optimized for the use for the jupyter notebooks. The %%opts arguments are used to modify the layout of the plot.
holoviews renders an interactive plot which can be exported as html:%%optsScatter[width=600,height=600,title='freeSurface at 0.3s',tools=['hover']]%%opts(muted_alpha=0.0)surface_ds.to(hv.Scatter,'x','y').overlay('res')version 0.0.10.0.1 (2021-04-14)First release on PyPI.version 0.0.20.0.2 (2021-04-14)First release on PyPI.version 0.0.30.0.3 (2021-04-14)First release on PyPI.version 0.0.40.0.4 (2021-04-14)First release on PyPI.version 0.1.00.1.0 (2022-02-16)added CIreplaced append with concatversion 0.1.10.1.1 (2022-05-18)new Function: of_cases finds all OpenFOAM cases in folderversion 0.2.00.2.0 (2022-05-18)new Function: profiling allows to load profiling data from OpenFOAMaddprofilingtosystemcontrolDict:profiling{activetrue;cpuInfofalse;memInfofalse;sysInfofalse;}prof=casefoam.profiling(time=0,processorDir="",caseStructure=caseStructure,baseCase=baseCase)