Debian Codegraph @

src/atlas/functionspace/CellColumns.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 "atlas/field/FieldSet.h"
14 #include "atlas/functionspace/FunctionSpace.h"
15 #include "atlas/functionspace/detail/FunctionSpaceImpl.h"
16 #include "atlas/mesh/Halo.h"
17 #include "atlas/mesh/Mesh.h"
18 #include "atlas/option.h"
19 #include "atlas/util/Config.h"
20
21 // ----------------------------------------------------------------------------
22 // Forward declarations
23
24 namespace atlas {
25 class FieldSet;
26 }
27
28 namespace atlas {
29 namespace parallel {
30 class HaloExchange;
31 class GatherScatter;
32 class Checksum;
33 } // namespace parallel
34 } // namespace atlas
35
36 namespace atlas {
37 namespace functionspace {
38 namespace detail {
39
40 // ----------------------------------------------------------------------------
41
42 class CellColumns : public functionspace::FunctionSpaceImpl {
43 public:
44 CellColumns(const Mesh&, const eckit::Configuration& = util::NoConfig());
45
46 ~CellColumns() override;
47
48 static std::string static_type() { return "CellColumns"; }
49 std::string type() const override { return static_type(); }
50
51 std::string distribution() const override;
52
53 idx_t nb_cells() const;
54 idx_t nb_cells_global() const; // Only on MPI rank 0, will this be different from 0
55 idx_t levels() const;
56 std::vector<idx_t> nb_cells_global_foreach_rank() const;
57
58 const Mesh& mesh() const { return mesh_; }
59 Mesh& mesh() { return mesh_; }
60
61 const mesh::HybridElements& cells() const { return cells_; }
62 mesh::HybridElements& cells() { return cells_; }
63
64 // -- Field creation methods
65
66 Field createField(const eckit::Configuration&) const override;
67
68 Field createField(const Field&, const eckit::Configuration&) const override;
69
70 // -- Parallelisation aware methods
71
72 const mesh::Halo& halo() const { return halo_; }
73
74 void haloExchange(const FieldSet&, bool on_device = false) const override;
75 void haloExchange(const Field&, bool on_device = false) const override;
76 const parallel::HaloExchange& halo_exchange() const;
77
78 void gather(const FieldSet&, FieldSet&) const override;
79 void gather(const Field&, Field&) const override;
80 const parallel::GatherScatter& gather() const override;
81
82 void scatter(const FieldSet&, FieldSet&) const override;
83 void scatter(const Field&, Field&) const override;
84 const parallel::GatherScatter& scatter() const override;
85
86 std::string checksum(const FieldSet&) const;
87 std::string checksum(const Field&) const;
88 const parallel::Checksum& checksum() const;
89
90 idx_t size() const override { return nb_cells_; }
91
92 const Grid& grid() const override;
93
94 Field lonlat() const override;
95
96 Field remote_index() const override;
97
98 Field global_index() const override;
99
100 Field ghost() const override;
101
102 Field partition() const override;
103
104 std::string mpi_comm() const override { return mesh_.mpi_comm(); }
105
106 private: // methods
107 idx_t config_size(const eckit::Configuration& config) const;
108 array::DataType config_datatype(const eckit::Configuration&) const;
109 std::string config_name(const eckit::Configuration&) const;
110 idx_t config_levels(const eckit::Configuration&) const;
111 array::ArrayShape config_shape(const eckit::Configuration&) const;
112 void set_field_metadata(const eckit::Configuration&, Field&) const;
113 size_t footprint() const override;
114
115 private: // data
116 mutable Grid grid_;
117 Mesh mesh_; // non-const because functionspace may modify mesh
118 mesh::HybridElements& cells_; // non-const because functionspace may modify mesh
119 idx_t nb_levels_;
120 mesh::Halo halo_;
121 idx_t nb_cells_;
122 mutable long nb_cells_global_{-1};
123 mutable util::ObjectHandle<parallel::GatherScatter> gather_scatter_; // without ghost
124 mutable util::ObjectHandle<parallel::HaloExchange> halo_exchange_;
125 mutable util::ObjectHandle<parallel::Checksum> checksum_;
126 };
127
128 // -------------------------------------------------------------------
129
130 extern "C" {
131
132 CellColumns* atlas__fs__CellColumns__new(Mesh::Implementation* mesh, const eckit::Configuration* config);
133 void atlas__fs__CellColumns__delete(CellColumns* This);
134 int atlas__fs__CellColumns__nb_cells(const CellColumns* This);
135 Mesh::Implementation* atlas__fs__CellColumns__mesh(CellColumns* This);
136 mesh::Cells* atlas__fs__CellColumns__cells(CellColumns* This);
137 field::FieldImpl* atlas__fs__CellColumns__create_field(const CellColumns* This, const eckit::Configuration* options);
138 field::FieldImpl* atlas__fs__CellColumns__create_field_template(const CellColumns* This,
139 const field::FieldImpl* field_template,
140 const eckit::Configuration* options);
141
142 void atlas__fs__CellColumns__halo_exchange_fieldset(const CellColumns* This, field::FieldSetImpl* fieldset);
143 void atlas__fs__CellColumns__halo_exchange_field(const CellColumns* This, field::FieldImpl* field);
144 const parallel::HaloExchange* atlas__fs__CellColumns__get_halo_exchange(const CellColumns* This);
145
146 void atlas__fs__CellColumns__gather_fieldset(const CellColumns* This, const field::FieldSetImpl* local,
147 field::FieldSetImpl* global);
148 void atlas__fs__CellColumns__gather_field(const CellColumns* This, const field::FieldImpl* local,
149 field::FieldImpl* global);
150 const parallel::GatherScatter* atlas__fs__CellColumns__get_gather(const CellColumns* This);
151
152 void atlas__fs__CellColumns__scatter_fieldset(const CellColumns* This, const field::FieldSetImpl* global,
153 field::FieldSetImpl* local);
154 void atlas__fs__CellColumns__scatter_field(const CellColumns* This, const field::FieldImpl* global,
155 field::FieldImpl* local);
156 const parallel::GatherScatter* atlas__fs__CellColumns__get_scatter(const CellColumns* This);
157
158 void atlas__fs__CellColumns__checksum_fieldset(const CellColumns* This, const field::FieldSetImpl* fieldset,
159 char*& checksum, int& size, int& allocated);
160 void atlas__fs__CellColumns__checksum_field(const CellColumns* This, const field::FieldImpl* field, char*& checksum,
161 int& size, int& allocated);
162 const parallel::Checksum* atlas__fs__CellColumns__get_checksum(const CellColumns* This);
163 }
164
165 } // namespace detail
166
167 // -------------------------------------------------------------------
168
169 class CellColumns : public FunctionSpace {
170 public:
171 using Implementation = detail::CellColumns;
172
173 public:
174 CellColumns();
175 CellColumns(const FunctionSpace&);
176 CellColumns(const Mesh&, const eckit::Configuration&);
177 CellColumns(const Mesh& mesh);
178
179 static std::string type() { return detail::CellColumns::static_type(); }
180
181 operator bool() const { return valid(); }
182 bool valid() const { return functionspace_; }
183
184 idx_t nb_cells() const;
185 idx_t nb_cells_global() const; // Only on MPI rank 0, will this be different from 0
186 idx_t levels() const;
187
188 const Mesh& mesh() const;
189
190 const mesh::HybridElements& cells() const;
191
192 // -- Parallelisation aware methods
193 const mesh::Halo& halo() const;
194
195 const parallel::HaloExchange& halo_exchange() const;
196
197 std::string checksum(const FieldSet&) const;
198 std::string checksum(const Field&) const;
199 const parallel::Checksum& checksum() const;
200
201 private:
202 const detail::CellColumns* functionspace_;
203 };
204
205 } // namespace functionspace
206 } // namespace atlas