Peano
Loading...
Searching...
No Matches
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
5tarch::logging::Log tutorials::exahype2::swe::SWESolver::_log("tutorials::exahype2::swe::SWESolver");
6
7void 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
19void 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 (std::abs(::tarch::la::norm2(x) - 0.5) < 0.2 ?
40 ::exahype2::RefinementCommand::Refine :
41 ::exahype2::RefinementCommand::Keep);
42}
43
44double tutorials::exahype2::swe::SWESolver::maxEigenvalue(
45 [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
46 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
47 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
48 [[maybe_unused]] const double t,
49 [[maybe_unused]] const double dt,
50 [[maybe_unused]] const int normal
51) {
52 constexpr double g = 9.81;
53 const double u = Q[Shortcuts::hu + normal] / Q[Shortcuts::h];
54 const double c = std::sqrt(g * Q[Shortcuts::h]);
55 return std::max(std::abs(u + c), std::abs(u - c));
56}
57
58void tutorials::exahype2::swe::SWESolver::flux(
59 [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
60 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
61 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
62 [[maybe_unused]] const double t,
63 [[maybe_unused]] const double dt,
64 [[maybe_unused]] const int normal,
65 [[maybe_unused]] double* const NOALIAS F // F[4]
66) {
67 double ih = 1.0 / Q[Shortcuts::h];
68 F[Shortcuts::h] = Q[Shortcuts::hu + normal];
69 F[Shortcuts::hu + 0] = Q[Shortcuts::hu + normal] * Q[Shortcuts::hu + 0] * ih;
70 F[Shortcuts::hu + 1] = Q[Shortcuts::hu + normal] * Q[Shortcuts::hu + 1] * ih;
71 F[Shortcuts::b] = 0.0;
72}
73
74void tutorials::exahype2::swe::SWESolver::nonconservativeProduct(
75 [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
76 [[maybe_unused]] const double* const NOALIAS deltaQ, // deltaQ[4+0]
77 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
78 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
79 [[maybe_unused]] const double t,
80 [[maybe_unused]] const double dt,
81 [[maybe_unused]] const int normal,
82 [[maybe_unused]] double* const NOALIAS BTimesDeltaQ // BTimesDeltaQ[4]
83) {
84 constexpr double g = 9.81;
85 BTimesDeltaQ[Shortcuts::h] = 0.0;
86 switch (normal) {
87 case 0:
88 BTimesDeltaQ[Shortcuts::hu + 0] = g * Q[Shortcuts::h] * (deltaQ[Shortcuts::h] + deltaQ[Shortcuts::b]);
89 BTimesDeltaQ[Shortcuts::hu + 1] = 0.0;
90 break;
91 case 1:
92 BTimesDeltaQ[Shortcuts::hu + 0] = 0.0;
93 BTimesDeltaQ[Shortcuts::hu + 1] = g * Q[Shortcuts::h] * (deltaQ[Shortcuts::h] + deltaQ[Shortcuts::b]);
94 break;
95 }
96 BTimesDeltaQ[Shortcuts::b] = 0.0;
97}
g
Definition swe.py:85