IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
FEMVector.h
1// Class FEMVector
2// This class represents a one dimensional vector which can be used in the
3// context of FEM to represent a field defined on the DOFs of a mesh.
4
5
6#ifndef IPPL_FEMVECTOR_H
7#define IPPL_FEMVECTOR_H
8
9#include <Kokkos_MathematicalFunctions.hpp>
10
11#include "Types/ViewTypes.h"
12#include "Field/HaloCells.h"
13
14namespace ippl {
15
31 template <typename T>
33 FEMVector<T>,
34 sizeof(typename detail::ViewType<T, 1>::view_type)>{
35 public:
45 static constexpr unsigned dim = 1;
46
56 using value_type = T;
57
70 FEMVector(size_t n, std::vector<size_t> neighbors,
71 std::vector< Kokkos::View<size_t*> > sendIdxs,
72 std::vector< Kokkos::View<size_t*> > recvIdxs);
73
74
83 KOKKOS_FUNCTION FEMVector(const FEMVector<T>& other);
84
85
96 FEMVector(size_t n);
97
98
106 void fillHalo();
107
115 void accumulateHalo();
116
122 void setHalo(T setValue);
123
124
133 FEMVector<T>& operator= (T value);
134
135
148 template <typename E, size_t N>
150
151
161
162
163
172 KOKKOS_INLINE_FUNCTION T operator[] (size_t i) const;
173
174
183 KOKKOS_INLINE_FUNCTION T operator() (size_t i) const;
184
185
193 const Kokkos::View<T*>& getView() const;
194
195
199 size_t size() const;
200
201
212 FEMVector<T> deepCopy() const;
213
214
227 template <typename K>
229
230
241 void pack(const Kokkos::View<size_t*>& idxStore);
242
243
258 template <typename Op>
259 void unpack(const Kokkos::View<size_t*>& idxStore);
260
261
266 struct Assign{
267 KOKKOS_INLINE_FUNCTION void operator()(T& lhs, const T& rhs) const {
268 lhs = rhs;
269 }
270 };
271
272
277 struct AssignAdd{
278 KOKKOS_INLINE_FUNCTION void operator()(T& lhs, const T& rhs) const {
279 lhs += rhs;
280 }
281 };
282
283
284 private:
295 struct BoundaryInfo {
296
308 BoundaryInfo (std::vector<size_t> neighbors,
309 std::vector< Kokkos::View<size_t*> > sendIdxs,
310 std::vector< Kokkos::View<size_t*> > recvIdxs_m);
311
312
322 std::vector<size_t> neighbors_m;
323
337 std::vector< Kokkos::View<size_t*> > sendIdxs_m;
338
354 std::vector< Kokkos::View<size_t*> > recvIdxs_m;
355
356
366 detail::FieldBufferData<T> commBuffer_m;
367 };
368
375 Kokkos::View<T*> data_m;
376
377
387 std::shared_ptr<BoundaryInfo> boundaryInfo_m;
388
389 };
390
391
406 template <typename T>
407 T innerProduct(const FEMVector<T>& a, const FEMVector<T>& b) {
408 T localSum = 0;
409 auto aView = a.getView();
410 auto bView = b.getView();
411
412
413 size_t n = aView.extent(0);
414 Kokkos::parallel_reduce("FEMVector innerProduct", n,
415 KOKKOS_LAMBDA(const size_t i, T& val){
416 val += aView(i)*bView(i);
417 },
418 Kokkos::Sum<T>(localSum)
419 );
420
421 T globalSum = 0;
422 ippl::Comm->allreduce(localSum, globalSum, 1, std::plus<T>());
423 return globalSum;
424 }
425
426 template <typename T>
427 T norm(const FEMVector<T>& v, int p = 2) {
428
429 T local = 0;
430 auto view = v.getView();
431 size_t n = view.extent(0);
432 switch (p) {
433 case 0: {
434 Kokkos::parallel_reduce("FEMVector l0 norm", n,
435 KOKKOS_LAMBDA(const size_t i, T& val) {
436 val = Kokkos::max(val, Kokkos::abs(view(i)));
437 },
438 Kokkos::Max<T>(local)
439 );
440 T globalMax = 0;
441 ippl::Comm->allreduce(local, globalMax, 1, std::greater<T>());
442 return globalMax;
443 }
444 default: {
445 Kokkos::parallel_reduce("FEMVector lp norm", n,
446 KOKKOS_LAMBDA(const size_t i, T& val) {
447 val += Kokkos::pow(Kokkos::abs(view(i)), p);
448 },
449 Kokkos::Sum<T>(local)
450 );
451 T globalSum = 0;
452 ippl::Comm->allreduce(local, globalSum, 1, std::plus<T>());
453 return std::pow(globalSum, 1.0 / p);
454 }
455 }
456 }
457} // namespace ippl
458
459
460#include "FEMVector.hpp"
461
462#endif // IPPL_FEMVECTOR_H
1D vector used in the context of FEM.
Definition FEMVector.h:34
void unpack(const Kokkos::View< size_t * > &idxStore)
Unpack data from BoundaryInfo::commBuffer_m into FEMVector::data_m after communication.
Definition FEMVector.hpp:330
T value_type
Dummy type definition in order for the detail::Expression defined operators to work.
Definition FEMVector.h:56
static constexpr unsigned dim
Dummy parameter in order for the detail::Expression defined operators to work.
Definition FEMVector.h:45
void fillHalo()
Copy values from neighboring ranks into local halo.
Definition FEMVector.hpp:38
FEMVector< K > skeletonCopy() const
Create a new FEMVector with different data type, but same size and boundary infromation.
Definition FEMVector.hpp:270
FEMVector< T > & operator=(T value)
Set all the values of the vector to value.
Definition FEMVector.hpp:174
const Kokkos::View< T * > & getView() const
Get underlying data view.
Definition FEMVector.hpp:223
KOKKOS_INLINE_FUNCTION T operator()(size_t i) const
Subscript operator to get value at position i.
Definition FEMVector.hpp:217
void pack(const Kokkos::View< size_t * > &idxStore)
Pack data into BoundaryInfo::commBuffer_m for MPI communication.
Definition FEMVector.hpp:302
void accumulateHalo()
Accumulate halo values in neighbor.
Definition FEMVector.hpp:95
size_t size() const
Get the size (number of elements) of the vector.
Definition FEMVector.hpp:229
KOKKOS_INLINE_FUNCTION T operator[](size_t i) const
Subscript operator to get value at position i.
Definition FEMVector.hpp:211
FEMVector< T > deepCopy() const
Create a deep copy, where all the information of this vector is copied to a new one.
Definition FEMVector.hpp:234
void setHalo(T setValue)
Set the halo cells to setValue.
Definition FEMVector.hpp:152
Definition Archive.h:20
T innerProduct(const FEMVector< T > &a, const FEMVector< T > &b)
Calculate the inner product between two ippl::FEMVector(s).
Definition FEMVector.h:407
Struct for addition+assignment operator to be used with FEMVector::unpack().
Definition FEMVector.h:277
Struct for assigment operator to be used with FEMVector::unpack().
Definition FEMVector.h:266
Definition IpplExpressions.h:26
Definition HaloCells.h:23