sandbox/larswd/test_prestore.c
Test for pdump
and
prestore
Here we test if particles are dumped and restored correctly with
_MPI
.
There will be a four particle lists in this test,
#include "particle.h"
#include "view.h"
#include "scatter2.h"
Particles zeroth, first, second, third;
A helper function to view the particle locations and the
pid()
is defined below.
void plot (char * fname, Particles * list) {
foreach_P_in_list (list) {
translate (z = 0.005)
scatter (P, pc = {cos(P), sin(P), sin(P*1.4)});
scatter (P, s = 50,
= {sin(pid()), cos(pid()), sin(pid()*2.4)});
pc }
translate (z = -0.01)
cells();
save (fname);
}
int main() {
= Y0 = -L0/2;
X0 (4);
init_grid refine (x + y < 0 && level < 3);
For testing purposes, the zeroth list is empty.
= new_particles (0); zeroth
The first list contains particles at cell centers.
int n = 0;
foreach()
++;
n= new_particles (n);
first place_in_cells (first);
The second and third list are 25 and 30 particles in a square and circle, respectively.
if (pid() == 0) {
= new_particles (25);
second = new_particles (30); third

invalid use of undefined type ‘struct Init_P’
place_in_square (second, (struct Init_P){5});

invalid use of undefined type ‘struct Init_P’
place_in_circle (third, (struct Init_P){30, 0.25, 0.25, L0/8.});
} else {
= new_particles (0);
second = new_particles (0);
third }
Particles pall[4] = {zeroth, first, second, third};
foreach_P_in_list (pall)
particle_boundary (P);
Particles Plist[3] = {zeroth, first, third};
plot ("all.png", pall);
plot ("Plist.png", Plist);
The particle locations with list
center-colour coding
and pid()
ring colour.


The particles in the Plist
particles lists are
dumped.
pdump ("dumplist", Plist);
We create a new grid, randomize the old particles.
(4);
init_grid refine (x + y > 0 && level < 3);
foreach_particle()
foreach_dimension()
().x = 0.75*noise();
pplot ("pmess.png", pall);
Particles are a mess before restoring

Now some data is restored:
("dumplist"); prestore
The Plist
may need be redefined for further usage.
// Plist[0] = zeroth = 0;
// Plist[1] = first = 1;
[2] = third = 2;
Plistplot ("restored.png", Plist);
The result:

Close inspection of the colour codes learns that everything went well!
free_p ();
}