CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   SU2 (https://www.cfd-online.com/Forums/su2/)
-   -   Change onflow condition "on-the-fly" with pysu2 ? (https://www.cfd-online.com/Forums/su2/240151-change-onflow-condition-fly-pysu2.html)

Arne Voß December 14, 2021 12:14

Change onflow condition "on-the-fly" with pysu2 ?
 
Hi everyone,



I use the pysu2 interface to launch a CFD computation similar as shown below. I have two questions/problems:
a) Is it possible to change parameters like the angle of attack, sideslip or the grid movement "on-the-fly", without initializing the solver again? For example it is possible to set mesh deformations on-the-fly with pysu2.CSinglezoneDriver.SetMeshDisplacement() but I haven't found a function to change e.g. the onflow condition.

b) Currently, my workaround is to write the new onflow condition into the config file and initialize SU2 again with hte new config file. However, this creates new problems because I found that the memory is not cleared after the post-processing and thus, after a couple of loops, I run out of memory. Note that I use mesh deformation, which uses a lot of memory.




import pysu2
class MySU2Interface(object):
def init_solver(self, para_filename):
self.FluidSolver = pysu2.CSinglezoneDriver(para_filename, 1, self.comm)


def run_solver(self):
# mpi barrier

self.comm.barrier()


# run solver
self.FluidSolver.Preprocess(0)
self.FluidSolver.Run()
self.FluidSolver.Postprocess()


# write outputs and restart file(s)
self.FluidSolver.Monitor(0)
self.FluidSolver.Output(0)

pcg December 14, 2021 14:26

Unfortunately we do not have that capability.

Arne Voß December 15, 2021 05:36

Hi Pedro,

thank you very much for the fast answer. Do you have any plans to integrate such a functionality in the future?

In the meantime, do your have or do you plan to have a function that clears/releases all memory when SU2 is done? Something like pysu2.CSinglezoneDriver.release_memory() or similar... I believe that would be very helpful for the users that don't use SU2 (only) as a standalone.
I tried to delete the SU2 instance in python, but that didn't do anything to the memory consumption and running the garbage collector manually didn't help neither.

del self.FluidSolver
gc.collect()

Do you have any suggestions how I could/should handle this problem?


Thank you very much for your help,
Arne




Update to question b): After looking into the code, I found that the function that clears/releases memory is called pysu2.CSinglezoneDriver.Postprocessing(). I didn't see it at the beginning, because there is a second function Postprocess(). Looking at the names only, I didn't realize the difference in the underlying function.

bigfootedrockmidget December 20, 2021 18:04

For the updating of parameters: At the start of every iteration you could read a file with the updated parameter value in it and update the value that is read from the config file.

Arne Voß December 21, 2021 03:05

Hi,

That sound like what I have in mind. However, I am not sure how to do this. Could you give more detailed instructions?
Thank you very much,
Arne

pcg December 22, 2021 05:41

Hi Arne you can have a look at CEulerSolver::SetFarfield_AoA in CEulerSolver.cpp for what needs to be changed to set a different AoA.
I would be careful with changing Mach number because it may be used for nondimensionalization, or as a parameter of some schemes.

Arne Voß December 22, 2021 06:03

Hi,

I see that I could call SetAoA(alpha) located in the CConfig.cpp. But I believe the CConfig.cpp is not accessible via the python interface, so I have no idea how I could do this. What needs to be done to expose the CConfig.cpp to the python interface? Is it possible at all?

Sorry that I ask questions that might appear simple to you guys, but I am not a software engineer and have no experience with C++.
Thank you for your help,
Arne

pcg December 23, 2021 12:37

It is not enough to set it in the config object because other classes will use the original value to convert that information into something else, for example, the flow solver will use it to compute the farfield velocity.
The function I pointed to above, modifies that velocity.
The typical process to expose functions to python is via the CDriver class, in particular the methods you add to python_wrapper_structure.cpp. In a nutshell you need to add a method to the driver to reach into the lower classes (solvers, etc.)
See e.g. CDriver::SetVertexNormalHeatFlux in that file.


All times are GMT -4. The time now is 21:47.