CFD Online Discussion Forums

CFD Online Discussion Forums (
-   SU2 (
-   -   Adding a configuration option to read a file (

mlatour August 29, 2019 16:38

Adding a configuration option to read a file
1 Attachment(s)
Hi everyone,

I'm currently working on adding body force modeling capabilities to SU2, which would require the reading of a file (see attachment) with values so that they can be stored in an array and used in the numerics class. I understand how to add simple list, double, or string options to the source code, but am having difficulty understanding how to read a file and store it in an array that can be used in the numerics class.

A new class will have to be created, but where would I add this? A file is read for the inlet profile option, but that code is quite extensive and more complicated to understand.

Any help would be appreciated.

Kind Regards,

pcg August 31, 2019 17:30

Would those values be used to compute some source term? Are they constant over time and space? Or do you have different values for different nodes/regions?

If the answers to the above are: yes, yes, no. Then:

Look into numerics_direct_mean.cpp and CSourceXXXX

If you can get away with modifying an existing class it would save you some time, for example take CSourceBodyForce, read your file in its constructor and then modify the ComputeResidual method.

Source term numerics are used by method CEulerSolver::Source_Residual, this method of the solver goes over all nodes, passes some data of each node to the numerics class and then calls ComputeResidual on it.
Make sure this method is passing all the data you need to the numerics class.

mlatour September 3, 2019 15:30

Hey Pedro,

The source term values are spatially varying and I have been able to hard-code an implementation that seems to be working. I've adapted the CSourceBodyForce code to compute my force at each node according to the theory.

I was thinking of having CSourceBodyForce read the file, but wouldn't this mean it will be done at every node? Although it may only be a simple file, this would add more computational time to each loop. Is there a way to have it read the file outside this loop and then have the CSourceBodyForce class accept an additional variable, in this case an array with the data from the file?


pcg September 5, 2019 07:49

Hi Marc,

Ah! That is why I asked if they are constant.

There is no automated way...
The numerics classes get their data from CGeometry and CVariable, the "SU2 way" to do what you want is to add the fields you need to CVariable (since they vary with space) and then set the data in numerics in the SourceResidual loop.

You could read and set that data in CVariable in the solver constructor (executed only once) or in the solver preprocessing method (executed every iteration).
If you just want to prototype you could also avoid CVariable and add a few vectors directly to CSolver...


All times are GMT -4. The time now is 20:41.