15parser = argparse.ArgumentParser(description=
"SPH benchmarking script")
17 "-j",
"--parallel-builds", dest=
"j", type=int, default=-1, help=
"Parallel builds"
30 dest=
"clean_temporary_directories",
32 help=
"Remove temporary directories before script starts",
40 help=
"Spatial dimensions (default 2)",
48 help=
"End of simulation",
56 help=
"Global timestep size (initial value)",
64 help=
"Plot delta (0 switches off)",
72 help=
"Cell size (default 0.3)",
75 "-pd",
"--peano-dir", dest=
"peanodir", default=
"../../..", help=
"Peano4 directory"
83 help=
"Switch on assertions",
88 dest=
"time_integrator",
89 choices=[
"leapfrog",
"euler",
"euler-dynamic",
"Euler",
"Euler-dynamic"],
91 help=
"Type of time integrator to use (default: leapfrog)",
93args = parser.parse_args()
100dimensions = args.dimensions
105 namespace=[
"tests",
"swift2",
"planetorbit"],
106 project_name=
"planetorbit",
107 executable=
"orbit-" + str(args.cell_size),
113Declare the particle type:
114We need to specify the time integration scheme that will be used to evolve
115this particle. Current choices include:
117 - Explicit Euler with fixed search radius
118 - Explicit Euler with variable search radius
122if args.time_integrator ==
"leapfrog":
127 initial_time_step_size=args.timestep_size,
128 particles_per_cell=0,
129 min_h=args.cell_size,
132 particle_set = project.add_particle_species(particle)
134elif args.time_integrator ==
"euler" or "Euler":
138 initial_time_step_size=args.timestep_size,
139 particles_per_cell=0,
140 min_h=args.cell_size,
143 particle_set = project.add_particle_species(particle)
144elif args.time_integrator ==
"euler-dynamic" or "Euler-dynamic":
148 initial_time_step_size=args.timestep_size,
149 particles_per_cell=0,
150 min_h=args.cell_size,
153 particle_set = project.add_particle_species(particle)
155 print(
"Time integrator not supported. Please check the list of options.")
162particle.data.add_attribute(energy_kin_attr)
163particle.data.add_attribute(energy_pot_attr)
164particle.data.add_attribute(energy_tot_attr)
170 build_mode = peano4.output.CompileMode.Asserts
172 build_mode = peano4.output.CompileMode.Release
175domain_size = [1, 1, 1]
176periodic_boundary_conditions = [
False,
False,
False]
178project.set_global_simulation_parameters(
179 dimensions=dimensions,
181 domain_size=domain_size,
182 min_end_time=args.end_time,
184 first_plot_time_stamp=0.0,
185 time_in_between_plots=args.plot_delta,
186 periodic_BC=periodic_boundary_conditions,
190project.set_load_balancing(
191 "toolbox::loadbalancing::strategies::SpreadOutHierarchically",
192 "new toolbox::loadbalancing::DefaultConfiguration()",
195project.set_Peano4_installation(args.peanodir, build_mode)
203G_NEWTON = 6.67384e-11
209R_MAX = 152097701000.0
211R_MIN = 147098074000.0
217LENGTH_UNIT = 4.0 * R_MAX
218SUN_X_COORD = str(0.5)
219SUN_Y_COORD = str(0.5)
220EARTH_X_INI = str(float(SUN_X_COORD) + R_MAX / LENGTH_UNIT)
221EARTH_Y_INI = SUN_Y_COORD
224e = (R_MAX - R_MIN) / (R_MAX + R_MIN)
226b = np.sqrt(R_MAX * R_MIN)
228p = b * np.sqrt(1.0 - e * e)
232T = np.sqrt(4.0 * np.pi * np.pi * a * a * a / (G_NEWTON * (M_SUN + M_EARTH)))
240GLOBAL_TIME_STEP_SIZE = str(dt)
243EARTH_V_INI_X = str(0.0)
244EARTH_V_INI_Y = str(V_MAX / LENGTH_UNIT * T)
287// Template in tests/swift2/planet-orbit.py
289::swift2::kernels::forAllParticles(
292 numberOfCoalescedLocalParticlesPerVertex,
294 const peano4::datamanagement::CellMarker& marker,
295 globaldata::Planet& localParticle
297 if ( ::swift2::kernels::localParticleCanBeUpdatedInCellKernel(
302 tarch::la::Vector<Dimensions,double> pos_sun = {SUN_X_COORD,SUN_Y_COORD};
304 tarch::la::Vector<Dimensions,double> pos_sun = {SUN_X_COORD,SUN_Y_COORD,0.0};
307 /* G_NEWTON in internal units */
308 double const L3 = LENGTH_UNIT * LENGTH_UNIT * LENGTH_UNIT;
309 double const T2 = PERIOD * PERIOD;
310 double const GN = G_NEWTON * M_SUN * T2 / L3;
313 tarch::la::Vector<Dimensions,double> earthSunDistance = localParticle.getX() - pos_sun;
314 const double r = tarch::la::norm2(earthSunDistance);
315 if (tarch::la::greater(r,0.0)) {
316 const double r_inv = 1.0 / r;
317 localParticle.setA( - GN * earthSunDistance * (r_inv * r_inv * r_inv) );
320 const double vel = tarch::la::norm2( localParticle.getV() );
321 const double E_kin = 0.5 * vel * vel;
322 const double E_pot = - GN * r_inv;
324 /* Update total energy (overall minus sign) */
325 localParticle.setEnergyKin( E_kin );
326 localParticle.setEnergyPot(-E_pot );
327 localParticle.setEnergyTot( - ( E_kin + E_pot ) );
328 } // end of radius check
329 } // end of "may I update" check
331 ::swift2::kernels::alwaysUpdateInCellKernel<globaldata::Planet>
337particle.cell_kernel = particle_force
352search_radius = args.cell_size / 100.0
353initialisation_snippet = (
356 * In this problem we will initialize just a single particle (Earth)
357 * This will orbit around a point where the hypothetical Sun is (no particle needed here)
360 /* Internal search radius used by Peano.
361 * Should always be larger than actual SPH interaction radius (~2h).
362 * But no really used here. */
363 particle->setSearchRadius("""
366 particle->setV( {0, 0, 0} );
367 particle->setA( {0, 0, 0} );
369 // Orbiting particle: We can also have a free moving sun, but by default, this
370 // one rests and the earth is actually orbiting.
371 if( particle->getX(0) == EARTH_X_INI ){
372 particle->setV(0, EARTH_V_INI_X) ;
373 particle->setV(1, EARTH_V_INI_Y) ;
380 /* G_NEWTON in internal units */
381 double const L3 = LENGTH_UNIT * LENGTH_UNIT * LENGTH_UNIT;
382 double const T2 = PERIOD * PERIOD;
383 double const GN = G_NEWTON * M_SUN * T2 / L3;
385 /* Sun-Earth initial distance */
386 const double r_ini = particle->getX()(0) - SUN_X_COORD;
387 const double r_inv = r_ini ? 1.0 / r_ini : 0.0;
388 const double vel = tarch::la::norm2( particle->getV() );
390 const double E_kin = 0.5 * vel * vel;
391 const double E_pot = - GN * r_inv;
393 particle->setEnergyKin( E_kin );
394 particle->setEnergyPot(-E_pot );
396 /* Overall minus sign for plotting */
397 particle->setEnergyTot( -( E_kin + E_pot ) );
399 logInfo( "Init()", "=====================================" );
400 logInfo( "Init()", "Initial energy:");
401 logInfo( "Init()", "Kinetic energy :" << E_kin);
402 logInfo( "Init()", "Potential energy:" << E_pot);
403 logInfo( "Init()", "Total energy :" << E_kin + E_pot);
404 logInfo( "Init()", "Search Radius :" << particle->getSearchRadius() );
405 logInfo( "Init()", "Initial velocity:" << particle->getV() );
406 logInfo( "Init()", "=====================================" );
415project.algorithm_step_initial_conditions.add_action_set(
417 particle_set=particle_set,
418 initialisation_call=initialisation_snippet,
419 coordinates=[(EARTH_X_INI, EARTH_Y_INI, 0)],
452 "globaldata::{}::getSpecies().getMinTimeStamp()".format(particle.name),
454particle_plotter.add_attribute_to_plot(particle.velocity, dimensions)
455particle_plotter.add_attribute_to_plot(energy_kin_attr, 1)
456particle_plotter.add_attribute_to_plot(energy_pot_attr, 1)
457particle_plotter.add_attribute_to_plot(energy_tot_attr, 1)
458project.algorithm_step_plot.add_action_set(particle_plotter)
463particle.add_to_reduction(
465nonCriticalAssertion( vertexdata::{particle.name}Set::getNumberOfRemainingLocalParticles() == 1 );
481peano4_project = project.generate_Peano4_project(verbose=args.verbose)
488peano4_project.output.makefile.add_CXX_flag(
"-D" +
"HYDRO_DIMENSION=1")
489peano4_project.output.makefile.add_CXX_flag(
"-D" +
"HYDRO_GAMMA_5_3")
490peano4_project.output.makefile.add_CXX_flag(
"-D" +
"QUARTIC_SPLINE_KERNEL")
492peano4_project.constants.export_const_with_type(
493 "GLOBAL_TIME_STEP_SIZE", GLOBAL_TIME_STEP_SIZE,
"double"
495peano4_project.constants.export_const_with_type(
"G_NEWTON", str(G_NEWTON),
"double")
496peano4_project.constants.export_const_with_type(
497 "LENGTH_UNIT", str(LENGTH_UNIT),
"double"
499peano4_project.constants.export_const_with_type(
"M_SUN", str(M_SUN),
"double")
500peano4_project.constants.export_const_with_type(
"SUN_X_COORD", SUN_X_COORD,
"double")
501peano4_project.constants.export_const_with_type(
"SUN_Y_COORD", SUN_Y_COORD,
"double")
502peano4_project.constants.export_const_with_type(
"EARTH_X_INI", EARTH_X_INI,
"double")
503peano4_project.constants.export_const_with_type(
"EARTH_Y_INI", EARTH_Y_INI,
"double")
504peano4_project.constants.export_const_with_type(
505 "EARTH_V_INI_X", EARTH_V_INI_X,
"double"
507peano4_project.constants.export_const_with_type(
508 "EARTH_V_INI_Y", EARTH_V_INI_Y,
"double"
510peano4_project.constants.export_const_with_type(
"ECCENTRICITY", str(e),
"double")
511peano4_project.constants.export_const_with_type(
"PERIOD", str(T),
"double")
512peano4_project.constants.export_const_with_type(
"R_MIN", str(R_MIN),
"double")
513peano4_project.constants.export_const_with_type(
"R_MAX", str(R_MAX),
"double")
517if args.clean_temporary_directories:
518 dirs = [
"vertexdata/",
"repositories/",
"globaldata/",
"observers/"]
522peano4_project.generate(
523 overwrite=peano4.output.Overwrite.Always, throw_away_data_after_generation=
True
525peano4_project.build(make_clean_first=
True, number_of_parallel_builds=args.j)
530 for f
in os.listdir(
".")
531 if f.endswith(
".peano-patch-file")
or f.endswith(
".vtu")
or f.endswith(
".pvd")
533for f
in output_files:
cardinality is a string (you can thus use symbols as well as long as they will be defined at compile ...
For constructor's time_stamp_evaluation argument.
Extension of the explicit Euler to support dynamic search radius adoption.
Simple particle with fixed search radius subject to explicit Euler.