Peano
Loading...
Searching...
No Matches
advection.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
6parser = exahype2.ArgumentParser(
7 "ExaHyPE 2 - Finite Volumes Dynamic AMR Testing Script"
8)
9parser.set_defaults(
10 min_depth=2,
11 amr_levels=4,
12 degrees_of_freedom=4,
13 end_time=1.5,
14 number_of_snapshots=0,
15)
16args = parser.parse_args()
17
18max_patch_size = 1.1 * 2.0 / (3.0**args.min_depth)
19max_h = max_patch_size / args.degrees_of_freedom
20min_h = 0.9 * max_h * 3.0 ** (-args.amr_levels)
21
22initial_conditions = """
23 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
24 Q[i] = 0.0;
25 }
26
27 constexpr double radius = 0.1;
28
29#if DIMENSIONS == 3
30 tarch::la::Vector<DIMENSIONS, double> centre = {0.75, 1.0, 1.0};
31#else
32 tarch::la::Vector<DIMENSIONS, double> centre = {0.75, 1.0};
33#endif
34
35 if (tarch::la::norm2(x - centre) < radius) {
36 Q[Shortcuts::rho] = 1.0;
37 }
38"""
39
40boundary_conditions = """
41 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
42 Qoutside[i] = Qinside[i];
43 }
44"""
45
46refinement_criterion = """
47 constexpr double radius = 0.1;
48
49#if DIMENSIONS == 3
50 const tarch::la::Vector<DIMENSIONS, double> centre = {0.75, 1.0, 1.0};
51#else
52 const tarch::la::Vector<DIMENSIONS, double> centre = {0.75, 1.0};
53#endif
54
55 if (tarch::la::equals(t, 0.0)) {
56 return (tarch::la::smallerEquals(tarch::la::norm2(x - centre), radius))
57 ? ::exahype2::RefinementCommand::Refine
58 : ::exahype2::RefinementCommand::Keep;
59 }
60
61 const double rho = Q[Shortcuts::rho];
62
63 return (tarch::la::greaterEquals(rho, 0.5) and tarch::la::smallerEquals(rho, 1.0))
64 ? ::exahype2::RefinementCommand::Refine
65 : ::exahype2::RefinementCommand::Erase;
66"""
67
68fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
69 name="FVSolver",
70 patch_size=args.degrees_of_freedom,
71 unknowns={"rho": 1, "rhoU": args.dimensions},
72 auxiliary_variables=0,
73 min_volume_h=min_h,
74 max_volume_h=max_h,
75 time_step_relaxation=0.5,
76)
77
78fv_solver.set_implementation(
79 initial_conditions=initial_conditions,
80 boundary_conditions=boundary_conditions,
81 refinement_criterion=refinement_criterion,
82 flux="""
83 for (int i = 0; i < NumberOfUnknowns; i++) {
84 F[i] = 0.0;
85 }
86 F[normal] = Q[normal];
87""",
88 max_eigenvalue="return 1.0;",
89)
90
91project = exahype2.Project(
92 namespace=["tests", "exahype2", "fv"],
93 project_name=".",
94 directory=".",
95 executable="ExaHyPE",
96)
97project.add_solver(fv_solver)
98
99if args.number_of_snapshots <= 0:
100 time_in_between_plots = 0.0
101else:
102 time_in_between_plots = args.end_time / args.number_of_snapshots
103 project.set_output_path(args.output)
104
105project.set_global_simulation_parameters(
106 dimensions=args.dimensions,
107 size=[2.0, 2.0, 2.0][0 : args.dimensions],
108 offset=[0.0, 0.0, 0.0][0 : args.dimensions],
109 min_end_time=args.end_time,
110 max_end_time=args.end_time,
111 first_plot_time_stamp=0.0,
112 time_in_between_plots=time_in_between_plots,
113 periodic_BC=[
114 True,
115 False,
116 False,
117 ],
118)
119
120project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
121project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
122project = project.generate_Peano4_project(verbose=False)
123project.output.makefile.set_target_device(args.target_device)
124project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)