Peano
Loading...
Searching...
No Matches
taylor-green-vortex.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import peano4
4import exahype2
5
6from PDE import max_eigenvalue, flux
7
8initial_conditions = """
9 constexpr double U0 = 1.0; // Initial amplitude of velocity
10 constexpr double Pressure0 = 100 / GAMMA; // Reference pressure
11
12 Q[Shortcuts::rho] = 1.0;
13 Q[Shortcuts::rhoU + 0] = U0 * std::sin(x(0)) * std::cos(x(1));
14 Q[Shortcuts::rhoU + 1] = -U0 * std::cos(x(0)) * std::sin(x(1));
15#if DIMENSIONS == 3
16 Q[Shortcuts::rhoU + 2] = 0.0;
17#endif
18
19 const double pressure = Pressure0 + (Q[Shortcuts::rho] * U0) * (1.0 / 4.0) * (std::cos(2.0 * x(0)) + std::cos(2.0 * x(1)));
20 // Total energy: internal energy + kinetic energy
21 Q[Shortcuts::rhoE] = pressure / (GAMMA - 1.0) + 0.5 * (Q[Shortcuts::rhoU + 0] * Q[Shortcuts::rhoU + 0] + Q[Shortcuts::rhoU + 1] * Q[Shortcuts::rhoU + 1]);
22"""
23
24boundary_conditions = """
25"""
26
27refinement_criterion = """
28 auto result = ::exahype2::RefinementCommand::Keep;
29 return result;
30"""
31
32analytical_solution = """
33 constexpr double Viscosity = 1.0;
34 const double C = 100.0 / GAMMA;
35
36 // Time decay factors for velocity and pressure
37 const double expVelocityFactor = std::exp(-2.0 * Viscosity * t); // Time decay factor for velocity
38 const double expPressureFactor = std::exp(-4.0 * Viscosity * t); // Time decay factor for pressure
39
40 // Set the initial conditions for the Taylor-Green vortex
41 solution[Shortcuts::rho] = 1.0; // Constant density
42
43 // Velocity components with time decay
44 solution[Shortcuts::rhoU + 0] = expVelocityFactor * std::sin(x(0)) * std::cos(x(1));
45 solution[Shortcuts::rhoU + 1] = -expVelocityFactor * std::cos(x(0)) * std::sin(x(1));
46#if DIMENSIONS == 3
47 solution[Shortcuts::rhoU + 2] = 0.0;
48#endif
49
50 // Pressure with time decay and the given formula
51 double pressure = expPressureFactor * (std::cos(2.0 * x(0)) + std::cos(2.0 * x(1)))*(1.0 / 4.0) + C;
52
53 // Total energy: internal energy + kinetic energy
54 solution[Shortcuts::rhoE] = pressure / (GAMMA - 1.0) + 0.5 * (Q[Shortcuts::rhoU + 0] * Q[Shortcuts::rhoU + 0] + Q[Shortcuts::rhoU + 1] * Q[Shortcuts::rhoU + 1]);
55"""
56
57parser = exahype2.ArgumentParser("ExaHyPE 2 - Finite Volumes Testing Script")
58parser.set_defaults(
59 min_depth=6,
60 degrees_of_freedom=16,
61 number_of_snapshots=0,
62 periodic_boundary_conditions_x=True,
63 periodic_boundary_conditions_y=True,
64 periodic_boundary_conditions_z=True,
65)
66args = parser.parse_args()
67
68size = [2 * 3.14159265359, 2 * 3.14159265359, 2 * 3.14159265359]
69max_h = 1.1 * min(size) / (3.0**args.min_depth)
70min_h = max_h * 3.0 ** (-args.amr_levels)
71
72fv_solver = exahype2.solvers.fv.musclhancock.GlobalAdaptiveTimeStep(
73 name="FVSolver",
74 patch_size=args.degrees_of_freedom,
75 unknowns={"rho": 1, "rhoU": args.dimensions, "rhoE": 1},
76 auxiliary_variables=0,
77 min_volume_h=min_h,
78 max_volume_h=max_h,
79 time_step_relaxation=0.5,
80 use_enclave_tasking=args.enclave_tasking,
81 number_of_enclave_tasks=args.ntasks,
82)
83
84fv_solver.set_implementation(
85 initial_conditions=initial_conditions,
86 boundary_conditions=boundary_conditions,
87 refinement_criterion=refinement_criterion,
88 max_eigenvalue=max_eigenvalue,
89 flux=flux,
90 limiter=exahype2.solvers.fv.musclhancock.Limiter.vanalbada,
91)
92
93fv_solver.set_plotter(peano4.plotter.VTUPatchAMRPlotter)
94
95exahype2.solvers.fv.ErrorMeasurement(
96 fv_solver,
97 error_measurement_implementation=analytical_solution,
98 output_file_name="Error",
99)
100
101project = exahype2.Project(
102 namespace=["tests", "exahype2", "fv"],
103 project_name="TaylorGreenVortex",
104 directory=".",
105 executable="ExaHyPE",
106)
107project.add_solver(fv_solver)
108
109if args.number_of_snapshots <= 0:
110 time_in_between_plots = 0.0
111else:
112 time_in_between_plots = args.end_time / args.number_of_snapshots
113 project.set_output_path(args.output)
114
115project.set_global_simulation_parameters(
116 dimensions=args.dimensions,
117 size=size[0 : args.dimensions],
118 offset=[0.0, 0.0, 0.0][0 : args.dimensions],
119 min_end_time=args.end_time,
120 max_end_time=args.end_time,
121 first_plot_time_stamp=0.0,
122 time_in_between_plots=time_in_between_plots,
123 periodic_BC=[
124 args.periodic_boundary_conditions_x,
125 args.periodic_boundary_conditions_y,
126 args.periodic_boundary_conditions_z,
127 ],
128)
129
130project.set_load_balancer(
131 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees})"
132)
133project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
134project = project.generate_Peano4_project(verbose=False)
135project.output.makefile.set_target_device(args.target_device)
136project.output.makefile.add_CXX_flag("-DGAMMA=1.4")
137project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)