... | ... | @@ -184,6 +184,8 @@ main -> simulation : run |
|
|
|
|
|
## Example
|
|
|
|
|
|
### A first 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)
|
... | ... | @@ -199,15 +201,20 @@ class SimulationTracker { |
|
|
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 {
|
|
|
class PlanetaryAccretionTracer : public SimulationTracker {
|
|
|
public:
|
|
|
MyCoolAccretionTracker(Simulation const& simulation, TrackingConfig::Tracker const& cfg)
|
|
|
: SimulationTracker(simulation, cfg) {}
|
|
|
void accretionRetrieved(MomentumMap const& retrievedGasMomentum) override {
|
|
|
for (auto const& m : retrievedGasMomentum) { std::cout << m.first << " -> " << m.second << '\n'; }
|
|
|
}
|
|
|
static std::string name() { return "my_cool_tracker"; }
|
|
|
PlanetaryAccretionTracer(Simulation const& simulation, TrackingConfig::Tracker const& cfg)
|
|
|
: SimulationTracker(simulation, cfg) {}
|
|
|
|
|
|
void accretionRetrieved(MomentumMap const& retrievedGasMomentum) override {
|
|
|
for (auto const& m : retrievedGasMomentum) {
|
|
|
log() << m.first << " -> " << m.second << '\n';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static std::string name() { return "planetary_accretion_tracer"; }
|
|
|
};
|
|
|
|
|
|
```
|
|
|
|
|
|
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'):
|
... | ... | @@ -215,13 +222,72 @@ Then we need to register the appropriate tracker creator in the creator map. Thi |
|
|
```
|
|
|
namespace fargOCA {
|
|
|
...
|
|
|
DeclaredTracker<MyCoolAccretionTracker> myCoolAccretionTracker;
|
|
|
DeclaredTracker<PlanetaryAccretionTracer> planetaryAccretionTracer;
|
|
|
...
|
|
|
}
|
|
|
```
|
|
|
|
|
|
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).
|
|
|
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):
|
|
|
```
|
|
|
Output
|
|
|
{
|
|
|
...
|
|
|
Trackers {
|
|
|
...
|
|
|
planetary_accretion_tracer {}
|
|
|
...
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
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/src/simulationTrackers.cpp#L235).
|
|
|
|
|
|
[^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). |
|
|
|
|
|
### Configuration
|
|
|
#### Problem description
|
|
|
In the previous example, the tracker has no configurable behavior. This is usually an over simplification.
|
|
|
We are going to see how to add some functionalities to it.
|
|
|
|
|
|
In the next example, the log won't be printed on the standard output but in files indexed by planet name.
|
|
|
That is, the gas accreted by planet `Jupiter` will be logged in file "accretionJupiter.txt".
|
|
|
|
|
|
#### Config file
|
|
|
First, we need to specify the log file format, will do that with a tracker parameter named "ofile_fmt" (there are no constraint here, it's just the name we've been using so far in that situation):
|
|
|
|
|
|
```
|
|
|
Output
|
|
|
{
|
|
|
...
|
|
|
Trackers {
|
|
|
...
|
|
|
planetary_accretion_tracer {
|
|
|
ofile_fmt "accretion%1%.txt"
|
|
|
}
|
|
|
...
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
We use the [boost format library](https://www.boost.org/doc/libs/1_71_0/libs/format/doc/format.html) to deal with the dynamic par of the string. So here, the "%1%" will be replaced with the planet name.
|
|
|
|
|
|
#### Parameter value retrieval
|
|
|
|
|
|
We will use the [SimulationTracker::parameter](https://disc.pages.oca.eu/fargOCA/public/doxy/classfargOCA_1_1SimulationTracker.html#a069b1be9c91f9424ce1fc8b79e0cb8a8) to retrieve the file name format, using a reasonnable format if none is specified.
|
|
|
|
|
|
|
|
|
```
|
|
|
void
|
|
|
PlanetaryAccretionLogger::accretionRetrieved(MomentumMap const& retrievedGasMomentum) {
|
|
|
for (auto const& m : retrievedGasMomentum) {
|
|
|
std::string planet = m.first;
|
|
|
Momentum const& momentum = m.second;
|
|
|
if (simulation().disk().grid().master()) {
|
|
|
boost::format fmt(parameter("ofile_fmt", "accretion%1%.log"));
|
|
|
std::string ofilename = (fmt%planet).str();
|
|
|
std::ofstream output(ofilename, std::ios::out | std::ios::app);
|
|
|
output << simulation().disk().step() << " " << simulation().disk().physicalTime() << " " << momentum << '\n';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
[^1]: this class is over simplified, does not allow 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). |