OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Interpolator.h
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 *
7 * Visit http://people.web.psi.ch/adelmann/ for more details
8 *
9 ***************************************************************************/
10
11#ifndef INTERPOLATOR_H
12#define INTERPOLATOR_H
13
14// include files
15#include "Field/BareField.h"
16#include "Field/LField.h"
18#include "Index/NDIndex.h"
19#include "Meshes/Centering.h"
20#include "AppTypes/Vektor.h"
21#include "Utility/IpplInfo.h"
23
24#include <ostream>
25#include <vector>
26
27// Helper class and functions for finding nearest grid point given centering
28
29// A tag indicating the Field centering type
30template <class C>
32};
33
34// Return NDIndex referring to the nearest Field element to the given position
35template <class PT, unsigned Dim, class M>
36inline
37NDIndex<Dim> FindNGP(const M& mesh, const Vektor<PT,Dim>& ppos,
39 return mesh.getCellContaining(ppos);
40}
41
42template <class PT, unsigned Dim, class M>
43inline
44NDIndex<Dim> FindNGP(const M& mesh, const Vektor<PT,Dim>& ppos,
46 return mesh.getNearestVertex(ppos);
47}
48
49template <class PT, unsigned Dim, class M>
50inline
51std::vector<NDIndex<Dim> > FindNGP(const M& mesh, const Vektor<PT,Dim>&ppos,
53 std::vector<NDIndex<Dim> > ngp;
54 ngp.push_back(mesh.getCellContaining(ppos));
55 ngp.push_back(mesh.getNearestVertex(ppos));
56 return ngp;
57}
58
59// Return position of element indicated by NDIndex
60template <class PT, unsigned Dim, class M>
61inline
62void FindPos(Vektor<PT,Dim>& pos, const M& mesh, const NDIndex<Dim>& indices,
64 pos = mesh.getCellPosition(indices);
65 return;
66}
67
68template <class PT, unsigned Dim, class M>
69inline
70void FindPos(Vektor<PT,Dim>& pos, const M& mesh, const NDIndex<Dim>& indices,
72 pos = mesh.getVertexPosition(indices);
73 return;
74}
75
76template <class PT, unsigned Dim, class M>
77inline
78void FindPos(std::vector<Vektor<PT,Dim> >& pos, const M& mesh,
79 const std::vector<NDIndex<Dim> >& indices, CenteringTag<Edge>) {
80 pos.resize(Dim);
81 Vektor<PT,Dim> cell_pos = mesh.getCellPosition(indices[0]);
82 Vektor<PT,Dim> vert_pos = mesh.getVertexPosition(indices[1]);
83
84 for (unsigned int d = 0; d < Dim; ++ d) {
85 pos[d] = vert_pos;
86 pos[d](d) = cell_pos(d);
87 }
88
89 return;
90}
91
92// Find sizes of next mesh element
93template <class PT, unsigned Dim, class M>
94inline
95void FindDelta(Vektor<PT,Dim>& delta, const M& mesh, const NDIndex<Dim>& gp,
97 NDIndex<Dim> vp;
98 for (unsigned d=0; d<Dim; ++d) vp[d] = gp[d] + 1;
99 delta = mesh.getDeltaCell(vp);
100 return;
101}
102
103template <class PT, unsigned Dim, class M>
104inline
105void FindDelta(Vektor<PT,Dim>& delta, const M& mesh, const NDIndex<Dim>& gp,
107 delta = mesh.getDeltaVertex(gp);
108 return;
109}
110
111template <class PT, unsigned Dim, class M>
112inline
113void FindDelta(std::vector<Vektor<PT,Dim> >& delta, const M& mesh,
114 const std::vector<NDIndex<Dim> >& gp, CenteringTag<Edge>) {
115 NDIndex<Dim> vp;
116 for (unsigned d=0; d<Dim; ++d) vp[d] = (gp[0])[d] + 1;
117 delta.resize(2U);
118 delta[0] = mesh.getDeltaCell(vp);
119 delta[1] = mesh.getDeltaVertex(gp[1]);
120 return;
121}
122
123
124// InterpolatorTraits struct -- used to specify type of mesh info to cache
125// (specialized by each interpolator subclass)
126
127template <class T, unsigned Dim, class InterpolatorType>
129
130// define struct for cached mesh info for 1st-order interpolators
131template <class T, unsigned Dim>
135};
136
137template <class T, unsigned Dim>
138inline std::ostream &operator<<(std::ostream &o, const CacheData1<T,Dim> &c)
139{
140 o << "(" << c.Index_m << "," << c.Delta_m << ")";
141 return o;
142}
143
144
145// define struct for cached mesh info for CIC interpolator
146template <class T, unsigned Dim>
151};
152
153//BENI:
154// define struct for cached mesh info for TSC interpolator
155template <class T, unsigned Dim>
160};
161
162template <class T, unsigned Dim>
163inline std::ostream &operator<<(std::ostream &o, const CacheDataCIC<T,Dim> &c)
164{
165 Vektor<int,Dim> offset;
166 for (unsigned int i=0; i < Dim; ++i)
167 offset[i] = c.Offset_m[i];
168 o << "(" << c.Index_m << "," << c.Delta_m << "," << offset << ")";
169 return o;
170}
171
172
173/* Interpolator -- Definition of base class for interpolation of data
174 for a single particle to or from a IPPL Field. */
175
177
178protected:
179
180 // helper function, similar to BareField::localElement, but return iterator
181 template <class T, unsigned Dim>
184
185 typename BareField<T,Dim>::const_iterator_if lf_i, lf_end = f.end_if();
186 for (lf_i = f.begin_if(); lf_i != lf_end; ++lf_i) {
187 LField<T,Dim>& lf(*(*lf_i).second);
188 if ( lf.getOwned().contains(pt) ) {
189 // found it ... get iterator for requested element
190 return lf.begin(pt);
191 }
192 }
193
194 // if not found ... try examining guard cell layers
195 for (lf_i = f.begin_if(); lf_i != lf_end; ++lf_i) {
196 LField<T,Dim>& lf(*(*lf_i).second);
197 if ( lf.getAllocated().contains(pt) ) {
198 // found it ... get iterator for requested element
199 return lf.begin(pt);
200 }
201 }
202
203 // throw ("Interploator:getFieldIter: attempt to access non-local index");
204
205
206 // if we're here, we did not find it ... it must not be local
207 ERRORMSG("Interpolator::getFieldIter: attempt to access non-local index");
208 ERRORMSG(pt << " on node " << Ippl::myNode() << endl);
209 ERRORMSG("Dumping local owned and allocated domains:" << endl);
210 int lfc = 0;
211 for ( lf_i = f.begin_if(); lf_i != lf_end ; ++lf_i, ++lfc ) {
212 LField<T,Dim>& lf(*(*lf_i).second);
213 ERRORMSG(lfc << ": owned = " << lf.getOwned());
214 ERRORMSG(", allocated = " << lf.getAllocated() << endl);
215 }
216 ERRORMSG("Error occurred for BareField with layout = " << f.getLayout());
217 ERRORMSG(endl);
218 ERRORMSG("Calling abort ..." << endl);
219 Ippl::abort();
220 return (*(*(f.begin_if())).second).begin();
221
222 }
223
224public:
225 // constructor/destructor
228
229 // gather/scatter function interfaces (implemented in derived classes)
230 /*
231
232 // scatter particle data into Field using particle position and mesh
233 template <class FT, unsigned Dim, class M, class C, class PT>
234 static
235 void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
236 const Vektor<PT,Dim>& ppos, const M& mesh);
237
238 // scatter particle data into Field using particle position and mesh
239 // and cache mesh information for reuse
240 template <class FT, unsigned Dim, class M, class C, class PT>
241 static
242 void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
243 const Vektor<PT,Dim>& ppos, const M& mesh,
244 InterpolatorTraits<PT,Dim,Interpolator>::Cache_t& cache);
245
246 // scatter particle data into Field using cached mesh information
247 template <class FT, unsigned Dim, class M, class C, class PT>
248 static
249 void scatter(const FT& pdata, Field<FT,Dim,M,C>& f,
250 const InterpolatorTraits<PT,Dim,Interpolator>::Cache_t& cache);
251
252
253 // gather particle data from Field using particle position and mesh
254 template <class FT, unsigned Dim, class M, class C, class PT>
255 static
256 void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
257 const Vektor<PT,Dim>& ppos, const M& mesh);
258
259 // gather particle data from Field using particle position and mesh
260 // and cache mesh information for reuse
261 template <class FT, unsigned Dim, class M, class C, class PT>
262 static
263 void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
264 const Vektor<PT,Dim>& ppos, const M& mesh,
265 InterpolatorTraits<PT,Dim,Interpolator>::Cache_t& cache);
266
267 // gather particle data from Field using cached mesh information
268 template <class FT, unsigned Dim, class M, class C, class PT>
269 static
270 void gather(FT& pdata, const Field<FT,Dim,M,C>& f,
271 const InterpolatorTraits<PT,Dim,Interpolator>::Cache_t& cache);
272
273 */
274
275};
276
277#endif // INTERPOLATOR_H
278
279/***************************************************************************
280 * $RCSfile: Interpolator.h,v $ $Author: adelmann $
281 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:28 $
282 * IPPL_VERSION_ID: $Id: Interpolator.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $
283 ***************************************************************************/
const unsigned Dim
void FindDelta(Vektor< PT, Dim > &delta, const M &mesh, const NDIndex< Dim > &gp, CenteringTag< Cell >)
Definition: Interpolator.h:95
NDIndex< Dim > FindNGP(const M &mesh, const Vektor< PT, Dim > &ppos, CenteringTag< Cell >)
Definition: Interpolator.h:37
std::ostream & operator<<(std::ostream &o, const CacheData1< T, Dim > &c)
Definition: Interpolator.h:138
void FindPos(Vektor< PT, Dim > &pos, const M &mesh, const NDIndex< Dim > &indices, CenteringTag< Cell >)
Definition: Interpolator.h:62
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
Definition: Vektor.h:32
iterator_if begin_if()
Definition: BareField.h:100
ac_id_larray::const_iterator const_iterator_if
Definition: BareField.h:93
Layout_t & getLayout() const
Definition: BareField.h:131
iterator_if end_if()
Definition: BareField.h:101
Definition: LField.h:58
const NDIndex< Dim > & getOwned() const
Definition: LField.h:99
const NDIndex< Dim > & getAllocated() const
Definition: LField.h:98
const iterator & begin() const
Definition: LField.h:110
Vektor< T, Dim > Delta_m
Definition: Interpolator.h:134
NDIndex< Dim > Index_m
Definition: Interpolator.h:133
NDIndex< Dim > Index_m
Definition: Interpolator.h:148
int Offset_m[Dim]
Definition: Interpolator.h:149
Vektor< T, Dim > Delta_m
Definition: Interpolator.h:150
NDIndex< Dim > Index_m
Definition: Interpolator.h:157
Vektor< T, Dim > Delta_m
Definition: Interpolator.h:159
int Offset_m[Dim]
Definition: Interpolator.h:158
static CompressedBrickIterator< T, Dim > getFieldIter(const BareField< T, Dim > &f, const NDIndex< Dim > &pt)
Definition: Interpolator.h:183
static void abort(const char *=0)
Definition: IpplInfo.cpp:616
static int myNode()
Definition: IpplInfo.cpp:691