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 public:
48 m_nCells = i_nCells;
49
50 // allocate memory including a single ghost cell on each side
51 for( unsigned short l_st = 0; l_st < 2; l_st++ ) {
52 m_h[l_st] = new t_real[ m_nCells + 2 ];
53 m_hu[l_st] = new t_real[ m_nCells + 2 ];
54 }
55
56 // init to zero (including both ghost cells at indices 0 and m_nCells+1)
57 for( unsigned short l_st = 0; l_st < 2; l_st++ ) {
58 for( t_idx l_ce = 0; l_ce < m_nCells + 2; l_ce++ ) {
59 m_h[l_st][l_ce] = 0;
60 m_hu[l_st][l_ce] = 0;
61 }
62 }
63 }
64
69 for( unsigned short l_st = 0; l_st < 2; l_st++ ) {
70 delete[] m_h[l_st];
71 delete[] m_hu[l_st];
72 }
73 }
74
80 void timeStep( t_real i_scaling ) {
81 // pointers to old and new data
82 t_real * l_hOld = m_h[m_step];
83 t_real * l_huOld = m_hu[m_step];
84
85 m_step = (m_step+1) % 2;
86 t_real * l_hNew = m_h[m_step];
87 t_real * l_huNew = m_hu[m_step];
88
89 // init new cell quantities
90 for( t_idx l_ce = 1; l_ce < m_nCells+1; l_ce++ ) {
91 l_hNew[l_ce] = l_hOld[l_ce];
92 l_huNew[l_ce] = l_huOld[l_ce];
93 }
94
95 // iterate over edges and update with Riemann solutions
96 for( t_idx l_ed = 0; l_ed < m_nCells+1; l_ed++ ) {
97 // determine left and right cell-id
98 t_idx l_ceL = l_ed;
99 t_idx l_ceR = l_ed+1;
100
101 // compute net-updates
102 t_real l_netUpdates[2][2];
103
104 this->solver.netUpdates( l_hOld[l_ceL],
105 l_hOld[l_ceR],
106 l_huOld[l_ceL],
107 l_huOld[l_ceR],
108 l_netUpdates[0],
109 l_netUpdates[1] );
110
111 // update the cells' quantities
112 l_hNew[l_ceL] -= i_scaling * l_netUpdates[0][0];
113 l_huNew[l_ceL] -= i_scaling * l_netUpdates[0][1];
114
115 l_hNew[l_ceR] -= i_scaling * l_netUpdates[1][0];
116 l_huNew[l_ceR] -= i_scaling * l_netUpdates[1][1];
117 }
118 }
119
124 t_real * l_h = m_h[m_step];
125 t_real * l_hu = m_hu[m_step];
126
127 // set left boundary
128 l_h[0] = l_h[1];
129 l_hu[0] = l_hu[1];
130
131 // set right boundary
132 l_h[m_nCells+1] = l_h[m_nCells];
133 l_hu[m_nCells+1] = l_hu[m_nCells];
134 }
135
142 return m_nCells+2;
143 }
144
150 t_real const * getHeight(){
151 return m_h[m_step]+1;
152 }
153
160 return m_hu[m_step]+1;
161 }
162
167 return nullptr;
168 }
169
176 void setHeight( t_idx i_ix,
177 t_idx,
178 t_real i_h ) {
179 m_h[m_step][i_ix+1] = i_h;
180 }
181
188 void setMomentumX( t_idx i_ix,
189 t_idx,
190 t_real i_hu ) {
191 m_hu[m_step][i_ix+1] = i_hu;
192 }
193
198 t_idx,
199 t_real ) {};
200};
201
202#endif
Definition WavePropagation1d.h:27
void setHeight(t_idx i_ix, t_idx, t_real i_h)
Definition WavePropagation1d.h:176
void timeStep(t_real i_scaling)
Definition WavePropagation1d.h:80
t_real const * getMomentumX()
Definition WavePropagation1d.h:159
WavePropagation1d(t_idx i_nCells)
Definition WavePropagation1d.h:47
t_idx getStride()
Definition WavePropagation1d.h:141
t_real const * getHeight()
Definition WavePropagation1d.h:150
~WavePropagation1d()
Definition WavePropagation1d.h:68
void setGhostOutflow()
Definition WavePropagation1d.h:123
void setMomentumX(t_idx i_ix, t_idx, t_real i_hu)
Definition WavePropagation1d.h:188
void setMomentumY(t_idx, t_idx, t_real)
Definition WavePropagation1d.h:197
t_real const * getMomentumY()
Definition WavePropagation1d.h:166
Definition WavePropagation.h:22
T solver
Definition WavePropagation.h:23
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