Peano
swe.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 from .equation import Equation
4 
5 
7  def __init__(self, dimensions=2):
8  if dimensions != 2:
9  raise Exception("SWE must be in 2 dimensions")
10  self.dimensionsdimensionsdimensions = 2
11  self.num_unknownsnum_unknownsnum_unknowns = 4
12  self.num_auxiliary_variablesnum_auxiliary_variablesnum_auxiliary_variables = 0
13 
14  def eigenvalues(self):
15  return """
16  constexpr double grav = 9.81;
17 
18  const double u = Q[1 + normal] / Q[0];
19  const double c = std::sqrt(grav * Q[0]);
20 
21  return std::fmax(std::abs(u + c), std::abs(u - c));
22 """
23 
24  def flux(self):
25  return """
26  double ih = 1.0 / Q[0];
27 
28  F[0] = Q[1 + normal];
29  F[1] = Q[1 + normal] * Q[1] * ih;
30  F[2] = Q[1 + normal] * Q[2] * ih;
31  F[3] = 0.0;
32 """
33 
34  def ncp(self):
35  return """
36  constexpr double grav = 9.81;
37  BTimesDeltaQ[0] = 0.0;
38  switch (normal) {
39  case 0:
40  BTimesDeltaQ[1] = grav * Q[0] * (deltaQ[0] + deltaQ[3]);
41  BTimesDeltaQ[2] = 0.0;
42  break;
43  case 1:
44  BTimesDeltaQ[1] = 0.0;
45  BTimesDeltaQ[2] = grav * Q[0] * (deltaQ[0] + deltaQ[3]);
46  break;
47  }
48  BTimesDeltaQ[3] = 0.0;
49 """
50 
51  def riemann_solver(self):
52  return """
53  //Compute max eigenvalue over face
54  double smax = 0.0;
55  for(int xy=0; xy<Order+1; xy++){
56  smax = std::max(smax, maxEigenvalue(&QL[xy*4], x, h, t, dt, direction));
57  smax = std::max(smax, maxEigenvalue(&QR[xy*4], x, h, t, dt, direction));
58  }
59 
60  for(int xy=0; xy<Order+1; xy++){
61 
62  // h gets added term from bathimetry, u and v are regular Rusanov, b does not change
63  FL[xy*4+0] = 0.5*(FL[xy*4+0]+FR[xy*4+0] + smax*(QL[xy*4+0]+QL[xy*4+3]-QR[xy*4+0]-QR[xy*4+3]) );
64  FL[xy*4+1] = 0.5*(FL[xy*4+1]+FR[xy*4+1] + smax*(QL[xy*4+1]-QR[xy*4+1]) );
65  FL[xy*4+2] = 0.5*(FL[xy*4+2]+FR[xy*4+2] + smax*(QL[xy*4+2]-QR[xy*4+2]) );
66  FL[xy*4+3] = 0.0;
67 
68  FR[xy*4+0] = FL[xy*4+0];
69  FR[xy*4+1] = FL[xy*4+1];
70  FR[xy*4+2] = FL[xy*4+2];
71  FR[xy*4+3] = 0.0;
72 
73  //Contribution from NCP
74  FL[xy*4+direction+1] += 0.5*9.81*0.5*(QL[xy*4+0]+QR[xy*4+0])*(QR[xy*4+3]+QR[xy*4+0]-QL[xy*4+3]-QL[xy*4+0]);
75  FR[xy*4+direction+1] -= 0.5*9.81*0.5*(QL[xy*4+0]+QR[xy*4+0])*(QR[xy*4+3]+QR[xy*4+0]-QL[xy*4+3]-QL[xy*4+0]);
76  }
77 """
78 
79 
81  def __init__(self, dimensions=2):
82  if dimensions != 2:
83  raise Exception("SWE must be in 2 dimensions")
84  self.dimensionsdimensionsdimensions = 2
85  self.num_unknownsnum_unknownsnum_unknowns = 3
86  self.num_auxiliary_variablesnum_auxiliary_variablesnum_auxiliary_variables = 0
87 
88  def eigenvalues(self):
89  return """
90  constexpr double grav = 9.81;
91 
92  const double u = Q[1 + normal] / Q[0];
93  const double c = std::sqrt(grav * Q[0]);
94 
95  return std::fmax(std::abs(u + c), std::abs(u - c));
96 """
97 
98  def flux(self):
99  return """
100  constexpr double grav = 9.81;
101  double ih = 1.0 / Q[0];
102 
103  F[0] = Q[1 + normal];
104  F[1] = Q[1 + normal] * Q[1] * ih;
105  F[2] = Q[1 + normal] * Q[2] * ih;
106 
107  F[normal+1] += 0.5 * grav * Q[0] * Q[0];
108 """
def __init__(self, dimensions=2)
Definition: swe.py:81
def __init__(self, dimensions=2)
Definition: swe.py:7