IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
FEMVector.h
Go to the documentation of this file.
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 "Types/ViewTypes.h"
10#include "Field/HaloCells.h"
11
12namespace ippl {
13
29 template <typename T>
31 FEMVector<T>,
32 sizeof(typename detail::ViewType<T, 1>::view_type)>{
33 public:
43 static constexpr unsigned dim = 1;
44
54 using value_type = T;
55
68 FEMVector(size_t n, std::vector<size_t> neighbors,
69 std::vector< Kokkos::View<size_t*> > sendIdxs,
70 std::vector< Kokkos::View<size_t*> > recvIdxs);
71
72
81 KOKKOS_FUNCTION FEMVector(const FEMVector<T>& other);
82
83
94 FEMVector(size_t n);
95
96
104 void fillHalo();
105
113 void accumulateHalo();
114
120 void setHalo(T setValue);
121
122
131 FEMVector<T>& operator= (T value);
132
133
146 template <typename E, size_t N>
148
149
159
160
161
170 KOKKOS_INLINE_FUNCTION T operator[] (size_t i) const;
171
172
181 KOKKOS_INLINE_FUNCTION T operator() (size_t i) const;
182
183
191 const Kokkos::View<T*>& getView() const;
192
193
197 size_t size() const;
198
199
210 FEMVector<T> deepCopy() const;
211
212
225 template <typename K>
227
228
239 void pack(const Kokkos::View<size_t*>& idxStore);
240
241
256 template <typename Op>
257 void unpack(const Kokkos::View<size_t*>& idxStore);
258
259
264 struct Assign{
265 KOKKOS_INLINE_FUNCTION void operator()(T& lhs, const T& rhs) const {
266 lhs = rhs;
267 }
268 };
269
270
275 struct AssignAdd{
276 KOKKOS_INLINE_FUNCTION void operator()(T& lhs, const T& rhs) const {
277 lhs += rhs;
278 }
279 };
280
281
282 private:
294
306 BoundaryInfo (std::vector<size_t> neighbors,
307 std::vector< Kokkos::View<size_t*> > sendIdxs,
308 std::vector< Kokkos::View<size_t*> > recvIdxs_m);
309
310
320 std::vector<size_t> neighbors_m;
321
335 std::vector< Kokkos::View<size_t*> > sendIdxs_m;
336
352 std::vector< Kokkos::View<size_t*> > recvIdxs_m;
353
354
365 };
366
373 Kokkos::View<T*> data_m;
374
375
385 std::shared_ptr<BoundaryInfo> boundaryInfo_m;
386
387 };
388
389
404 template <typename T>
406 T localSum = 0;
407 auto aView = a.getView();
408 auto bView = b.getView();
409
410
411 size_t n = aView.extent(0);
412 Kokkos::parallel_reduce("FEMVector innerProduct", n,
413 KOKKOS_LAMBDA(const size_t i, T& val){
414 val += aView(i)*bView(i);
415 },
416 Kokkos::Sum<T>(localSum)
417 );
418
419 T globalSum = 0;
420 ippl::Comm->allreduce(localSum, globalSum, 1, std::plus<T>());
421 return globalSum;
422 }
423
424 template <typename T>
425 T norm(const FEMVector<T>& v, int p = 2) {
426
427 T local = 0;
428 auto view = v.getView();
429 size_t n = view.extent(0);
430 switch (p) {
431 case 0: {
432 Kokkos::parallel_reduce("FEMVector l0 norm", n,
433 KOKKOS_LAMBDA(const size_t i, T& val) {
434 val = Kokkos::max(val, Kokkos::abs(view(i)));
435 },
436 Kokkos::Max<T>(local)
437 );
438 T globalMax = 0;
439 ippl::Comm->allreduce(local, globalMax, 1, std::greater<T>());
440 return globalMax;
441 }
442 default: {
443 Kokkos::parallel_reduce("FEMVector lp norm", n,
444 KOKKOS_LAMBDA(const size_t i, T& val) {
445 val += std::pow(Kokkos::abs(view(i)), p);
446 },
447 Kokkos::Sum<T>(local)
448 );
449 T globalSum = 0;
450 ippl::Comm->allreduce(local, globalSum, 1, std::plus<T>());
451 return std::pow(globalSum, 1.0 / p);
452 }
453 }
454 }
455} // namespace ippl
456
457
458#include "FEMVector.hpp"
459
460#endif // IPPL_FEMVECTOR_H
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:405
std::unique_ptr< mpi::Communicator > Comm
Definition Ippl.h:22
T norm(const FEMVector< T > &v, int p=2)
Definition FEMVector.h:425
1D vector used in the context of FEM.
Definition FEMVector.h:32
void unpack(const Kokkos::View< size_t * > &idxStore)
Unpack data from BoundaryInfo::commBuffer_m into FEMVector::data_m after communication.
std::shared_ptr< BoundaryInfo > boundaryInfo_m
Struct holding all the MPI and boundary information.
Definition FEMVector.h:385
T value_type
Dummy type definition in order for the detail::Expression defined operators to work.
Definition FEMVector.h:54
static constexpr unsigned dim
Dummy parameter in order for the detail::Expression defined operators to work.
Definition FEMVector.h:43
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.
FEMVector< T > & operator=(T value)
Set all the values of the vector to value.
const Kokkos::View< T * > & getView() const
Get underlying data view.
KOKKOS_INLINE_FUNCTION T operator()(size_t i) const
Subscript operator to get value at position i.
Kokkos::View< T * > data_m
Data this object is storing.
Definition FEMVector.h:373
void pack(const Kokkos::View< size_t * > &idxStore)
Pack data into BoundaryInfo::commBuffer_m for MPI communication.
void accumulateHalo()
Accumulate halo values in neighbor.
Definition FEMVector.hpp:95
size_t size() const
Get the size (number of elements) of the vector.
KOKKOS_INLINE_FUNCTION T operator[](size_t i) const
Subscript operator to get value at position i.
FEMVector(size_t n, std::vector< size_t > neighbors, std::vector< Kokkos::View< size_t * > > sendIdxs, std::vector< Kokkos::View< size_t * > > recvIdxs)
Constructor taking size, neighbors, and halo exchange indices.
Definition FEMVector.hpp:4
FEMVector< T > deepCopy() const
Create a deep copy, where all the information of this vector is copied to a new one.
void setHalo(T setValue)
Set the halo cells to setValue.
Struct for assigment operator to be used with FEMVector::unpack().
Definition FEMVector.h:264
KOKKOS_INLINE_FUNCTION void operator()(T &lhs, const T &rhs) const
Definition FEMVector.h:265
Struct for addition+assignment operator to be used with FEMVector::unpack().
Definition FEMVector.h:275
KOKKOS_INLINE_FUNCTION void operator()(T &lhs, const T &rhs) const
Definition FEMVector.h:276
std::vector< Kokkos::View< size_t * > > recvIdxs_m
Stores indices of FEMVector::data_m which are part of the halo.
Definition FEMVector.h:352
std::vector< size_t > neighbors_m
Stores the ranks of the neighboring MPI tasks.
Definition FEMVector.h:320
BoundaryInfo(std::vector< size_t > neighbors, std::vector< Kokkos::View< size_t * > > sendIdxs, std::vector< Kokkos::View< size_t * > > recvIdxs_m)
constructor for a BoundaryInfo object.
Definition FEMVector.hpp:29
std::vector< Kokkos::View< size_t * > > sendIdxs_m
Stores indices of FEMVector::data_m which need to be send to the MPI neighbors.
Definition FEMVector.h:335
detail::FieldBufferData< T > commBuffer_m
Buffer for MPI communication.
Definition FEMVector.h:364