Peano
SWESolver.cpp
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 #include "SWESolver.h"
4 
5 tarch::logging::Log tutorials::exahype2::swe::SWESolver::_log("tutorials::exahype2::swe::SWESolver");
6 
7 void tutorials::exahype2::swe::SWESolver::initialCondition(
8  [[maybe_unused]] double* const NOALIAS Q, // Q[4+0]
9  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
10  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
11  [[maybe_unused]] const bool gridIsConstructed
12 ) {
13  Q[Shortcuts::hu + 0] = 0.0; // v_x
14  Q[Shortcuts::hu + 1] = 0.0; // v_y
15  Q[Shortcuts::h] = 1.0;
16  Q[Shortcuts::b] = (tarch::la::norm2(x) < 0.5 ? 0.1 : 0.0);
17 }
18 
19 void tutorials::exahype2::swe::SWESolver::boundaryConditions(
20  [[maybe_unused]] const double* const NOALIAS Qinside, // Qinside[4+0]
21  [[maybe_unused]] double* const NOALIAS Qoutside, // Qoutside[4+0]
22  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
23  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
24  [[maybe_unused]] const double t,
25  [[maybe_unused]] const int normal
26 ) {
27  Qoutside[Shortcuts::h] = 1.0; // h
28  Qoutside[Shortcuts::hu + 0] = 0.0; // v_x
29  Qoutside[Shortcuts::hu + 1] = 0.0; // v_y
30  Qoutside[Shortcuts::b] = 0.0; // b
31 }
32 
33 ::exahype2::RefinementCommand tutorials::exahype2::swe::SWESolver::refinementCriterion(
34  [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
35  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
36  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
37  [[maybe_unused]] const double t
38 ) {
39  return tarch::la::norm2(x) < 0.6 ? ::exahype2::RefinementCommand::Refine : ::exahype2::RefinementCommand::Keep;
40 }
41 
43  [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
44  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
45  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
46  [[maybe_unused]] const double t,
47  [[maybe_unused]] const double dt,
48  [[maybe_unused]] const int normal
49 ) {
50  constexpr double g = 9.81;
51  const double u = Q[Shortcuts::hu + normal] / Q[Shortcuts::h];
52  const double c = std::sqrt(g * Q[Shortcuts::h]);
53  return std::max(std::abs(u + c), std::abs(u - c));
54 }
55 
57  [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
58  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
59  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
60  [[maybe_unused]] const double t,
61  [[maybe_unused]] const double dt,
62  [[maybe_unused]] const int normal,
63  [[maybe_unused]] double* const NOALIAS F // F[4]
64 ) {
65  double ih = 1.0 / Q[Shortcuts::h];
66  F[Shortcuts::h] = Q[Shortcuts::hu + normal];
67  F[Shortcuts::hu + 0] = Q[Shortcuts::hu + normal] * Q[Shortcuts::hu + 0] * ih;
68  F[Shortcuts::hu + 1] = Q[Shortcuts::hu + normal] * Q[Shortcuts::hu + 1] * ih;
69  F[Shortcuts::b] = 0.0;
70 }
71 
72 void tutorials::exahype2::swe::SWESolver::nonconservativeProduct(
73  [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
74  [[maybe_unused]] const double* const NOALIAS deltaQ, // deltaQ[4+0]
75  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
76  [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
77  [[maybe_unused]] const double t,
78  [[maybe_unused]] const double dt,
79  [[maybe_unused]] const int normal,
80  [[maybe_unused]] double* const NOALIAS BTimesDeltaQ // BTimesDeltaQ[4]
81 ) {
82  constexpr double g = 9.81;
83  BTimesDeltaQ[Shortcuts::h] = 0.0;
84  switch (normal) {
85  case 0:
86  BTimesDeltaQ[Shortcuts::hu + 0] = g * Q[Shortcuts::h] * (deltaQ[Shortcuts::h] + deltaQ[Shortcuts::b]);
87  BTimesDeltaQ[Shortcuts::hu + 1] = 0.0;
88  break;
89  case 1:
90  BTimesDeltaQ[Shortcuts::hu + 0] = 0.0;
91  BTimesDeltaQ[Shortcuts::hu + 1] = g * Q[Shortcuts::h] * (deltaQ[Shortcuts::h] + deltaQ[Shortcuts::b]);
92  break;
93  }
94  BTimesDeltaQ[Shortcuts::b] = 0.0;
95 }
double norm2(double *v, int n)
static double maxEigenvalue(const double *const Q, int normal, const double CCZ4e, const double CCZ4ds, const double CCZ4GLMc, const double CCZ4GLMd)
u
Definition: euler.py:113
flux
Definition: euler.py:29
hu
Definition: swe.py:80
g
Definition: swe.py:85
b
Definition: swe.py:82
h
Definition: swe.py:79
tarch::logging::Log _log
This is variant 1 of the fused kernels.