Peano 4
No Matches
planet-orbit Namespace Reference


 parser = argparse.ArgumentParser(description="SPH benchmarking script")
 Parse user input.
 args = parser.parse_args()
 dimensions = args.dimensions
 Generate SWIFT project.
 particle_set = project.add_particle_species(particle)
 energy_kin_attr = dastgen2.attributes.Double("energyKin")
 energy_pot_attr = dastgen2.attributes.Double("energyPot")
 energy_tot_attr = dastgen2.attributes.Double("energyTot")
 build_mode = peano4.output.CompileMode.Asserts
list offset = [0, 0, 0]
list domain_size = [1, 1, 1]
list periodic_boundary_conditions = [False, False, False]
int N_orbits = 8
float G_NEWTON = 6.67384e-11
float M_SUN = 1.9885e30
float M_EARTH = 5.97219e24
float R_MAX = 152097701000.0
float R_MIN = 147098074000.0
float V_MAX = 30287.0
float LENGTH_UNIT = 4.0 * R_MAX
 SUN_X_COORD = str(0.5)
 SUN_Y_COORD = str(0.5)
tuple e = (R_MAX - R_MIN) / (R_MAX + R_MIN)
 b = np.sqrt(R_MAX * R_MIN)
 p = b * np.sqrt(1.0 - e * e)
 a = p / (1.0 - e * e)
 T = np.sqrt(4.0 * np.pi * np.pi * a * a * a / (G_NEWTON * (M_SUN + M_EARTH)))
int dt = 1e-3 * T
int N = N_orbits / dt
 EARTH_V_INI_X = str(0.0)
str particle_force
 Declare the force acting on the particle.
float search_radius = args.cell_size / 100.0
 Initialisation snippet for the particle.
tuple initialisation_snippet
 Set up the plotter.
 peano4_project = project.generate_Peano4_project(verbose=args.verbose)
 Generate plain Peano 4 project.
list dirs = ["vertexdata/", "repositories/", "globaldata/", "observers/"]
list output_files

Variable Documentation

◆ a

planet-orbit.a = p / (1.0 - e * e)

Definition at line 231 of file

◆ action


Definition at line 23 of file

◆ Always


Definition at line 521 of file

◆ args

planet-orbit.args = parser.parse_args()

Definition at line 93 of file

◆ b

planet-orbit.b = np.sqrt(R_MAX * R_MIN)

Definition at line 227 of file

◆ build_mode

planet-orbit.build_mode = peano4.output.CompileMode.Asserts

Definition at line 170 of file

◆ cell_kernel


Definition at line 334 of file

◆ choices


Definition at line 89 of file

◆ default


Definition at line 17 of file

◆ dest


Definition at line 17 of file

◆ dimensions

planet-orbit.dimensions = args.dimensions

Generate SWIFT project.

Definition at line 100 of file

◆ dirs

list planet-orbit.dirs = ["vertexdata/", "repositories/", "globaldata/", "observers/"]

Definition at line 516 of file

◆ domain_size

planet-orbit.domain_size = [1, 1, 1]

Definition at line 175 of file

◆ dt

int planet-orbit.dt = 1e-3 * T

Definition at line 237 of file

◆ e

tuple planet-orbit.e = (R_MAX - R_MIN) / (R_MAX + R_MIN)

Definition at line 225 of file


planet-orbit.EARTH_V_INI_X = str(0.0)

Definition at line 244 of file


planet-orbit.EARTH_V_INI_Y = str(V_MAX / LENGTH_UNIT * T)

Definition at line 245 of file


planet-orbit.EARTH_X_INI = str(float(SUN_X_COORD) + R_MAX / LENGTH_UNIT)

Definition at line 221 of file


planet-orbit.EARTH_Y_INI = SUN_Y_COORD

Definition at line 222 of file

◆ energy_kin_attr

planet-orbit.energy_kin_attr = dastgen2.attributes.Double("energyKin")

Definition at line 159 of file

◆ energy_pot_attr

planet-orbit.energy_pot_attr = dastgen2.attributes.Double("energyPot")

Definition at line 160 of file

◆ energy_tot_attr

planet-orbit.energy_tot_attr = dastgen2.attributes.Double("energyTot")

Definition at line 161 of file

◆ first_plot_time_stamp


Definition at line 184 of file


float planet-orbit.G_NEWTON = 6.67384e-11

Definition at line 204 of file


planet-orbit.GLOBAL_TIME_STEP_SIZE = str(dt)

Definition at line 241 of file

◆ help

Definition at line 17 of file

◆ initialisation_snippet

