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) {
12 Q[Shortcuts::hu + 0] = 0.0; // v_x
13 Q[Shortcuts::hu + 1] = 0.0; // v_y
14 Q[Shortcuts::h] = 1.0;
15 Q[Shortcuts::b] = (tarch::la::norm2(x) < 0.5 ? 0.1 : 0.0);
16}
17
18void tutorials::exahype2::swe::SWESolver::boundaryConditions(
19 [[maybe_unused]] const double* const NOALIAS Qinside, // Qinside[4+0]
20 [[maybe_unused]] double* const NOALIAS Qoutside, // Qoutside[4+0]
21 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
22 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
23 [[maybe_unused]] const double t,
24 [[maybe_unused]] const int normal
25) {
26 Qoutside[Shortcuts::h] = 1.0; // h
27 Qoutside[Shortcuts::hu + 0] = 0.0; // v_x
28 Qoutside[Shortcuts::hu + 1] = 0.0; // v_y
29 Qoutside[Shortcuts::b] = 0.0; // b
30}
31
32::exahype2::RefinementCommand tutorials::exahype2::swe::SWESolver::refinementCriterion(
33 [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
34 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
35 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
36 [[maybe_unused]] const double t
37) {
38 return (
39 std::abs(::tarch::la::norm2(x) - 0.5) < 0.2
40 ? ::exahype2::RefinementCommand::Refine
41 : ::exahype2::RefinementCommand::Keep
42 );
43}
44
45double tutorials::exahype2::swe::SWESolver::maxEigenvalue(
46 [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
47 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
48 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
49 [[maybe_unused]] const double t,
50 [[maybe_unused]] const double dt,
51 [[maybe_unused]] const int normal
52) {
53 constexpr double g = 9.81;
54 const double u = Q[Shortcuts::hu + normal] / Q[Shortcuts::h];
55 const double c = std::sqrt(g * Q[Shortcuts::h]);
56 return std::max(std::abs(u + c), std::abs(u - c));
57}
58
59void tutorials::exahype2::swe::SWESolver::flux(
60 [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
61 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
62 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
63 [[maybe_unused]] const double t,
64 [[maybe_unused]] const double dt,
65 [[maybe_unused]] const int normal,
66 [[maybe_unused]] double* const NOALIAS F // F[4]
67) {
68 double ih = 1.0 / Q[Shortcuts::h];
69 F[Shortcuts::h] = Q[Shortcuts::hu + normal];
70 F[Shortcuts::hu + 0] = Q[Shortcuts::hu + normal] * Q[Shortcuts::hu + 0] * ih;
71 F[Shortcuts::hu + 1] = Q[Shortcuts::hu + normal] * Q[Shortcuts::hu + 1] * ih;
72 F[Shortcuts::b] = 0.0;
73}
74
75void tutorials::exahype2::swe::SWESolver::nonconservativeProduct(
76 [[maybe_unused]] const double* const NOALIAS Q, // Q[4+0]
77 [[maybe_unused]] const double* const NOALIAS deltaQ, // deltaQ[4+0]
78 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& x,
79 [[maybe_unused]] const tarch::la::Vector<DIMENSIONS, double>& h,
80 [[maybe_unused]] const double t,
81 [[maybe_unused]] const double dt,
82 [[maybe_unused]] const int normal,
83 [[maybe_unused]] double* const NOALIAS BTimesDeltaQ // BTimesDeltaQ[4]
84) {
85 constexpr double g = 9.81;
86 BTimesDeltaQ[Shortcuts::h] = 0.0;
87 switch (normal) {
88 case 0:
89 BTimesDeltaQ[Shortcuts::hu + 0] = g * Q[Shortcuts::h] * (deltaQ[Shortcuts::h] + deltaQ[Shortcuts::b]);
90 BTimesDeltaQ[Shortcuts::hu + 1] = 0.0;
91 break;
92 case 1:
93 BTimesDeltaQ[Shortcuts::hu + 0] = 0.0;
94 BTimesDeltaQ[Shortcuts::hu + 1] = g * Q[Shortcuts::h] * (deltaQ[Shortcuts::h] + deltaQ[Shortcuts::b]);
95 break;
96 }
97 BTimesDeltaQ[Shortcuts::b] = 0.0;
98}