quadgrid 0.1
simple cartesian quad grid with particles for c++/octave
Loading...
Searching...
No Matches
taylor_dispersion.h
Go to the documentation of this file.
1#ifndef CHANNEL_H
2#define CHANNEL_H
3
4#include <json.hpp>
5#include <particles.h>
6
7#include <fstream>
8#include <iostream>
9#include <map>
10#include <random>
11#include <vector>
12
13#include "counter.h"
14#include <timer.h>
15#include <quadgrid_config.h>
16
17
20 real_t operator()(real_t num, real_t den) const {
21 return den > 0.0 ? num / den : 0.0;
22 }
23};
24
25struct abs_no_nan {
27 real_t operator()(real_t value) const {
28 return value == value ? (value < 0.0 ? -value : value) : 0.0;
29 }
30};
31
32
33template<typename PVAR_t>
34class
35stepper {
36private :
37 PVAR_t x;
38 PVAR_t y;
39 PVAR_t vx;
40 PVAR_t vy;
41
42
43public :
44 real_t dt;
45 stepper (PVAR_t x_, PVAR_t y_,
46 PVAR_t vx_, PVAR_t vy_,
47 real_t dt_)
48 : x(x_), y(y_), vx(vx_), vy(vy_), dt{dt_} { }
49
51
55
56 DEVICE
57 void operator() (int n) {
58
59 //update particles positions
60 x[n] += vx[n] * dt;
61 y[n] += vy[n] * dt;
62
63 // Apply boundary conditions (unelastic walls)
64 y[n] = fmin (0.1999, fmax (0.001, y[n]));
65
66 }
67
68};
69
70//Custom P2G
71template<typename PVAR_t, typename GVAR_t, typename P2C_t>
72class
74
76 const PVAR_t x;
77 const PVAR_t y;
78 const PVAR_t dprop1;
79 const PVAR_t dprop2;
80 const P2C_t ptcl_to_grd;
81 const idx_t nrows;
82 const real_t hx;
83 const real_t hy;
84 GVAR_t M;
85 GVAR_t gvar;
86 bool apply_mass;
87
88public:
89
90 p2g_step1 (const PVAR_t x_, const PVAR_t y_, GVAR_t M_,
91 GVAR_t gvar_, const P2C_t ptcl_to_grd_, const idx_t nrows_,
92 const real_t hx_, const real_t hy_, const PVAR_t dprop1_, const PVAR_t dprop2_, bool apply_mass_)
93 : x(x_), y(y_), M(M_), gvar(gvar_),
94 ptcl_to_grd(ptcl_to_grd_), nrows(nrows_), hx(hx_), hy(hy_),
95 dprop1(dprop1_), dprop2(dprop2_), apply_mass(apply_mass_) {};
96
97
98 DEVICE
99 void
101
102 using qgt = quadgrid_t<GVAR_t>;
103 real_t N = 0.0;
104 auto xx = x[ip];
105 auto yy = y[ip];
106 auto r = qgt::gind2row (ptcl_to_grd[ip], nrows);
107 auto c = qgt::gind2col (ptcl_to_grd[ip], nrows);
108 for (idx_t inode = 0; inode < 4; ++inode) {
109 N = apply_mass ? qgt::shp (xx, yy, inode, c, r, hx, hy)/M[qgt::gt(inode, c, r, nrows)] :
110 qgt::shp (xx, yy, inode, c, r, hx, hy);
111 atomicAdd(&(gvar[qgt::gt(inode, c, r, nrows)]), N*dprop1[ip]*dprop2[ip]);
112 }
113 }
114
115};
116
117//Custom P2GD
118template<typename PVAR_t, typename GVAR_t, typename P2C_t>
119class
121
123 const PVAR_t x;
124 const PVAR_t y;
125 const PVAR_t dpropx;
126 const PVAR_t dpropy;
127 const P2C_t ptcl_to_grd;
128 const idx_t nrows;
129 const real_t hx;
130 const real_t hy;
131 const real_t D;
132 GVAR_t M;
133 GVAR_t gvar;
134
135 bool apply_mass;
136
137public :
138
139 p2gd_step2 (const PVAR_t x_, const PVAR_t y_, const GVAR_t M_,
140 GVAR_t gvar_, const P2C_t ptcl_to_grd_, const idx_t nrows_,
141 const real_t hx_, const real_t hy_, const real_t D_, const PVAR_t dpropx_, const PVAR_t dpropy_, bool apply_mass_)
142 : x(x_), y(y_), M(M_), gvar(gvar_),
143 ptcl_to_grd(ptcl_to_grd_), nrows(nrows_), hx(hx_), hy(hy_),
144 D(D_), dpropx(dpropx_), dpropy(dpropy_), apply_mass(apply_mass_) {};
145
146 DEVICE
147 void
148 operator() (idx_t ip) {
149 using qgt = quadgrid_t<GVAR_t>;
150 real_t Nx = 0.0, Ny = 0.0;
151 auto xx = x[ip];
152 auto yy = y[ip];
153 auto r = qgt::gind2row (ptcl_to_grd[ip], nrows);
154 auto c = qgt::gind2col (ptcl_to_grd[ip], nrows);
155 for (idx_t inode = 0; inode < 4; ++inode) {
156 Nx = apply_mass ? qgt::shg (xx, yy, 0, inode, c, r, hx, hy) / M[qgt::gt(inode, c, r, nrows)] :
157 qgt::shg (xx, yy, 0, inode, c, r, hx, hy);
158 Ny = apply_mass ? qgt::shg (xx, yy, 1, inode, c, r, hx, hy) / M[qgt::gt(inode, c, r, nrows)] :
159 qgt::shg (xx, yy, 1, inode, c, r, hx, hy);
160
161 atomicAdd(&(gvar[qgt::gt(inode, c, r, nrows)]), (Nx*dpropx[ip] + Ny*dpropy[ip])*D);
162 }
163 }
164
165};
166
167//Custom G2P
168template<typename GVAR_t, typename PVAR_t, typename P2C_t>
169class
170g2p_step3 {
171
173 PVAR_t x;
174 PVAR_t y;
175 const GVAR_t M;
176 const GVAR_t gvar1;
177 const GVAR_t gvar2;
178 const P2C_t ptcl_to_grd;
179 const idx_t nrows;
180 const real_t hx;
181 const real_t hy;
182 PVAR_t dprop;
183 bool apply_mass;
184
185public :
186
187 g2p_step3 (PVAR_t x_, PVAR_t y_, const GVAR_t M_,
188 const GVAR_t gvar1_, const GVAR_t gvar2_, const P2C_t ptcl_to_grd_, const idx_t nrows_,
189 const real_t hx_, const real_t hy_, PVAR_t dprop_, bool apply_mass_)
190 : x(x_), y(y_), M(M_), gvar1(gvar1_), gvar2(gvar2_),
191 ptcl_to_grd(ptcl_to_grd_), nrows(nrows_), hx(hx_), hy(hy_),
192 dprop(dprop_), apply_mass(apply_mass_) {};
193
194 DEVICE
195 void
196 operator() (idx_t ip) {
197 using qgt = quadgrid_t<GVAR_t>;
198 real_t N = 0.0;
199 auto xx = x[ip];
200 auto yy = y[ip];
201 auto r = qgt::gind2row (ptcl_to_grd[ip], nrows);
202 auto c = qgt::gind2col (ptcl_to_grd[ip], nrows);
203 for (idx_t inode = 0; inode < 4; ++inode) {
204 N = apply_mass ? qgt::shp (xx, yy, inode, c, r, hx, hy) * M[qgt::gt(inode, c, r, nrows)] :
205 qgt::shp (xx, yy, inode, c, r, hx, hy);
206 dprop[ip] += N * (gvar1[qgt::gt(inode, c, r, nrows)] + gvar2[qgt::gt(inode, c, r, nrows)]);
207 }
208 }
209};
210
211
212template<typename GVAR_t>
215 GVAR_t Jdiffy;
217public:
218
219 boundary(GVAR_t Jdiffy_, idx_t nx_, idx_t ny_) :
220 Jdiffy(Jdiffy_), nx(nx_), ny(ny_) {}
221
222 DEVICE
223 void
225 using qgt = quadgrid_t<GVAR_t>;
226
227 Jdiffy[qgt::sub2gind(ny, i, ny+1)] = 0;
228 Jdiffy[qgt::sub2gind(0, i, ny+1)] = 0;
229
230 }
231
232};
233
234
235
236#endif
void atomicAdd(T *x, const T y)
Definition atomicAdd.h:9
particles_t::idx_t idx_t
boundary(GVAR_t Jdiffy_, idx_t nx_, idx_t ny_)
DEVICE void operator()(idx_t i)
particles_t::idx_t idx_t
const real_t hx
g2p_step3(PVAR_t x_, PVAR_t y_, const GVAR_t M_, const GVAR_t gvar1_, const GVAR_t gvar2_, const P2C_t ptcl_to_grd_, const idx_t nrows_, const real_t hx_, const real_t hy_, PVAR_t dprop_, bool apply_mass_)
const idx_t nrows
const GVAR_t gvar1
const GVAR_t M
const real_t hy
const GVAR_t gvar2
const P2C_t ptcl_to_grd
const PVAR_t y
const PVAR_t x
const PVAR_t dprop1
const real_t hx
const idx_t nrows
const PVAR_t dprop2
const P2C_t ptcl_to_grd
DEVICE void operator()(idx_t ip)
const real_t hy
p2g_step1(const PVAR_t x_, const PVAR_t y_, GVAR_t M_, GVAR_t gvar_, const P2C_t ptcl_to_grd_, const idx_t nrows_, const real_t hx_, const real_t hy_, const PVAR_t dprop1_, const PVAR_t dprop2_, bool apply_mass_)
particles_t::idx_t idx_t
const idx_t nrows
particles_t::idx_t idx_t
const PVAR_t y
const PVAR_t dpropy
const PVAR_t x
const real_t hx
const real_t D
const PVAR_t dpropx
const P2C_t ptcl_to_grd
p2gd_step2(const PVAR_t x_, const PVAR_t y_, const GVAR_t M_, GVAR_t gvar_, const P2C_t ptcl_to_grd_, const idx_t nrows_, const real_t hx_, const real_t hy_, const real_t D_, const PVAR_t dpropx_, const PVAR_t dpropy_, bool apply_mass_)
const real_t hy
Functor class for moving particles.
std::vector< double > & vx
std::vector< double > & y
stepper(PVAR_t x_, PVAR_t y_, PVAR_t vx_, PVAR_t vy_, real_t dt_)
std::vector< double > & x
std::vector< double > & vy
#define DEVICE
double real_t
#define HOST
HOST DEVICE real_t operator()(real_t value) const
quadgrid_t< vector_t< real_t > >::idx_t idx_t
datatype for indexing into vectors of properties
Definition particles.h:32
HOST DEVICE real_t operator()(real_t num, real_t den) const