Tudat / tudat

NOTE: This Tudat version is no longer supported. See https://docs.tudat.space/en/stable/ and https://github.com/tudat-team/tudat-bundle for the new version
BSD 3-Clause "New" or "Revised" License
87 stars 142 forks source link

RAM overload bodyMap #661

Closed ptorrente closed 1 year ago

ptorrente commented 3 years ago

Hello,

I would like to know if there is a way to clear the bodyMap memory.

I am performing a for loop simulation with 10000 runs, varying some user specified spherical harmonic coefficients that are provided in the bodySettings. I usually perform my loops after the creation of the bodyMap, but it is the first time I have to do it before because of the spherical harmonics coefficients that I define in the bodySettings.

The problem is therefore that the start of my for loop is currently before the creation of the bodyMap performed as: NamedBodyMap bodyMap = createBodies( bodySettings );

After investigation, this line is the problem. I found explained here: https://tudat.tudelft.nl/tutorials/applicationWalkthroughs/propTargeting.html that it stores information at each iteration and the RAM usage of my computer just grows over time until my computer crashes, because I cannot reach 10000 runs.

I found this thread (https://github.com/Tudat/tudat/issues/206) about a memory leak issue that seems related as it mentions a need to clear the bodyMap memory with the use of some functions implemented by Dominic in this code (https://github.com/DominicDirkx/tudat/commit/c6913de9cf981fe70244ed832ffab5d578eefe8b), especially a emptyBodyMapMemory() function.

I could not figure out in the thread if it solved the problem, and it also appears that those changes are not part of the current version of TUDAT.

So I guess my questions are:

Thank you for your time.

Kind regards,

Paul Torrente

DominicDirkx commented 3 years ago

Hi Paul,

Please provide a link to the code you're using, and we can have a look,

Dominic

ptorrente commented 3 years ago

Hi Dominic,

Thank you for the quick answer.

You will find the code here: https://github.com/ptorrente/Master_Thesis_4905261/blob/master/ChaosIndicators/sensitivityAnalysis.cpp

It is a bit messy, I apologize for that.

If you want to run the program, you will need to change the path in lines 125 and 140, the input file being in this folder: https://github.com/ptorrente/Master_Thesis_4905261/tree/master/BetaEphemeris

The beginning of my for loop is at the moment at line 796 right after the creation of the bodyMap at line 743.

If I start the for loop before that line (which I would like to do for example at line 270, just before providing my spherical harmonic coefficients that I would like to vary), the RAM usage increases over time as explained in my previous post.

I hope this gives enough details.

Kind regards,

Paul

DominicDirkx commented 3 years ago

HI Paul,

If I understand correctly, you want to modify the gravity fields of the asteroids in a loop after you've created the body map. Can you confirm that this is the case?

You can do this by:


std::dynamic_pointer_case< SphericalHarmonicsGravityField >( bodyMap.at( "Alpha" )->getGravityFieldModel( ) )->setCosineCoefficients( ... )

std::dynamic_pointer_case< SphericalHarmonicsGravityField >( bodyMap.at( "Alpha" )->getGravityFieldModel( ) )->setSineCoefficients( ... )
ptorrente commented 3 years ago

Hi Dominic,

Initially I would like to modify the gravity fields of the asteroids in a loop situated before the creation of the body map because right now the spherical harmonics are defined in the body settings in my code, which is before the creation of the body map. This however creates the RAM overload because the body map creation is inside the loop so that is why I was wondering whether it was possible to empty the body map memory at the end of each iteration.

But indeed, if I define the spherical harmonics in the body map instead of the body settings, I can do the loop after the body map creation, so I will test that out. Thank you for the code lines!

Kind regards,

Paul

DominicDirkx commented 1 year ago

NOTE: This Tudat version is no longer supported. See https://docs.tudat.space/en/stable/ and https://github.com/tudat-team/tudat-bundle for the new version