Line data Source code
1 : //
2 : // Class UniformCartesian
3 : // UniformCartesian class - represents uniform-spacing cartesian meshes.
4 : //
5 : #include "Utility/IpplInfo.h"
6 : #include "Utility/PAssert.h"
7 :
8 : #include "Field/BareField.h"
9 : #include "Field/Field.h"
10 :
11 : namespace ippl {
12 :
13 : template <typename T, unsigned Dim>
14 146 : KOKKOS_INLINE_FUNCTION UniformCartesian<T, Dim>::UniformCartesian()
15 : : Mesh<T, Dim>()
16 146 : , volume_m(0.0) {}
17 :
18 : template <typename T, unsigned Dim>
19 516 : KOKKOS_INLINE_FUNCTION UniformCartesian<T, Dim>::UniformCartesian(const NDIndex<Dim>& ndi,
20 : const vector_type& hx,
21 516 : const vector_type& origin) {
22 516 : this->initialize(ndi, hx, origin);
23 516 : }
24 :
25 : template <typename T, unsigned Dim>
26 528 : KOKKOS_INLINE_FUNCTION void UniformCartesian<T, Dim>::initialize(const NDIndex<Dim>& ndi,
27 : const vector_type& hx,
28 : const vector_type& origin) {
29 528 : meshSpacing_m = hx;
30 :
31 528 : volume_m = 1.0;
32 2082 : for (unsigned d = 0; d < Dim; ++d) {
33 1554 : this->gridSizes_m[d] = ndi[d].length();
34 1554 : volume_m *= meshSpacing_m[d];
35 : }
36 :
37 528 : this->setOrigin(origin);
38 528 : }
39 :
40 : template <typename T, unsigned Dim>
41 0 : KOKKOS_INLINE_FUNCTION void UniformCartesian<T, Dim>::setMeshSpacing(
42 : const vector_type& meshSpacing) {
43 0 : meshSpacing_m = meshSpacing;
44 0 : this->updateCellVolume_m();
45 0 : }
46 :
47 : template <typename T, unsigned Dim>
48 462 : KOKKOS_INLINE_FUNCTION T UniformCartesian<T, Dim>::getMeshSpacing(unsigned dim) const {
49 462 : PAssert_LT(dim, Dim);
50 462 : return meshSpacing_m[dim];
51 : }
52 :
53 : template <typename T, unsigned Dim>
54 : KOKKOS_INLINE_FUNCTION const typename UniformCartesian<T, Dim>::vector_type&
55 277 : UniformCartesian<T, Dim>::getMeshSpacing() const {
56 277 : return meshSpacing_m;
57 : }
58 :
59 : template <typename T, unsigned Dim>
60 48 : KOKKOS_INLINE_FUNCTION T UniformCartesian<T, Dim>::getCellVolume() const {
61 48 : return volume_m;
62 : }
63 :
64 : template <typename T, unsigned Dim>
65 36 : KOKKOS_INLINE_FUNCTION T UniformCartesian<T, Dim>::getMeshVolume() const {
66 36 : T ret = 1;
67 162 : for (unsigned int d = 0; d < Dim; ++d) {
68 126 : ret *= this->getGridsize(d) * this->getMeshSpacing(d);
69 : }
70 36 : return ret;
71 : }
72 :
73 : template <typename T, unsigned Dim>
74 0 : KOKKOS_INLINE_FUNCTION void UniformCartesian<T, Dim>::updateCellVolume_m() {
75 : // update cell volume
76 0 : volume_m = 1.0;
77 0 : for (unsigned i = 0; i < Dim; ++i) {
78 0 : volume_m *= meshSpacing_m[i];
79 : }
80 0 : }
81 :
82 : } // namespace ippl
|