Peano
tohoku-tsunami.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
3 import os
4 import sys
5 
6 import peano4
7 import exahype2
8 
9 sys.path.insert(0, os.path.abspath(".."))
10 from FWave import fWave
11 
12 initial_conditions = """
13  static tarch::reader::NetCDFFieldParser fieldParser(
14  \"tohoku_gebco_ucsb3_2000m_hawaii_bath.nc\",
15  \"tohoku_gebco_ucsb3_2000m_hawaii_displ.nc\",
16  DomainSize(0),
17  DomainSize(1),
18  DomainOffset(0),
19  DomainOffset(1)
20  );
21 
22  const double bathymetryBeforeEarthquake = fieldParser.sampleTopology(x(0), x(1));
23  const double displacement = fieldParser.sampleDisplacement(x(0), x(1));
24  const double bathymetryAfterEarthquake = bathymetryBeforeEarthquake + displacement;
25 
26  Q[Shortcuts::h] = -std::min(bathymetryBeforeEarthquake, 0.0);
27  Q[Shortcuts::hu] = 0.0;
28  Q[Shortcuts::hv] = 0.0;
29  Q[Shortcuts::z] = bathymetryAfterEarthquake;
30 """
31 
32 boundary_conditions = """
33  for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
34  Qoutside[i] = Qinside[i];
35  }
36 """
37 
38 refinement_criterion = """
39  auto result = ::exahype2::RefinementCommand::Keep;
40  if (x(0) <= 2e6 and x(1) >= 2e6) {
41  result = ::exahype2::RefinementCommand::Refine;
42  }
43  return result;
44 """
45 
46 parser = exahype2.ArgumentParser()
47 parser.set_defaults(
48  min_depth=4,
49  end_time=5000.0,
50 )
51 args = parser.parse_args()
52 
53 constants = {
54  "g": [9.81, "double"],
55  "hThreshold": [1e-5, "double"],
56 }
57 
58 size = [7e6, 4e6]
59 max_h = (1.1 * min(size) / (3.0**args.min_depth))
60 min_h = max_h * 3.0 ** (-args.amr_levels)
61 
62 fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
63  name="FVSolver",
64  patch_size=args.degrees_of_freedom,
65  unknowns={"h": 1, "hu": 1, "hv": 1},
66  auxiliary_variables={"z": 1},
67  min_volume_h=min_h,
68  max_volume_h=max_h,
69  time_step_relaxation=args.time_step_relaxation,
70  use_enclave_tasking=args.enclave_tasking,
71  number_of_enclave_tasks=args.ntasks,
72 )
73 
74 fv_solver.set_implementation(
75  initial_conditions=initial_conditions,
76  boundary_conditions=boundary_conditions,
77  refinement_criterion=refinement_criterion,
78  riemann_solver=fWave,
79 )
80 
81 fv_solver.set_plotter(args.plotter)
82 fv_solver.add_user_solver_includes(
83  """
84 #include "tarch/reader/NetCDFFieldParser.h"
85 """
86 )
87 
88 project = exahype2.Project(
89  namespace=["applications", "exahype2", "swe"],
90  project_name="TohokuTsunami",
91  directory=".",
92  executable="ExaHyPE-ShallowWater",
93 )
94 project.add_solver(fv_solver)
95 
96 if args.number_of_snapshots <= 0:
97  time_in_between_plots = 0.0
98 else:
99  time_in_between_plots = args.end_time / args.number_of_snapshots
100  project.set_output_path(args.output)
101 
102 project.set_global_simulation_parameters(
103  dimensions=2,
104  size=size,
105  offset=[0.0, 0.0],
106  min_end_time=args.end_time,
107  max_end_time=args.end_time,
108  first_plot_time_stamp=0.0,
109  time_in_between_plots=time_in_between_plots,
110  periodic_BC=[
111  args.periodic_boundary_conditions_x,
112  args.periodic_boundary_conditions_y,
113  ],
114 )
115 
116 project.set_load_balancer(f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})")
117 project.set_Peano4_installation("../../../../", mode=peano4.output.string_to_mode(args.build_mode))
118 project = project.generate_Peano4_project(verbose=False)
119 for const_name, const_info in constants.items():
120  const_val, const_type = const_info
121  project.constants.export_constexpr_with_type(
122  const_name, str(const_val), const_type
123  )
124 project.output.makefile.set_target_device(args.target_device)
125 project.set_fenv_handler(args.fpe)
126 project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
static double min(double const x, double const y)
str
Definition: ccz4.py:55