atlas
Field.h
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 
13 
14 #pragma once
15 
16 #include <iosfwd>
17 #include <string>
18 
19 #include "atlas/array/ArrayShape.h"
20 #include "atlas/array/DataType.h"
21 #include "atlas/array_fwd.h"
22 #include "atlas/library/config.h"
23 #include "atlas/util/ObjectHandle.h"
24 
25 namespace eckit {
26 class Parametrisation;
27 }
28 namespace atlas {
29 namespace field {
30 class FieldImpl;
31 }
32 } // namespace atlas
33 namespace atlas {
34 namespace util {
35 class Metadata;
36 }
37 } // namespace atlas
38 namespace atlas {
39 class FunctionSpace;
40 }
41 
42 namespace atlas {
43 
59 class Field : DOXYGEN_HIDE( public util::ObjectHandle<field::FieldImpl> ) {
60 public:
61  using Handle::Handle;
62  Field() = default;
63 
65  Field( const eckit::Parametrisation& );
66 
68  Field( const std::string& name, array::DataType, const array::ArrayShape& = array::ArrayShape() );
69 
71  Field( const std::string& name, array::DataType, array::ArraySpec&& );
72 
74  Field( const std::string& name, array::Array* );
75 
78  template <typename DATATYPE>
79  Field( const std::string& name, DATATYPE* data, const array::ArraySpec& );
80 
83  template <typename DATATYPE>
84  Field( const std::string& name, DATATYPE* data, const array::ArrayShape& );
85 
86  // -- Conversion
87 
89  operator const array::Array&() const;
90  operator array::Array&();
91 
93  const array::Array& array() const;
94  array::Array& array();
95 
96  bool valid() const { return get() != nullptr; }
97 
98  // -- Accessors
99 
101  void* storage();
102 
104  array::DataType datatype() const;
105 
107  const std::string& name() const;
108 
110  void rename( const std::string& name );
111 
113  const util::Metadata& metadata() const;
114  util::Metadata& metadata();
115 
117  void resize( const array::ArrayShape& shape );
118 
119  void insert( idx_t idx1, idx_t size1 );
120 
122  const std::vector<int>& shapef() const;
123 
125  const std::vector<int>& stridesf() const;
126 
128  const array::ArrayShape& shape() const;
129 
131  const array::ArrayStrides& strides() const;
132 
134  idx_t shape( idx_t i ) const;
135 
137  idx_t stride( idx_t i ) const;
138 
140  size_t size() const;
141 
143  idx_t rank() const;
144 
146  size_t bytes() const;
147 
148  bool contiguous() const;
149 
151  friend std::ostream& operator<<( std::ostream& os, const Field& v );
152 
154  void dump( std::ostream& os ) const;
155 
157  void set_levels( idx_t n );
158  idx_t levels() const;
159 
161  void set_variables( idx_t n );
162  idx_t variables() const;
163 
164  void set_functionspace( const FunctionSpace& functionspace );
165  const FunctionSpace& functionspace() const;
166 
168  size_t footprint() const;
169 
170  bool dirty() const;
171 
172  void set_dirty( bool = true ) const;
173 
174  void haloExchange( bool on_device = false ) const;
175  void adjointHaloExchange( bool on_device = false ) const;
176 
177  // -- Methods related to host-device synchronisation
178  void updateHost() const;
179  void updateDevice() const;
180  void syncHostDevice() const;
181  bool hostNeedsUpdate() const;
182  bool deviceNeedsUpdate() const;
183  void reactivateDeviceWriteViews() const;
184  void reactivateHostWriteViews() const;
185 };
186 
187 extern template Field::Field( const std::string&, float*, const array::ArraySpec& );
188 extern template Field::Field( const std::string&, float*, const array::ArrayShape& );
189 extern template Field::Field( const std::string&, double*, const array::ArraySpec& );
190 extern template Field::Field( const std::string&, double*, const array::ArrayShape& );
191 extern template Field::Field( const std::string&, long*, const array::ArraySpec& );
192 extern template Field::Field( const std::string&, long*, const array::ArrayShape& );
193 extern template Field::Field( const std::string&, int*, const array::ArraySpec& );
194 extern template Field::Field( const std::string&, int*, const array::ArrayShape& );
195 
196 //------------------------------------------------------------------------------------------------------
197 
198 } // namespace atlas
Definition: ArrayShape.h:33
A Field contains an Array, Metadata, and a reference to a FunctionSpace.
Definition: Field.h:59
Definition: ArraySpec.h:27
Definition: ArrayStrides.h:23
Definition: Domain.h:19
Definition: DataType.h:40
Definition: Metadata.h:23
Forward declarations of public API header atlas/array.h.
Definition: Array.h:37
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42
Definition: FunctionSpace.h:39