Debian Codegraph @

src/atlas/functionspace/detail/CubedSphereStructure.h

raw
1 /*
2 * (C) Crown Copyright 2021 Met Office
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 */
7
8 #pragma once
9
10 #include "atlas/array.h"
11 #include "atlas/field.h"
12 #include "atlas/meshgenerator/detail/cubedsphere/CubedSphereUtility.h"
13 #include "atlas/parallel/omp/omp.h"
14 #include "atlas/util/Object.h"
15
16 /// Extra cubed sphere functionality for NodeColumns and CellColumns function
17 /// spaces.
18
19 namespace atlas {
20 class Field;
21 }
22
23 namespace atlas {
24 namespace functionspace {
25 namespace detail {
26
27 class CubedSphereStructure : public util::Object {
28 public:
29 CubedSphereStructure() = default;
30 CubedSphereStructure(const Field& tij, const Field& ghost, idx_t size);
31
32 /// Invalid index.
33 static constexpr idx_t invalid_index() { return -1; }
34
35 /// Number of elements.
36 idx_t size() const;
37
38 /// Number of owned elements.
39 idx_t sizeOwned() const;
40
41 /// i lower bound for tile t (including halo)
42 idx_t i_begin(idx_t) const;
43
44 /// i lower bound for tile t (including halo)
45 idx_t i_end(idx_t t) const;
46
47 /// j lower bound for tile t (including halo)
48 idx_t j_begin(idx_t t) const;
49
50 /// j lower bound for tile t (including halo)
51 idx_t j_end(idx_t t) const;
52
53 /// Return array_view index for (t, i, j).
54 idx_t index(idx_t t, idx_t i, idx_t j) const;
55
56 /// Return true if (t, i, j) is a valid index.
57 bool is_valid_index(idx_t t, idx_t i, idx_t j) const;
58
59
60 /// Return ijt field.
61 Field tij() const;
62
63 /// Return ghost/halo field.
64 Field ghost() const;
65
66 private:
67 // Bounding box struct.
68 struct BoundingBox {
69 BoundingBox();
70 idx_t iBegin;
71 idx_t iEnd;
72 idx_t jBegin;
73 idx_t jEnd;
74 };
75
76 // Bounds checking.
77 void tBoundsCheck(idx_t t) const;
78 void iBoundsCheck(idx_t i, idx_t t) const;
79 void jBoundsCheck(idx_t j, idx_t t) const;
80
81 // Row-major index of ijtToidx vectors.
82 size_t vecIndex(idx_t i, idx_t j, idx_t t) const;
83
84 // Index storage vectors.
85 std::vector<std::vector<idx_t>> tijToIdx_;
86
87 // Array of bounding boxes.
88 std::array<BoundingBox, 6> ijBounds_;
89
90 // ijt field.
91 Field tij_;
92
93 // ghost field.
94 Field ghost_;
95
96 // Number cells/nodes.
97 idx_t nElems_{};
98
99 // Number of owned cells/nodes.
100 idx_t nOwnedElems_{};
101 };
102
103 } // namespace detail
104 } // namespace functionspace
105 } // namespace atlas