22 #include <type_traits> 25 #include "atlas/field/Field.h" 26 #include "atlas/library/config.h" 27 #include "atlas/runtime/Exception.h" 28 #include "atlas/util/Object.h" 29 #include "atlas/util/ObjectHandle.h" 35 #ifndef DOXYGEN_SHOULD_SKIP_THIS 44 using iterator = std::vector<Field>::iterator;
45 using const_iterator = std::vector<Field>::const_iterator;
48 static constexpr
bool is_index() {
49 return std::is_integral<T>::value or std::is_enum<T>::value;
53 using enable_if_t =
typename std::enable_if<pred, int>::type;
56 using enable_if_index_t = enable_if_t<is_index<T>()>;
64 bool empty()
const {
return !
fields_.size(); }
68 const std::string& name()
const {
return name_; }
69 std::string& name() {
return name_; }
71 template <
typename Index, enable_if_index_t<Index> = 0>
72 const Field& operator[]( Index i )
const {
76 template <
typename Index, enable_if_index_t<Index> = 0>
77 Field& operator[]( Index i ) {
81 const Field& operator[](
const std::string& name )
const {
return field( name ); }
82 Field& operator[](
const std::string& name ) {
return field( name ); }
84 template <
typename Index, enable_if_index_t<Index> = 0>
85 const Field& field( Index i )
const {
87 throw_OutOfRange(
"fieldset", i, size(), Here() );
91 template <
typename Index, enable_if_index_t<Index> = 0>
92 Field& field( Index i ) {
94 throw_OutOfRange(
"fieldset", i, size(), Here() );
98 std::vector<std::string> field_names()
const;
102 bool has_field(
const std::string& name )
const;
104 Field& field(
const std::string& name )
const;
106 iterator begin() {
return fields_.begin(); }
107 iterator end() {
return fields_.end(); }
108 const_iterator begin()
const {
return fields_.begin(); }
109 const_iterator end()
const {
return fields_.end(); }
110 const_iterator cbegin()
const {
return fields_.begin(); }
111 const_iterator cend()
const {
return fields_.end(); }
113 void haloExchange(
bool on_device =
false )
const;
114 void adjointHaloExchange(
bool on_device =
false )
const;
115 void set_dirty(
bool =
true )
const;
130 int atlas__FieldSet__has_field(
const FieldSetImpl* This,
char* name );
134 void atlas__FieldSet__set_dirty(
FieldSetImpl* This,
int value );
135 void atlas__FieldSet__halo_exchange(
FieldSetImpl* This,
int on_device );
146 class FieldSet : DOXYGEN_HIDE( public util::ObjectHandle<field::FieldSetImpl> ) {
148 using iterator = Implementation::iterator;
149 using const_iterator = Implementation::const_iterator;
151 template <
typename T>
152 using enable_if_index_t = Implementation::enable_if_index_t<T>;
155 using Handle::Handle;
157 FieldSet(
const std::string& name );
160 idx_t size()
const {
return get()->size(); }
161 bool empty()
const {
return get()->empty(); }
163 void clear() {
get()->clear(); }
165 const std::string& name()
const {
return get()->name(); }
166 std::string& name() {
return get()->name(); }
168 template <
typename Index, enable_if_index_t<Index> = 0>
169 const Field& operator[]( Index i )
const {
170 return get()->
operator[]( i );
173 template <
typename Index, enable_if_index_t<Index> = 0>
174 Field& operator[]( Index i ) {
175 return get()->
operator[]( i );
178 const Field& operator[](
const std::string& name )
const {
return get()->
operator[]( name ); }
179 Field& operator[](
const std::string& name ) {
return get()->
operator[]( name ); }
181 const Field& operator[](
const char* name )
const {
return get()->
operator[]( name ); }
182 Field& operator[](
const char* name ) {
return get()->
operator[]( name ); }
184 template <
typename Index, enable_if_index_t<Index> = 0>
185 const Field& field( Index i )
const {
186 return get()->field( i );
189 template <
typename Index, enable_if_index_t<Index> = 0>
190 Field& field( Index i ) {
191 return get()->field( i );
194 std::vector<std::string> field_names()
const {
return get()->field_names(); }
196 Field add(
const Field& field ) {
return get()->add( field ); }
198 bool has_field(
const std::string& name )
const {
return get()->has_field( name ); }
200 Field& field(
const std::string& name )
const {
return get()->field( name ); }
202 iterator begin() {
return get()->begin(); }
203 iterator end() {
return get()->end(); }
204 const_iterator begin()
const {
return get()->begin(); }
205 const_iterator end()
const {
return get()->end(); }
206 const_iterator cbegin()
const {
return get()->begin(); }
207 const_iterator cend()
const {
return get()->end(); }
209 void haloExchange(
bool on_device =
false )
const {
get()->haloExchange( on_device ); }
210 void set_dirty(
bool =
true )
const;
A Field contains an Array, Metadata, and a reference to a FunctionSpace.
Definition: Field.h:59
std::map< std::string, idx_t > index_
name-to-index map, to refer fields by name
Definition: FieldSet.h:120
FieldSetImpl(const std::string &name="untitled")
Constructs an empty FieldSet.
Definition: FieldSet.cc:23
Represents a set of fields, where order is preserved.
Definition: FieldSet.h:42
std::vector< Field > fields_
field storage
Definition: FieldSet.h:118
Represents a set of fields, where order is preserved.
Definition: FieldSet.h:146
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
Definition: FieldImpl.h:40
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42
std::string name_
internal name
Definition: FieldSet.h:119