Peano
Loading...
Searching...
No Matches
dastgen-test.py
Go to the documentation of this file.
1import os
2import argparse
3import numpy as np
4
5import peano4.api
6import exaparty
7import dastgen2
8from exaparty.api.particle.tests import DastgenTestDummyParticle
9
10import shutil
11
12
13
16
17parser = argparse.ArgumentParser(description="Dastgen2 testing script")
18parser.add_argument(
19 "-j", "--parallel-builds", dest="j", type=int, default=-1, help="Parallel builds"
20)
21parser.add_argument(
22 "-v",
23 "--verbose",
24 dest="verbose",
25 action="store_true",
26 default=False,
27 help="Verbose",
28)
29parser.add_argument(
30 "-pd",
31 "--peano-dir",
32 dest="peanodir",
33 default="../../..",
34 help="Peano4 directory",
35)
36args = parser.parse_args()
37
38
39
42
43project_namespace = ["tests", "exaparty", "dastgenTest"]
44
46 namespace=project_namespace, project_name="dastgen_test", executable="dastgen_test"
47)
48
49
50# Initialise the Dummy particle --------------------------------------------------
51dimensions = 2 # Peano dimensions
52cell_size = 0.3
53
54
56 "dummyPart",
57 particles_per_cell=20,
58 min_h=cell_size / 100,
59 max_h=cell_size,
60)
61
62# Add particle to project --------------------------------------------
63# Notice that any change to the particle will not take effect after adding
64# the particle_set to the project
65particle_set = project.add_particle_species(particle)
66
67# Always build with asserts on.
68build_mode = peano4.api.output.CompileMode.ASSERTS
69
70# Set Peano4 simulation parameters ---------------------------------------------
71offset = [0, 0, 0]
72domain_size = [1, 1, 1]
73periodic_boundary_conditions = [False, False, False]
74
75project.set_global_simulation_parameters(
76 dimensions=dimensions,
77 offset=offset,
78 domain_size=domain_size,
79 min_end_time=1.0,
80 max_end_time=1.0,
81 first_plot_time_stamp=0.0,
82 time_in_between_plots=1.0,
83 periodic_BC=periodic_boundary_conditions,
84 plotter_precision=8,
85)
86
87project.set_Peano4_installation(args.peanodir, build_mode)
88project._project.output.makefile.add_cpp_file("DastgenTest.cpp", generated=False)
89
90
91
92
95
96# Set up the coordinates for the particles
97# We construct a regular (lattice) configuration.
98Npart = 10
99offset = 1 / Npart
100
101# This should always be a 3D array, even if you are using fewer
102# dimensions in your actual run
103coords = np.zeros((Npart**dimensions, 3))
104
105x = np.linspace(offset, 1, Npart, endpoint=False)
106y = np.linspace(offset, 1, Npart, endpoint=False)
107
108xp, yp = np.meshgrid(x, y)
109xp = xp.reshape((np.prod(xp.shape),))
110yp = yp.reshape((np.prod(yp.shape),))
111
112coords[:, 0] = xp
113coords[:, 1] = yp
114
115initialisation_snippet = """
116 /*
117 * Initial Conditions: None. The dummy particles aren't even proper SPH
118 * particles. Notably, they don't even contain fields like mass, density,
119 * etc. Nothing to do here except read in particle positions (which is
120 * done elsewhere) and give particles a search radius, which needs to
121 * exist.
122 */
123 tarch::la::Vector<Dimensions,double> GridSize = marker.h();
124 const double GridSize_x = GridSize(0);
125 particle->setSearchRadius( GridSize_x / 4.0);
126"""
127
128# Finally, pass this configuration to the initialisation script
129project.algorithm_step_initial_conditions.add_action_set(
131 particle_set=particle_set,
132 initialisation_call=initialisation_snippet,
133 coordinates=coords,
134 additional_includes="",
135 )
136)
137
138
139
142
143peano4_project = project.generate_Peano4_project(verbose=args.verbose)
144
145
146
149
150# Always build project from scratch
151dirs = ["vertexdata/", "repositories/", "globaldata/", "observers/"]
152for dir in dirs:
153 if os.path.exists(dir):
154 shutil.rmtree(dir)
155
156# It is safe (and recommended) to overwrite any existing main file, since this
157# is generated automatically by the ExaParty graph compiler.
158peano4_project.generate(
159 overwrite=peano4.api.output.Overwrite.Always, throw_away_data_after_generation=True
160)
161peano4_project.build(make_clean_first=True, number_of_parallel_builds=args.j)
162
163# remove output files from previous runs
164output_files = [
165 f
166 for f in os.listdir(".")
167 if f.endswith(".peano-patch-file") or f.endswith(".vtu") or f.endswith(".pvd")
168]
169for f in output_files:
170 os.remove(f)
ExaParty project.
Definition Project.py:27
A dummy particle containing meaningless variables to test the functionality of dastgen2.
This file is part of the ExaParty project.
Definition __init__.py:1