Skip to content

Programming with OpenFOAM is explained with a follow-along approach.

Notifications You must be signed in to change notification settings

LS-2ednar/OpenFOAM_Programming

Repository files navigation

Note this REPO is in the making and will take some time until it is finished.



General Information


This repo is used to show the process to develop functions for OpenFOAM and how these functions need to be structured to archive working applications to enchance your CFD simulations. First very briefly the appliaction directory structure and important files which have to be defined are explained. Then it is explained how the applcations are compiled and how certain dependencies can be removed again. Finally an example is shown, that explains the developement of a new application for OpenFOAM in different complexity levels increasing with the example number.

Basics


To generate new applications and functions in OpenFOAM the structure of the sepcific files has to be stored as shown in the image below:

From OpenFOAM Programmer's Guide


As indicated there are several files which are important for the final working application. New application show a Placeholder.C source file, which it the file that is to be compiled. This file has the code which later is run after compilation. The Placeholder.H files are used to check for errors, since these files represent headers of classes which later are used in the code. The subdirectory Make has two files the files file and the options file. The files file is a list of the files which are generated in the end aswell as the name of the source file and the the name of the later executable command. The options file contains the full directory paths to locate header files. To compile an application one can run the wmake command to compile everything. This step is especially usefull ince hit might show potential errors which are found during compilation. In case that the application should be removed, one can run the wclean command.

In general the approach to create a new application for OpenFOAM should be that an allready exisiting application is modified by introducing new .H files and including them in existing solver code (.C files).

Code Examples


The preseneted codes try to show some different level of monod kinetics. The examples (00 to XY) work with the imaginary concept of constant growth, no limitations and no negative effects of anymetabolites. Therefore one can say that the amount of Cells () after a time t is only dependent on the maximal growth rate initial number of Cells (), the maximal specific growth rate () and, time (t). Which can be described as follows:

The next set of examples (02 & 03) have an specific growthrate based on the amount of availabe substrate. Which leads to the equations:

Where () is determined via the substrate and the substrate affinity coefficient as shown below:

First example

The first example (00_monod_simple) is used to show how the basic monod calculation with a fixed value for muemax and an inital cell density can be applied and how the amount of cells would be calculated using C syntax.

Second example

The second example (01_monod_save_data) shows how data is accessed from dictionary files and how to work with runTime. Further, it is show how data can be stored in other files by creating a "postProcessing" directory where the calculated cell values per time step are stored in a file called "CellGrowth.csv"

Third example

The Cell Growth is determined prior to an the calculation of of the flowfield (using simpleFoam) followed by the custom function also the concept of a substrate is introduced and an changing value for the specific growthrate is implemented.

Forth example

Here the pimple algorithm is modified to work with specific values which are added to an "cellProperties" dictionary and calculate the value of cells and substrate after every iteration. To archive this the pimpleFoam solver application is copyied then the .C file is renamed and adjusted in the Make/files file. Then an additional TestEqn.H is introduced where the calculation of cells and substrate is done. Note that at this stage the calculated values are not reflecting the acctual values. This is due to the way the function is updated every timestep. Further, the outputfile no just shows the last calculated value which needs some more modifications.

Fifth example

Here the "particleFoam" solver is used to first simulate the different particles in a given test case. Then an additional step is taken and the postprocessing technique "particleTracks" which needs an additional constant/particleTrackProperties file are used to generate a VTK file.

Sixth example

Here the DPMFoam solver was used and then the particleTracks method was applied. Then a python script was introduced which allows the reorganization of the vtk file in a way, that the individual particle tracks are saved at the same spot.

Seventh example (Not jet workign)

This case will combine the MPPIC solver with the "particleTracks" utility to save the ParticleTracks in runtime and therefore have more tracking points. After inspecting the source code it is clear, that the MPPICFoam is based on the code of the the DPMFoam however in the MPPICFoam code another cloud headerfile is used "basicKinematicMPPICCloud.H" which means that the DPMFoam is the code that needs to be modified. To trick "wmake" the "DPMFoam.C" is directly modified and used for hte new solver Code to include other dependent files later in the code which are linked with a OpenFOAM specific function. Therfore only in the Make/files file the resulting appications name is changed but the sourceFile is still DPMFoam.C.It looks as if the testCase which is based on a MultipleReferenceFrame will not work with this setup therfore a modification of the case is needed. The MPPIC tutorials will need more inspection.

Eigth example

This approach modifies the icoFoam solver. First the application code is copied, then the createFields.H and icoTempFoam.C are modified. Then in the createFields.H file the DT dimensionedScalar is introduced and a Temperaturefield is added to the file. In the icoTempFoam.C file a new equation is added and solved before runTime.write()-ing it. These given parameters need new conditions for the initial parameters in 0/ therfore T is introduced there and in the constant/transportPropteries DT is added. Finaly the fvSchemes and fvSolution files in the systems directory need to be updated for the divSchemes and laplacianSchemes. And the solver for T needs to be added.

Nineth example

Adding functionality to acces the total volume of the internalMesh and saveing it to a file. This example originates from the icoFoam solver.

Tenth example

Here a python script is developed to distribute particles for manual injection randomly.

Eleventh example

Provides an overview of usable geometries to work with the developed procedures. Currently there is a need for more finess which will deployed over the next days.



Sources

This Repo is based on the ideas shown here UnnamedMoose BasicOpenFOAMProgrammingTutorials


TO DO

Try to fuse some of the particletracking methods (particleFoam, MPPICFoam) with the particleTracks method to get a vtk file and link the function with the pythonscript provided in case 04

It seems that the Tracking of particles is harder in OpenFOAM v8 but as of july 2021 OpenFOAM v9 seems the show improvement in several quite important locations. Link

About

Programming with OpenFOAM is explained with a follow-along approach.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published