Tsunami Project Lab
Loading...
Searching...
No Matches
WavePropagation1d.h
Go to the documentation of this file.
1
7#ifndef TSUNAMI_LAB_PATCHES_WAVE_PROPAGATION_1D
8#define TSUNAMI_LAB_PATCHES_WAVE_PROPAGATION_1D
9
10#include "WavePropagation.h"
11
12namespace tsunami_lab {
13 namespace patches {
14 template<class T>
15 class WavePropagation1d;
16 }
17}
18
26template<class T>
28 private:
30 unsigned short m_step = 0;
31
33 t_idx m_nCells = 0;
34
36 t_real * m_h[2] = { nullptr, nullptr };
37
39 t_real * m_hu[2] = { nullptr, nullptr };
40
41 // bathymetry array
42 t_real * m_bm = nullptr;
43
44 public:
51 m_nCells = i_nCells;
52
53 // allocate memory including a single ghost cell on each side
54 for( unsigned short l_st = 0; l_st < 2; l_st++ ) {
55 m_h[l_st] = new t_real[ m_nCells + 2 ];
56 m_hu[l_st] = new t_real[ m_nCells + 2 ];
57 }
58
59 // init to zero (including both ghost cells at indices 0 and m_nCells+1)
60 for( unsigned short l_st = 0; l_st < 2; l_st++ ) {
61 for( t_idx l_ce = 0; l_ce < m_nCells + 2; l_ce++ ) {
62 m_h[l_st][l_ce] = 0;
63 m_hu[l_st][l_ce] = 0;
64 }
65 }
66
67 // init bathymetry array to 0 (value-initialised)
68 m_bm = new t_real[m_nCells + 2]();
69 }
70
75 for( unsigned short l_st = 0; l_st < 2; l_st++ ) {
76 delete[] m_h[l_st];
77 delete[] m_hu[l_st];
78 }
79 delete[] m_bm;
80 }
81
87 void timeStep( t_real i_scaling ) {
88 // pointers to old and new data
89 t_real * l_hOld = m_h[m_step];
90 t_real * l_huOld = m_hu[m_step];
91
92 m_step = (m_step+1) % 2;
93 t_real * l_hNew = m_h[m_step];
94 t_real * l_huNew = m_hu[m_step];
95
96 // init new cell quantities
97 for( t_idx l_ce = 1; l_ce < m_nCells+1; l_ce++ ) {
98 l_hNew[l_ce] = l_hOld[l_ce];
99 l_huNew[l_ce] = l_huOld[l_ce];
100 }
101
102 // iterate over edges and update with Riemann solutions
103 for( t_idx l_ed = 0; l_ed < m_nCells+1; l_ed++ ) {
104 // determine left and right cell-id
105 t_idx l_ceL = l_ed;
106 t_idx l_ceR = l_ed+1;
107
108 t_real l_hL_ref = l_hOld[l_ceL];
109 t_real l_hR_ref = l_hOld[l_ceR];
110 t_real l_huL_ref = l_huOld[l_ceL];
111 t_real l_huR_ref = l_huOld[l_ceR];
112 t_real l_bmL_ref = m_bm[l_ceL];
113 t_real l_bmR_ref = m_bm[l_ceR];
114
115 // wet/dry classification by water column: h > 0 is wet, h == 0 is dry
116 const bool l_dryL = l_hL_ref <= 0;
117 const bool l_dryR = l_hR_ref <= 0;
118
119 // dry-dry edge: Riemann problem is undefined, no update needed
120 if( l_dryL && l_dryR ) continue;
121
122 // wet-dry interface: replace the dry side with a mirror of the wet side
123 // (Spec 3.2.1) so the edge acts as a solid wall
124 if( l_dryL ) {
125 l_hL_ref = l_hR_ref;
126 l_huL_ref = -l_huR_ref;
127 l_bmL_ref = l_bmR_ref;
128 } else if( l_dryR ) {
129 l_hR_ref = l_hL_ref;
130 l_huR_ref = -l_huL_ref;
131 l_bmR_ref = l_bmL_ref;
132 }
133
134 // compute net-updates
135 t_real l_netUpdates[2][2];
136
137 this->solver.netUpdates( l_hL_ref,
138 l_hR_ref,
139 l_huL_ref,
140 l_huR_ref,
141 l_bmL_ref,
142 l_bmR_ref,
143 l_netUpdates[0],
144 l_netUpdates[1] );
145
146 // only apply updates to wet cells; Spec 3.2 requires dry cells to stay dry
147 if( !l_dryL ) {
148 l_hNew[l_ceL] -= i_scaling * l_netUpdates[0][0];
149 l_huNew[l_ceL] -= i_scaling * l_netUpdates[0][1];
150 }
151 if( !l_dryR ) {
152 l_hNew[l_ceR] -= i_scaling * l_netUpdates[1][0];
153 l_huNew[l_ceR] -= i_scaling * l_netUpdates[1][1];
154 }
155 }
156 }
157
164 BoundaryCondition i_right,
165 BoundaryCondition /*i_bottom*/,
166 BoundaryCondition /*i_top*/ ) {
167 t_real * l_h = m_h[m_step];
168 t_real * l_hu = m_hu[m_step];
169
170 // left ghost cell mirrors cell 1
171 l_h[0] = l_h[1];
172 m_bm[0] = m_bm[1];
173 l_hu[0] = (i_left == BoundaryCondition::REFLECTING) ? -l_hu[1] : l_hu[1];
174
175 // right ghost cell mirrors cell m_nCells
176 l_h[m_nCells + 1] = l_h[m_nCells];
177 m_bm[m_nCells + 1] = m_bm[m_nCells];
178 l_hu[m_nCells + 1] = (i_right == BoundaryCondition::REFLECTING)
179 ? -l_hu[m_nCells]
180 : l_hu[m_nCells];
181 }
182
190
198
205 return m_nCells+2;
206 }
207
213 t_real const * getHeight(){
214 return m_h[m_step]+1;
215 }
216
223 return m_hu[m_step]+1;
224 }
225
230 return nullptr;
231 }
232
239 return m_bm + 1;
240 }
241
248 void setHeight( t_idx i_ix,
249 t_idx,
250 t_real i_h ) {
251 m_h[m_step][i_ix+1] = i_h;
252 }
253
260 void setMomentumX( t_idx i_ix,
261 t_idx,
262 t_real i_hu ) {
263 m_hu[m_step][i_ix+1] = i_hu;
264 }
265
270 t_idx,
271 t_real ) {};
272
273
281 void setBathymetry(t_idx i_ix, t_idx /*i_iy*/, t_real i_b) {
282 m_bm[i_ix + 1] = i_b;
283 };
284};
285
286#endif
Definition WavePropagation1d.h:27
t_real const * getBathymetry()
Definition WavePropagation1d.h:238
void setGhostBoundary(BoundaryCondition i_left, BoundaryCondition i_right, BoundaryCondition, BoundaryCondition)
Definition WavePropagation1d.h:163
void setHeight(t_idx i_ix, t_idx, t_real i_h)
Definition WavePropagation1d.h:248
void timeStep(t_real i_scaling)
Definition WavePropagation1d.h:87
t_real const * getMomentumX()
Definition WavePropagation1d.h:222
WavePropagation1d(t_idx i_nCells)
Definition WavePropagation1d.h:50
t_idx getStride()
Definition WavePropagation1d.h:204
t_real const * getHeight()
Definition WavePropagation1d.h:213
~WavePropagation1d()
Definition WavePropagation1d.h:74
void setGhostReflection()
Definition WavePropagation1d.h:194
void setGhostOutflow()
Definition WavePropagation1d.h:186
void setMomentumX(t_idx i_ix, t_idx, t_real i_hu)
Definition WavePropagation1d.h:260
void setMomentumY(t_idx, t_idx, t_real)
Definition WavePropagation1d.h:269
void setBathymetry(t_idx i_ix, t_idx, t_real i_b)
Definition WavePropagation1d.h:281
t_real const * getMomentumY()
Definition WavePropagation1d.h:229
Definition WavePropagation.h:31
T solver
Definition WavePropagation.h:32
BoundaryCondition
Definition WavePropagation.h:19
@ OUTFLOW
zero-gradient: copy the inner cell into the ghost cell
Definition constants.h:12
float t_real
floating point type
Definition constants.h:17
std::size_t t_idx
integral type for cell-ids, pointer arithmetic, etc.
Definition constants.h:14