Sampling data over a line during OpenFOAM simulation
I have joined a work far from CFD for now. However, I encountered a task that requires a CFD simulation to reveal the physical process recently. The open-source solution comes to my mind at first priority. I started to install the latest OpenFOAM(12) in my new laptop and then re-learned the key points to implement the simulation. However, the OpenFOAM implementation is far from filling parameters and clicking “Run”. The references are also somewhat scattered on the internet. It takes quite a long time to pick up OpenFOAM again since I did not learn OpenFOAM very deeply, however, it is worth it.
In my task, I want to monitor a variable over the central line at every 10 timesteps. After searching the Internet, I found that this can be realized through the functions utility. However, I didn’t find a direct example. Here I provide my implementation for your reference.(Note: Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows by producing additional user-requested data both during runtime and postprocessing calculations, typically in the form of additional logging to the screen, or generating text, image and field files.[1])
The functions block can be added in the system/controlDict directory. I was inspired by the discussions on cfd-online[2] and the comments from ufocfd.
Then I searched on Google about the topic “openfoam write variable over a line at every timestep”. The Google AI search gives the following code example:
1 | functions |
It gives me a lot of confidence though the AI generated code does not work generally, especially for OpenFOAM which is not widely used by people worldwide. Whatever, it is a good start. Thank you LLM.
I copied the code into system/controlDict and compile the code. OpenFOAM complains about the code errors, such as the unknown type of sampling. With the “banana” method, I can quickly correct the code block in the following:
1 | functions |
Now the monitored data will be stored in the postProcessing/ directory.
In the above code block, sets can define the sampling line I am using. executeControl and writeControl control the implementation of the code block. The interpolationScheme can be referred on the sampling webpage[3]. For example, the “cellPoint” scheme I used applies linear weighted interpolation using cell values.
With the help of LLMs, the development of user modules is greatly accelerated.
Ref:
[1] https://www.openfoam.com/documentation/guides/latest/doc/guide-function-objects.html
[2] https://www.cfd-online.com/Forums/openfoam-post-processing/219747-openfoam-monitor-flow-value-internal-surface.html
[3] https://www.openfoam.com/documentation/user-guide/7-post-processing/7.4-sampling-data