Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
slave.h
Go to the documentation of this file.
1/** @file slave.h
2 */
3/**
4# Coupled slave
5
6This can be used in combination with [master.h]() to couple two
7Basilisk solvers.
8
9## Example of coupling function
10
11This is a simple function which can be called by the master to
12retrieve (interpolated) field values from the slave.
13
14Using this model, it should be easy to write more sophisticated
15coupling functions, if necessary.
16
17Note that new coupling functions must be added to the list of symbols
18which are exported. See the recipe for `slave.o` in the examples
19[Makefile](/src/examples/Makefile) for details. */
20
21double slave_interpolate (const char * name, double xp, double yp, double zp, bool linear)
22{
23 if (!grid) {
24 fprintf (stderr, "slave_interpolate: error: no grid! this may be a "
25 "master/slave synchronization issue\n");
26 exit (1);
27 }
28 scalar s = lookup_field (name);
29 if (s.i < 0) {
30 fprintf (stderr, "slave_interpolate: error: unknown field '%s'\n", name);
31 exit (1);
32 }
33 return interpolate (s, xp, yp, zp, linear);
34}
35
36/**
37## Synchronization functions
38
39These functions are called by the master to synchronize the
40master/slave times. */
41
42#if _OBJECT
43event slave_event (t <= HUGE);
44
45void slave_step (double t0)
46{
47 static Event * slave = NULL;
48 if (!slave) {
50 int slave_init();
51 slave_init();
52 init_grid (N);
53
54 for (Event * ev = Events; !ev->last; ev++)
55 if (!strcmp (ev->name, "slave_event")) {
56 slave = ev;
57 break;
58 }
59 assert (slave);
60
61 iter = 0, t = 0., dt = 1.;
62 events (true);
63 iter = inext, t = tnext;
64 }
65
66 slave->t = t0;
67 while (t0 - t > TEPS*t0 && events (true))
68 iter = inext, t = tnext;
69}
70
71void slave_stop()
72{
73 free_grid();
74}
75
76/**
77When this file is included in a simulation (i.e. compiled as an
78object), the main() and run() functions are overloaded, since the
79master main() function will drive the simulation. */
80
81# define main() slave_init()
82# define run() return 0
83#endif // _OBJECT
84
trace double interpolate(scalar v, double xp=0., double yp=0., double zp=0., bool linear=true)
int x
Definition common.h:76
#define HUGE
Definition common.h:6
int N
Definition common.h:39
Grid * grid
Definition common.h:32
#define assert(a)
Definition config.h:107
double dt
scalar s
Definition embed-tree.h:56
double t
Definition events.h:24
static Event * Events
Definition events.h:21
int inext
Definition events.h:23
int iter
Definition events.h:23
double tnext
Definition events.h:24
static double TEPS
Definition events.h:35
static void _init_solver(void)
#define free_grid()
Definition grid.h:1404
#define init_grid(n)
Definition grid.h:1402
int events
Definition qcc.c:60
double slave_interpolate(const char *name, double xp, double yp, double zp, bool linear)
Definition slave.h:21
Definition events.h:6
int last
Definition events.h:7
int i
Definition common.h:44
scalar lookup_field(const char *name)
These functions return the scalar/vector fields called name, or -1 if they don't exist.
Definition utils.h:321