Repository navigation
Expand file tree
/
Copy pathexample_plugin.cpp
More file actions
59 lines (48 loc) · 1.44 KB
/
Copy pathexample_plugin.cpp
File metadata and controls
59 lines (48 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Reference external plugin for gravityCU v3.1 PhysicsStage ABI.
// Build: g++ -O2 -std=c++17 -shared -fPIC -Isrc plugins/example_plugin.cpp -o build/example_plugin.so
// Run: GRAV_PLUGINS=build/example_plugin.so ./build/grav_cosmo_hydro ...
#include "grav_plugin.h"
#include <cstdio>
namespace {
int g_pre_pm_calls = 0;
int g_post_kick_calls = 0;
int g_snapshot_calls = 0;
int on_init(const GravPluginInitInfo* info) {
std::printf("EXAMPLE_PLUGIN init box=%.2f a=[%.4f->%.4f] n_gas=%d n_dm=%d\n",
info->box_mpc, info->a_init, info->a_end, info->n_gas, info->n_dm);
std::fflush(stdout);
return 0;
}
int on_pre_pm(const GravPluginStepInfo* /*st*/) {
++g_pre_pm_calls;
return 0;
}
int on_post_kick(const GravPluginStepInfo* /*st*/) {
++g_post_kick_calls;
return 0;
}
int on_snapshot(const GravPluginStepInfo* st) {
++g_snapshot_calls;
std::printf("EXAMPLE_PLUGIN snapshot step=%d a=%.5f\n", st->step, st->a);
std::fflush(stdout);
return 0;
}
void on_finalize() {
std::printf("EXAMPLE_PLUGIN finalize pre_pm=%d post_kick=%d snapshots=%d\n",
g_pre_pm_calls, g_post_kick_calls, g_snapshot_calls);
std::fflush(stdout);
}
const GravPluginVTable kVTable = {
GRAV_PLUGIN_ABI_VERSION,
"example_diagnostics",
"1.0.0",
on_init,
on_pre_pm,
on_post_kick,
on_snapshot,
on_finalize,
};
} // namespace
extern "C" const GravPluginVTable* grav_plugin_register(void) {
return &kVTable;
}