29#ifndef TSUNAMI_LAB_PATCHES_WAVE_PROPAGATION_2D
30#define TSUNAMI_LAB_PATCHES_WAVE_PROPAGATION_2D
37 class WavePropagation2d;
45 unsigned short m_step = 0;
57 t_idx m_innerOffset = 0;
60 t_real * m_h[2] = {
nullptr,
nullptr };
63 t_real * m_hu[2] = {
nullptr,
nullptr };
66 t_real * m_hv[2] = {
nullptr,
nullptr };
75 return ( i_ix + 1 ) + ( i_iy + 1 ) * m_stride;
89 m_innerOffset = m_stride + 1;
91 const t_idx l_total = m_stride * ( m_ny + 2 );
94 for(
unsigned short l_st = 0; l_st < 2; l_st++ ) {
95 m_h [l_st] =
new t_real[ l_total ]();
96 m_hu[l_st] =
new t_real[ l_total ]();
97 m_hv[l_st] =
new t_real[ l_total ]();
101 m_bm =
new t_real[ l_total ]();
108 for(
unsigned short l_st = 0; l_st < 2; l_st++ ) {
141 t_real * l_hOld = m_h [m_step];
142 t_real * l_huOld = m_hu[m_step];
143 t_real * l_hvOld = m_hv[m_step];
145 m_step = ( m_step + 1 ) % 2;
146 t_real * l_hNew = m_h [m_step];
147 t_real * l_huNew = m_hu[m_step];
148 t_real * l_hvNew = m_hv[m_step];
150 const t_idx l_s = m_stride;
153 for(
t_idx l_j = 1; l_j <= m_ny; l_j++ ) {
154 for(
t_idx l_i = 1; l_i <= m_nx; l_i++ ) {
155 const t_idx l_id = l_i + l_j * l_s;
156 l_hNew [l_id] = l_hOld [l_id];
157 l_huNew[l_id] = l_huOld[l_id];
158 l_hvNew[l_id] = l_hvOld[l_id];
164 for(
t_idx l_j = 1; l_j <= m_ny; l_j++ ) {
165 for(
t_idx l_i = 0; l_i <= m_nx; l_i++ ) {
166 const t_idx l_idL = l_i + l_j * l_s;
167 const t_idx l_idR = ( l_i+1 ) + l_j * l_s;
169 t_real l_hL = l_hOld [l_idL];
170 t_real l_hR = l_hOld [l_idR];
171 t_real l_huL = l_huOld[l_idL];
172 t_real l_huR = l_huOld[l_idR];
173 t_real l_bL = m_bm [l_idL];
174 t_real l_bR = m_bm [l_idR];
176 const bool l_dryL = l_hL <= 0;
177 const bool l_dryR = l_hR <= 0;
178 if( l_dryL && l_dryR )
continue;
182 l_hL = l_hR; l_huL = -l_huR; l_bL = l_bR;
183 }
else if( l_dryR ) {
184 l_hR = l_hL; l_huR = -l_huL; l_bR = l_bL;
187 t_real l_netUpdates[2][2];
188 this->
solver.netUpdates( l_hL, l_hR,
191 l_netUpdates[0], l_netUpdates[1] );
194 l_hNew [l_idL] -= i_scaling * l_netUpdates[0][0];
195 l_huNew[l_idL] -= i_scaling * l_netUpdates[0][1];
198 l_hNew [l_idR] -= i_scaling * l_netUpdates[1][0];
199 l_huNew[l_idR] -= i_scaling * l_netUpdates[1][1];
207 for(
t_idx l_j = 0; l_j <= m_ny; l_j++ ) {
208 for(
t_idx l_i = 1; l_i <= m_nx; l_i++ ) {
209 const t_idx l_idB = l_i + l_j * l_s;
210 const t_idx l_idT = l_i + ( l_j+1 ) * l_s;
212 t_real l_hB = l_hOld [l_idB];
213 t_real l_hT = l_hOld [l_idT];
214 t_real l_hvB = l_hvOld[l_idB];
215 t_real l_hvT = l_hvOld[l_idT];
216 t_real l_bB = m_bm [l_idB];
217 t_real l_bT = m_bm [l_idT];
219 const bool l_dryB = l_hB <= 0;
220 const bool l_dryT = l_hT <= 0;
221 if( l_dryB && l_dryT )
continue;
224 l_hB = l_hT; l_hvB = -l_hvT; l_bB = l_bT;
225 }
else if( l_dryT ) {
226 l_hT = l_hB; l_hvT = -l_hvB; l_bT = l_bB;
229 t_real l_netUpdates[2][2];
230 this->
solver.netUpdates( l_hB, l_hT,
233 l_netUpdates[0], l_netUpdates[1] );
236 l_hNew [l_idB] -= i_scaling * l_netUpdates[0][0];
237 l_hvNew[l_idB] -= i_scaling * l_netUpdates[0][1];
240 l_hNew [l_idT] -= i_scaling * l_netUpdates[1][0];
241 l_hvNew[l_idT] -= i_scaling * l_netUpdates[1][1];
262 t_real * l_h = m_h [m_step];
263 t_real * l_hu = m_hu[m_step];
264 t_real * l_hv = m_hv[m_step];
265 const t_idx l_s = m_stride;
272 for(
t_idx l_j = 1; l_j <= m_ny; l_j++ ) {
273 l_h [ l_j*l_s] = l_h [1 + l_j*l_s];
275 ? -l_hu[1 + l_j*l_s] : l_hu[1 + l_j*l_s];
276 l_hv[ l_j*l_s] = l_hv[1 + l_j*l_s];
277 m_bm[ l_j*l_s] = m_bm[1 + l_j*l_s];
281 for(
t_idx l_j = 1; l_j <= m_ny; l_j++ ) {
282 l_h [(m_nx+1) + l_j*l_s] = l_h [m_nx + l_j*l_s];
284 ? -l_hu[m_nx + l_j*l_s] : l_hu[m_nx + l_j*l_s];
285 l_hv[(m_nx+1) + l_j*l_s] = l_hv[m_nx + l_j*l_s];
286 m_bm[(m_nx+1) + l_j*l_s] = m_bm[m_nx + l_j*l_s];
290 for(
t_idx l_i = 1; l_i <= m_nx; l_i++ ) {
291 l_h [l_i ] = l_h [l_i + l_s];
292 l_hu[l_i ] = l_hu[l_i + l_s];
294 ? -l_hv[l_i + l_s] : l_hv[l_i + l_s];
295 m_bm[l_i ] = m_bm[l_i + l_s];
299 for(
t_idx l_i = 1; l_i <= m_nx; l_i++ ) {
300 l_h [l_i + (m_ny+1)*l_s] = l_h [l_i + m_ny*l_s];
301 l_hu[l_i + (m_ny+1)*l_s] = l_hu[l_i + m_ny*l_s];
303 ? -l_hv[l_i + m_ny*l_s] : l_hv[l_i + m_ny*l_s];
304 m_bm[l_i + (m_ny+1)*l_s] = m_bm[l_i + m_ny*l_s];
340 return m_h[m_step] + m_innerOffset;
349 return m_hu[m_step] + m_innerOffset;
358 return m_hv[m_step] + m_innerOffset;
367 return m_bm + m_innerOffset;
380 m_h[m_step][ idx( i_ix, i_iy ) ] = i_h;
393 m_hu[m_step][ idx( i_ix, i_iy ) ] = i_hu;
406 m_hv[m_step][ idx( i_ix, i_iy ) ] = i_hv;
419 m_bm[ idx( i_ix, i_iy ) ] = i_b;
Definition WavePropagation2d.h:42
void setBathymetry(t_idx i_ix, t_idx i_iy, t_real i_b)
Definition WavePropagation2d.h:416
void setHeight(t_idx i_ix, t_idx i_iy, t_real i_h)
Definition WavePropagation2d.h:377
t_idx getStride()
Definition WavePropagation2d.h:329
void timeStep(t_real i_scaling)
Definition WavePropagation2d.h:139
t_real const * getBathymetry()
Definition WavePropagation2d.h:366
WavePropagation2d(t_idx i_nx, t_idx i_ny)
Definition WavePropagation2d.h:85
void setGhostBoundary(BoundaryCondition i_left, BoundaryCondition i_right, BoundaryCondition i_bottom, BoundaryCondition i_top)
Definition WavePropagation2d.h:258
t_real const * getMomentumY()
Definition WavePropagation2d.h:357
void setMomentumX(t_idx i_ix, t_idx i_iy, t_real i_hu)
Definition WavePropagation2d.h:390
~WavePropagation2d()
Definition WavePropagation2d.h:107
t_real const * getMomentumX()
Definition WavePropagation2d.h:348
void setMomentumY(t_idx i_ix, t_idx i_iy, t_real i_hv)
Definition WavePropagation2d.h:403
void setGhostReflection()
Definition WavePropagation2d.h:319
t_real const * getHeight()
Definition WavePropagation2d.h:339
void setGhostOutflow()
Definition WavePropagation2d.h:311
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