quadgrid 0.1
simple cartesian quad grid with particles for c++/octave
particles_imp.h
Go to the documentation of this file.
1#ifndef PARTICLES_IMP_H
2#define PARTICLES_IMP_H
3
4template<typename str>
5void
7(std::map<std::string, std::vector<double>> & vars,
8 std::initializer_list<str> const & pvarnames,
9 std::initializer_list<str> const & gvarnames,
10 bool apply_mass, assignment_t OP) const {
11 using strlist = std::initializer_list<str> const &;
12 p2g<strlist, strlist>
13 (vars, pvarnames, gvarnames, apply_mass, OP);
14}
15
16template<typename GT, typename PT>
17void
19(std::map<std::string, std::vector<double>> & vars,
20 PT const & pvarnames,
21 GT const & gvarnames,
22 bool apply_mass,
23 assignment_t OP) const {
24
26 double N = 0.0, xx = 0.0, yy = 0.0;
27 idx_t idx = 0;
28
29 for (std::size_t ivar = 0; ivar < std::size(gvarnames); ++ivar) {
30 auto & gvar = vars[getkey(gvarnames, ivar)];
31 auto const & dprop = dprops.at (getkey(pvarnames, ivar));
32 for (auto icell = grid.begin_cell_sweep ();
33 icell != grid.end_cell_sweep (); ++icell) {
34
35 if (grd_to_ptcl.count (icell->get_global_cell_idx ()) > 0)
36 for (idx_t ii = 0;
37 ii < grd_to_ptcl.at (icell->get_global_cell_idx ()).size ();
38 ++ii) {
39 idx = grd_to_ptcl.at (icell->get_global_cell_idx ())[ii];
40 xx = x[idx];
41 yy = y[idx];
42
43 for (idx_t inode = 0; inode < 4; ++inode) {
44 N = icell->shp(xx, yy, inode);
45
46 OP (gvar[icell->gt(inode)],
47 N * dprop[idx]);
48 }
49 }
50 }
51 }
52
53 if (apply_mass)
54 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar)
55 for (idx_t ii = 0; ii < M.size (); ++ii) {
56 vars[getkey(gvarnames, ivar)][ii] /= M[ii];
57 }
58}
59
60
61template<typename str>
62void
64(std::map<std::string, std::vector<double>> & vars,
65 std::initializer_list<str> const & pxvarnames,
66 std::initializer_list<str> const & pyvarnames,
67 std::string const &area,
68 std::initializer_list<str> const & gvarnames,
69 bool apply_mass, assignment_t OP) const {
70 using strlist = std::initializer_list<str> const &;
71 p2gd<strlist, strlist>
72 (vars, pxvarnames, pyvarnames, area, gvarnames, apply_mass, OP);
73}
74
75
76template<typename GT, typename PT>
77void
79(std::map<std::string, std::vector<double>> & vars,
80 PT const & pxvarnames,
81 PT const & pyvarnames,
82 std::string const &area,
83 GT const & gvarnames,
84 bool apply_mass, assignment_t OP) const {
85
87 double xx = 0.0, yy = 0.0, Nx = 0.0, Ny = 0.0;
88 idx_t idx = 0;
89
90 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar) {
91 auto & gvar = vars[getkey(gvarnames, ivar)];
92 auto const & dpropx = dprops.at (getkey(pxvarnames, ivar));
93 auto const & dpropy = dprops.at (getkey(pyvarnames, ivar));
94 auto const & dproparea = dprops.at (area);
95 for (auto icell = grid.begin_cell_sweep();
96 icell != grid.end_cell_sweep(); ++icell) {
97
98 if (grd_to_ptcl.count (icell->get_global_cell_idx ()) > 0)
99 for (idx_t ii = 0;
100 ii < grd_to_ptcl.at (icell->get_global_cell_idx ()).size ();
101 ++ii) {
102
103 idx = grd_to_ptcl.at (icell->get_global_cell_idx())[ii];
104 xx = x[idx];
105 yy = y[idx];
106
107 for (idx_t inode=0; inode<4; ++inode) {
108
109 Nx = icell->shg (xx, yy, 0, inode);
110 Ny = icell->shg (xx, yy, 1, inode);
111
112
113 OP (gvar[icell->gt(inode)],
114 (Nx * dpropx[idx] + Ny * dpropy[idx]) * dproparea[idx]);
115 }
116 }
117 }
118
119 }
120
121 if (apply_mass)
122 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar)
123 for (idx_t ii = 0; ii < M.size (); ++ii) {
124 vars[getkey(gvarnames, ivar)][ii] /= M[ii];
125 }
126
127}
128
129template<typename str>
130void
132(const std::map<std::string, std::vector<double>> & vars,
133 std::initializer_list<str> const & gvarnames,
134 std::initializer_list<str> const & pvarnames,
135 bool apply_mass, assignment_t OP) {
136 using strlist = std::initializer_list<str> const &;
137 g2p<strlist, strlist> (vars, gvarnames,
138 pvarnames, apply_mass, OP);
139}
140
141template<typename GT, typename PT>
142void
144(const std::map<std::string, std::vector<double>>& vars,
145 GT const & gvarnames,
146 PT const & pvarnames,
147 bool apply_mass, assignment_t OP) {
148
150 double N = 0.0, xx = 0.0, yy = 0.0;
151 idx_t idx = 0;
152
153 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar) {
154 auto & dprop = dprops.at (getkey (pvarnames, ivar));
155 auto const & gvar = vars.at (getkey (gvarnames, ivar));
156 for (auto icell = grid.begin_cell_sweep ();
157 icell != grid.end_cell_sweep (); ++icell) {
158
159 if (grd_to_ptcl.count (icell->get_global_cell_idx ()) > 0)
160 for (idx_t ii = 0;
161 ii < grd_to_ptcl.at (icell->get_global_cell_idx ()).size ();
162 ++ii) {
163
164 idx = grd_to_ptcl.at(icell->get_global_cell_idx ())[ii];
165 xx = x[idx];
166 yy = y[idx];
167
168 for (idx_t inode = 0; inode < 4; ++inode) {
169 N = apply_mass ?
170 icell->shp(xx, yy, inode) * M[icell->gt(inode)] :
171 icell->shp(xx, yy, inode);
172
173 OP (dprop [idx], N * gvar[icell->gt(inode)]);
174 }
175 }
176 }
177 }
178}
179
180template<typename str>
181void
183(const std::map<std::string, std::vector<double>>& vars,
184 std::initializer_list<str> const & gvarnames,
185 std::initializer_list<str> const & pxvarnames,
186 std::initializer_list<str> const & pyvarnames,
187 bool apply_mass, assignment_t OP) {
188 using strlist = std::initializer_list<str> const &;
189 g2pd<strlist, strlist> (vars, gvarnames, pxvarnames,
190 pyvarnames, apply_mass, OP);
191}
192
193template<typename GT, typename PT>
194void
196(const std::map<std::string, std::vector<double>>& vars,
197 GT const & gvarnames,
198 PT const & pxvarnames,
199 PT const & pyvarnames,
200 bool apply_mass, assignment_t OP) {
201
203 double Nx = 0.0, Ny = 0.0, xx = 0.0, yy = 0.0;
204 idx_t idx = 0;
205
206 for (std::size_t ivar = 0; ivar < std::size (gvarnames); ++ivar) {
207
208 for (auto icell = grid.begin_cell_sweep ();
209 icell != grid.end_cell_sweep (); ++icell) {
210 auto & dpropx = dprops.at (getkey (pxvarnames, ivar));
211 auto & dpropy = dprops.at (getkey (pyvarnames, ivar));
212 auto const & gvar = vars.at (getkey (gvarnames, ivar));
213 if (grd_to_ptcl.count (icell->get_global_cell_idx ()) > 0)
214 for (idx_t ii = 0;
215 ii < grd_to_ptcl.at (icell->get_global_cell_idx ()).size ();
216 ++ii) {
217
218 idx = grd_to_ptcl.at(icell->get_global_cell_idx ())[ii];
219 xx = x[idx];
220 yy = y[idx];
221
222 for (idx_t inode = 0; inode < 4; ++inode) {
223 Nx = apply_mass ?
224 icell->shg(xx, yy, 0, inode) * M[icell->gt(inode)] :
225 icell->shg(xx, yy, 0, inode);
226 Ny = apply_mass ?
227 icell->shg(xx, yy, 1, inode) * M[icell->gt(inode)] :
228 icell->shg(xx, yy, 1, inode);
229
230 OP (dpropx[idx], Nx * gvar[icell->gt(inode)]);
231 OP (dpropy[idx], Ny * gvar[icell->gt(inode)]);
232 }
233 }
234 }
235
236 }
237
238}
239
240template<>
241void
242particles_t::print<particles_t::output_format::octave_ascii>
243(std::ostream & os) const;
244
245template<>
246void
247particles_t::print<particles_t::output_format::json>
248(std::ostream & os) const;
249
250template<>
251void
252particles_t::print<particles_t::output_format::csv>
253(std::ostream & os) const;
254
255#endif
Definition: quadgrid_cpp.h:15
cell_iterator begin_cell_sweep()
Definition: quadgrid_cpp_imp.h:4
cell_iterator end_cell_sweep()
Definition: quadgrid_cpp.h:308
std::function< double &(double &, const double &)> assignment_t
datatype for assignment operators
Definition: particles.h:14
void p2gd(std::map< std::string, std::vector< double > > &vars, PT const &pxvarnames, PT const &pyvarnames, std::string const &area, GT const &gvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ) const
Definition: particles_imp.h:79
void g2p(const std::map< std::string, std::vector< double > > &vars, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ)
Definition: particles.h:331
std::map< idx_t, std::vector< idx_t > > grd_to_ptcl
grid/particles connectivity.
Definition: particles.h:53
void g2pd(const std::map< std::string, std::vector< double > > &vars, GT const &gvarnames, PT const &pxvarnames, PT const &pyvarnames, bool apply_mass=false, assignment_t OP=ASSIGNMENT_OPS::PLUS_EQ)
Definition: particles_imp.h:196
const quadgrid_t< std::vector< double > > & grid
refernce to a grid object.
Definition: particles.h:54
static const std::string & getkey(std::map< std::string, std::vector< double > > const &varnames, std::size_t ivar)
Definition: particles.h:258
std::map< std::string, std::vector< double > > dprops
double type quantities associated with the particles.
Definition: particles.h:50
std::vector< double > x
x coordinate of particle positions.
Definition: particles.h:43
quadgrid_t< std::vector< double > >::idx_t idx_t
datatype for indexing into vectors of properties
Definition: particles.h:40
std::vector< double > y
y coordinate of particle positions.
Definition: particles.h:44
std::vector< double > M
Mass matrix to be used for transfers if required.
Definition: particles.h:52
void p2g(std::map< std::string, std::vector< double > > &vars, bool apply_mass=false) const
Map particle variables to the grid.
Definition: particles.h:283