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 143 forks source link

Key not found in accelerationMap #649

Closed liampieters closed 4 years ago

liampieters commented 4 years ago

Hi all,

I simulate a laser and multiple debris objects simultaneously. To do this I add each Body to the bodiesToPropagate vector and give each body a central body. No problems here. However, I stop the simulation when the laser nears any of the objects, after which I want to start a new propagation with only the laser and that target debris object. So I construct a new vector named bodiesToPropagateInteraction and add only the laser and the string of the respective debris. I also assign a central body to both objects. I add one acceleration type to the debris object (ablation acceleration that uses a custom made function). The code looks as follows: (line 651 in https://github.com/liampieters/SpaceDebris/blob/master/LEO_test.cpp

std::vector< std::string > bodiesToPropagateInteraction;
std::vector< std::string > centralBodiesInteraction;
bodiesToPropagateInteraction.push_back( "Asterix");
centralBodiesInteraction.push_back( "Earth" );
bodiesToPropagateInteraction.push_back( debrisNumberInteraction );
centralBodiesInteraction.push_back( "Earth" );

accelerationsOfDebris[ debrisNumberInteraction ].push_back(
                        std::make_shared< ThrustAccelerationSettings >( customThrustDirectionSettings, thrustMagnitudeSettings ) );
accelerationMap[ debrisNumberInteraction ] = accelerationsOfDebris;
basic_astrodynamics::AccelerationMap accelerationModelMapAblation = createAccelerationModelsMap(
                                bodyMap, accelerationMap, bodiesToPropagateInteraction, centralBodiesInteraction );

but when I construct the new accelerationMapAblation in the last line it returns an error and claims: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: map::at: key not found. I checked the content of each of the entries in the accelerationModelMapAblation (bodymap, accelerationMap, bodiesToPropagate and centralBodiesInteraction) but the representative debris is present in each of them, so I dont understand the error. Does anyone see what I do wrong? Thanks a million for any help!

Best, Liam

DominicDirkx commented 4 years ago

Hi Liam,

Line 651 in the code you link to is a commented block of code. On which line of code does it crash exactly?

Best,

Dominic

liampieters commented 4 years ago

Hi professor,

Sorry I was stupid enough to alter the code in the meantime.. The code crashes at line 601 at the creation of the new accelerationMap where it tells me that a key is not found. I checked the entries of all the inputs of the accelerationMap and the key 'debris3' should be there.

Thanks in advance, Best, Liam

DominicDirkx commented 4 years ago

Hi Liam,

I believe the error may be in this line:

https://github.com/liampieters/SpaceDebris/blob/master/LEO_test.cpp#594

you are not creating a new accelerationMap, but adding entries to an existing map. Unless this is by design, always try to use fresh, empty maps when creating these lists of settings. That way, you can be sure that no old entries pollute, and maybe crash, the code,

Dominic

liampieters commented 4 years ago

Hi Dominic,

Thanks for the reply. I created a new accelerationMapAblation where I define the accelerations on the laser and the debris during the interaction. Unfortunately I get the same error when creating the accelerationModelMapAblation. I noticed that the error only comes up when I create the accelerationModelMapAblation using bodiesToPropagateInteraction, in which I only add the laser and the debris that the laser encounters. There seems to be something about the keys in bodiesToPropagateInteraction that the program does not get, because the error does not come up when I create the accelerationModelMap with only bodiesToPropagate, which is filled with the laser and all the debris objects. Do I implement the bodiesToPropagateInteraction in a wrong way (line 570 in my code)? Or should I create a new bodyMapAblation with only the laser and the target debris every time it encounters a debris? Thanks a lot for the help!

Best, Liam

liampieters commented 4 years ago

Got it! Turned out that the size of bodiesToPropagate needs to correspond with the size of the accelerationMap, so I indeed had to make a fresh map. It was just a little hard to configure. Thanks professor!

Best, Liam