tuple planet-orbit.initialisation_snippet
Initial value:
1= (
3 + str(search_radius)
4 +

Definition at line 350 of file

◆ int

Definition at line 17 of file


float planet-orbit.LENGTH_UNIT = 4.0 * R_MAX

Definition at line 218 of file


float planet-orbit.M_EARTH = 5.97219e24

Definition at line 208 of file


float planet-orbit.M_SUN = 1.9885e30

Definition at line 206 of file

◆ make_clean_first


Definition at line 523 of file

◆ max_end_time


Definition at line 183 of file

◆ min_end_time


Definition at line 182 of file

◆ N

int planet-orbit.N = N_orbits / dt

Definition at line 240 of file

◆ N_orbits

int planet-orbit.N_orbits = 8

Definition at line 202 of file

◆ number_of_parallel_builds


Definition at line 523 of file

◆ offset

planet-orbit.offset = [0, 0, 0]

Definition at line 174 of file

◆ output_files

list planet-orbit.output_files
Initial value:
1= [
2 f
3 for f in os.listdir(".")
4 if f.endswith(".peano-patch-file") or f.endswith(".vtu") or f.endswith(".pvd")

Definition at line 526 of file

◆ overwrite


Definition at line 521 of file

◆ p

planet-orbit.p = b * np.sqrt(1.0 - e * e)

Definition at line 229 of file

◆ parser

planet-orbit.parser = argparse.ArgumentParser(description="SPH benchmarking script")

Parse user input.

Definition at line 15 of file

◆ particle

Initial value:
2 name="Planet",
3 cfl_factor=0.2,
4 initial_time_step_size=args.timestep_size,
5 particles_per_cell=0,
6 min_h=args.cell_size,
7 max_h=0.3,
8 )

Definition at line 124 of file

◆ particle_force

str planet-orbit.particle_force

Declare the force acting on the particle.

We effectively solve a 2d setup even in 3d. Peano's vector classes can be used over the compiler symbol Dimensions, but then we have to use different initialisation lists - one with two entries and one if three - and distinguish them via an ifdef. If we compile without assertions, an additional entry in the initialisation list will simply be ignored. If we compile with assertions however the code will complain, as initialisation lists with "too many" entries are a hint that something in the code is wrong.

We have two variants covered by this script: Either we work with only one particle or we resolve the sun explicitly. If we model the sun as explicit particle, then we have to be careful not to update it.

The code snippets here rely on some global constants that we compute here in the Python code base. We have various ways how to deal with such constants:

  • We can calculate them within Python and then export them into the Peano project. This is the strategy implemented here: The statements
    below make the constants known to the build environment. Consequently, we can use them within our C code snippets, as they will be well-defined by the time we compile.
  • We can construct the string in Python and replace the constants straightaway. In this case, we don't have to add the constants to the makefile, as they are not required throughout the compile. In return, we have to ensure that the constants within the code snippet here are replaced with their actual value before we hand the kernel particle_force over.

Definition at line 289 of file

◆ particle_plotter

Initial value:
2 "particles",
3 particle_set,
4 "globaldata::{}::getSpecies().getMinTimeStamp()".format(,

Set up the plotter.

A plotter has to be told explicitly which data to visualisation. We visualise the velocity here as scalar attribute. To some degree, this is redundant info as we implicitly have the position of the particle and can "see" its velocity when we play through a movie. But the explicit visualisation shows how to handle attributes per particle.

When we create the plotter, we have to inform it how to enumerate the individual snapshots. Obviously, we can just count through the snapshots. In this case, you have to pass the constant peano4.toolbox.particles.PlotParticlesInVTKFormat.CountTimeSteps into the field time_stamp_evaluation. You can also define your own time stamp. For this, it is useful to know that each particle definition in the Python script will yield a particle class with the same name in the subnamespace globaldata. Every particle class in return has a class attribute


which returns an object that holds global information about this particle type.

Definition at line 446 of file

◆ particle_set

planet-orbit.particle_set = project.add_particle_species(particle)

Definition at line 132 of file

◆ peano4_project

planet-orbit.peano4_project = project.generate_Peano4_project(verbose=args.verbose)

Generate plain Peano 4 project.

See commments above (for the force interaction kernel) why we might want to have some of the constants from the Python script within the C++ code base that's generated.

! [tutorials swift2 planet-orbit Create Peano project]

Definition at line 479 of file

◆ periodic_BC


Definition at line 186 of file

◆ periodic_boundary_conditions

list planet-orbit.periodic_boundary_conditions = [False, False, False]

Definition at line 176 of file

◆ plotter_precision


Definition at line 187 of file

◆ project

Initial value:
2 namespace=["tests", "swift2", "planetorbit"],
3 project_name="planetorbit",
4 executable="orbit-" + str(args.cell_size),
Swift2 project.

Definition at line 104 of file


float planet-orbit.R_MAX = 152097701000.0

Definition at line 210 of file


float planet-orbit.R_MIN = 147098074000.0

Definition at line 212 of file

◆ required


Definition at line 90 of file

◆ search_radius

float planet-orbit.search_radius = args.cell_size / 100.0

Initialisation snippet for the particle.

If we work with only one particle, then we can simply set its velocity. However, our script works both if we only module the earth but also when we model earth and sun explicitly. In the latter case, we have to ensure that only the earth is given an initial velocity.

Definition at line 349 of file


planet-orbit.SUN_X_COORD = str(0.5)

Definition at line 219 of file


planet-orbit.SUN_Y_COORD = str(0.5)

Definition at line 220 of file

◆ T

planet-orbit.T = np.sqrt(4.0 * np.pi * np.pi * a * a * a / (G_NEWTON * (M_SUN + M_EARTH)))

Definition at line 233 of file

◆ throw_away_data_after_generation


Definition at line 521 of file

◆ time_in_between_plots


Definition at line 185 of file

◆ True


Definition at line 523 of file

◆ type


Definition at line 17 of file


float planet-orbit.V_MAX = 30287.0

Definition at line 214 of file