Peano 4
Loading...
Searching...
No Matches
AdjointSolver.hpp
Go to the documentation of this file.
1#ifndef applications_exahype2_swe_adjoint_adjoint_solver_h_
2#define applications_exahype2_swe_adjoint_adjoint_solver_h_
3#include <cmath>
6{
8 {
9 public:
10 inline static void compute_net_updates(double m_h_l, double m_h_r, double m_hu_l, double m_hu_r, double bat_l, double bat_r, double &h_netup_l,
11 double &h_netup_r, double &hu_netup_l, double &hu_netup_r, double &maxEdgeSpeed)
12 {
13 // Steady states && land mass
14 if ((tarch::la::equals(m_h_l, m_h_r) && tarch::la::equals(m_hu_l, m_hu_r) && tarch::la::equals(bat_l, bat_r)) || (tarch::la::equals(m_h_l, 0.0) && tarch::la::equals(m_h_r, 0.0)))
15 {
16 h_netup_l = 0.0;
17 h_netup_r = 0.0;
18 hu_netup_l = 0.0;
19 hu_netup_r = 0.0;
20 maxEdgeSpeed = 0.0;
21 return;
22 }
23 // Is left cell wet and right cell dry?
24 else if (tarch::la::equals(m_h_r, 0.0) && tarch::la::greater(m_h_l, 0.0))
25 {
26 m_h_r = m_h_l;
27 m_hu_r = -m_hu_l;
28 bat_r = bat_l;
29 }
30 // Is right cell wet and left cell dry?
31 else if (tarch::la::equals(m_h_l, 0.0) && tarch::la::greater(m_h_r, 0.0))
32 {
33 m_h_l = m_h_r;
34 m_hu_l = -m_hu_r;
35 bat_l = bat_r;
36 }
37
38 double h_l_hat = -bat_l;
39 double h_r_hat = -bat_r;
40
41 double c_l = sqrt(9.81 * h_l_hat);
42 double c_r = sqrt(9.81 * h_r_hat);
43
44 //delta[0] = -hu_r * cR**2 + hu_l * cL**2
45 double delta0 = (-m_hu_r * c_r * c_r) + (m_hu_l * c_l * c_l);
46 //delta[1] = -(h_r + b_r) + (h_l + b_l)
47 double delta1 = -(m_h_r + bat_r) + (m_h_l + bat_l);
48
49 //beta[0] = (delta[0] + cR * delta[1])
50 double beta0 = delta0 + c_r * delta1;
51 //beta[1] = (-delta[0] + cL * delta[1])
52 double beta1 = -delta0 + c_l * delta1;
53 if(!tarch::la::equals(c_l + c_r, 0.0))
54 {
55 beta0 /= (c_l + c_r);
56 beta1 /= (c_l + c_r);
57 }
58
59 maxEdgeSpeed = std::max(std::abs(c_l), std::abs(c_r));
60 h_netup_l = c_l * beta0;
61 hu_netup_l = beta0;
62 h_netup_r = -c_r * beta1;
63 hu_netup_r = beta1;
64 }
65 };
66};
67#endif
static void compute_net_updates(double m_h_l, double m_h_r, double m_hu_l, double m_hu_r, double bat_l, double bat_r, double &h_netup_l, double &h_netup_r, double &hu_netup_l, double &hu_netup_r, double &maxEdgeSpeed)
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.