... | ... | @@ -181,3 +181,43 @@ main -> simulation : run |
|
|
|
|
|
## Example
|
|
|
|
|
|
Let's say we want to keep track of the gas lost to planet accretion.
|
|
|
|
|
|
The signal for that event is [accretionRetrieved](znort, doxi files not copied into static file)
|
|
|
```
|
|
|
class SimulationTracker {
|
|
|
....
|
|
|
/// \brief Called just after the gas accreted by planets has been retrieved.
|
|
|
/// \param retrievedGasMomentum a planet name -> momentum map
|
|
|
virtual void accretionRetrieved(std::map<std::string, Momentum> const& retrievedGasMomentum);
|
|
|
...
|
|
|
```
|
|
|
|
|
|
So the first step is to created, preferably in [simulationTrackers.hpp](https://gitlab.oca.eu/DISC/fargOCA/blob/master/include/simulationTrackers.hpp), a tracker class that will redifine that method[^1]:
|
|
|
|
|
|
```
|
|
|
class MyCoolAccretionTracker : public SimulationTracker {
|
|
|
public:
|
|
|
MyCoolAccretionTracker(Simulation const& simulation, TrackingConfig::Tracker const& cfg) {}
|
|
|
void accretionRetrieved(std::map<std::string, Momentum> const& retrievedGasMomentum) override {
|
|
|
for (auto const& m : retrievedGasMomentum) { std::cout << m.first << " -> " << m.second << '\n';
|
|
|
}
|
|
|
static std::string name() { return "my_cool_tracker"; }
|
|
|
};
|
|
|
```
|
|
|
|
|
|
Then we need to register the appropriate tracker creator in the creator map. This can be achieved by instantiating the following declaration object in the global scope in the implementation file ('simulationTrackers.cpp'):
|
|
|
|
|
|
```
|
|
|
namespace fargOCA {
|
|
|
...
|
|
|
DeclaredTracker<HillForceTxtLogger> hillForceTxtLogger;
|
|
|
...
|
|
|
}
|
|
|
```
|
|
|
|
|
|
And that's it. You can now activate the "my_cool_tracker" in your configuration file as described in the [user's manual](User's-Guide/Configuring-the-simulation#the-predifined-trackers).
|
|
|
|
|
|
Of course, in the real case, you probably want to log that information in a file indexed by the planet names. That is achieved through the use of the configuration. You will find many examples of that in the existing predefined tracker, such as [PlanetTxtLogger](https://gitlab.oca.eu/DISC/fargOCA/blob/master/include/simulationTrackers.hpp#L240).
|
|
|
|
|
|
[^1]: this class is over simplified, does not alow any user configuration and does not keep any state. Also, all implementation code should be in the [simulationTrackers.cpp](https://gitlab.oca.eu/DISC/fargOCA/blob/master/include/simulationTrackers.hpp). |