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