Debian Codegraph @

src/atlas/grid/Stencil.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
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 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <array>
14 #include "atlas/library/config.h"
15
16 namespace atlas {
17 namespace grid {
18
19 //---------------------------------------------------------------------------------------------------------------------
20
21 template <idx_t StencilWidth>
22 class HorizontalStencil {
23 friend class ComputeHorizontalStencil;
24 std::array<idx_t, StencilWidth> i_begin_;
25 idx_t j_begin_;
26
27 public:
28 idx_t i(idx_t offset_i, idx_t offset_j) const { return i_begin_[offset_j] + offset_i; }
29 idx_t j(idx_t offset) const { return j_begin_ + offset; }
30 constexpr idx_t width() const { return StencilWidth; }
31 };
32
33 //-----------------------------------------------------------------------------
34
35 template <idx_t StencilWidth>
36 class VerticalStencil {
37 friend class ComputeVerticalStencil;
38 idx_t k_begin_;
39 idx_t k_interval_;
40 // within the stencil, a point falls in a certain interval.
41 // e.g. for a cubic stencil:
42 // + |-----|-----|-----| --> k_interval_ = -1
43 // |--+--|-----|-----| --> k_interval_ = 0
44 // |-----|--+--|-----| --> k_interval_ = 1 (the centred case)
45 // |-----|-----|--+--| --> k_interval_ = 2
46 // |-----|-----|-----| + --> k_interval_ = 3
47 public:
48 idx_t k(idx_t offset) const { return k_begin_ + offset; }
49 constexpr idx_t width() const { return StencilWidth; }
50 idx_t k_interval() const { return k_interval_; }
51 };
52
53 //-----------------------------------------------------------------------------
54
55 template <idx_t StencilWidth>
56 class Stencil3D {
57 friend class ComputeHorizontalStencil;
58 friend class ComputeVerticalStencil;
59 std::array<idx_t, StencilWidth> i_begin_;
60 idx_t j_begin_;
61 idx_t k_begin_;
62 idx_t k_interval_;
63
64 public:
65 idx_t i(idx_t offset_i, idx_t offset_j) const { return i_begin_[offset_j] + offset_i; }
66 idx_t j(idx_t offset) const { return j_begin_ + offset; }
67 idx_t k(idx_t offset) const { return k_begin_ + offset; }
68 constexpr idx_t width() const { return StencilWidth; }
69 idx_t k_interval() const { return k_interval_; }
70 };
71
72 //---------------------------------------------------------------------------------------------------------------------
73
74 } // namespace grid
75 } // namespace atlas