atlas
FunctionSpaceImpl.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 
11 #pragma once
12 
13 #include <string>
14 #include <type_traits>
15 #include <vector>
16 
17 #include "atlas/util/Object.h"
18 
19 #include "atlas/library/config.h"
20 
21 namespace eckit {
22 class Configuration;
23 }
24 
25 namespace atlas {
26 class FieldSet;
27 class Field;
28 class Projection;
29 namespace util {
30 class Metadata;
31 class PartitionPolygon;
32 class PartitionPolygons;
33 } // namespace util
34 } // namespace atlas
35 
36 namespace atlas {
37 namespace functionspace {
38 
39 #define FunctionspaceT_nonconst typename std::remove_const<FunctionSpaceT>::type
40 #define FunctionspaceT_const typename std::add_const<FunctionSpaceT>::type
41 
45 public:
47  virtual ~FunctionSpaceImpl();
48  virtual std::string type() const = 0;
49  virtual operator bool() const { return true; }
50  virtual size_t footprint() const = 0;
51 
52  virtual atlas::Field createField( const eckit::Configuration& ) const = 0;
53 
54  virtual atlas::Field createField( const atlas::Field&, const eckit::Configuration& ) const = 0;
55 
56  atlas::Field createField( const atlas::Field& ) const;
57 
58  template <typename DATATYPE>
59  atlas::Field createField( const eckit::Configuration& ) const;
60 
61  template <typename DATATYPE>
62  atlas::Field createField() const;
63 
64  const util::Metadata& metadata() const { return *metadata_; }
65  util::Metadata& metadata() { return *metadata_; }
66 
67  template <typename FunctionSpaceT>
68  FunctionspaceT_nonconst* cast();
69 
70  template <typename FunctionSpaceT>
71  FunctionspaceT_const* cast() const;
72 
73  virtual std::string distribution() const = 0;
74 
75  virtual void haloExchange( const FieldSet&, bool /*on_device*/ = false ) const;
76  virtual void haloExchange( const Field&, bool /* on_device*/ = false ) const;
77 
78  virtual void adjointHaloExchange( const FieldSet&, bool /*on_device*/ = false ) const;
79  virtual void adjointHaloExchange( const Field&, bool /* on_device*/ = false ) const;
80 
81  virtual idx_t size() const = 0;
82 
83  virtual idx_t nb_partitions() const;
84 
85  virtual const util::PartitionPolygon& polygon( idx_t halo = 0 ) const;
86 
87  virtual atlas::Field lonlat() const;
88 
89  virtual atlas::Field ghost() const;
90 
91  virtual const util::PartitionPolygons& polygons() const;
92 
93  virtual const Projection& projection() const;
94 
95 private:
96  util::Metadata* metadata_;
97 };
98 
99 template <typename FunctionSpaceT>
100 inline FunctionspaceT_nonconst* FunctionSpaceImpl::cast() {
101  return dynamic_cast<FunctionspaceT_nonconst*>( this );
102 }
103 
104 template <typename FunctionSpaceT>
105 inline FunctionspaceT_const* FunctionSpaceImpl::cast() const {
106  return dynamic_cast<FunctionspaceT_const*>( this );
107 }
108 
109 #undef FunctionspaceT_const
110 #undef FunctionspaceT_nonconst
111 
112 //------------------------------------------------------------------------------------------------------
113 
116 public:
118  virtual ~NoFunctionSpace() {}
119  virtual std::string type() const { return "NoFunctionSpace"; }
120  virtual operator bool() const { return false; }
121  virtual size_t footprint() const { return sizeof( *this ); }
122  virtual std::string distribution() const { return std::string(); }
123 
124  virtual Field createField( const eckit::Configuration& ) const;
125  virtual Field createField( const Field&, const eckit::Configuration& ) const;
126  virtual idx_t size() const { return 0; }
127 };
128 
129 //------------------------------------------------------------------------------------------------------
130 
131 } // namespace functionspace
132 
133 //------------------------------------------------------------------------------------------------------
134 
135 } // namespace atlas
A Field contains an Array, Metadata, and a reference to a FunctionSpace.
Definition: Field.h:59
Dummy Functionspace class that evaluates to false.
Definition: FunctionSpaceImpl.h:115
Definition: Polygon.h:155
Definition: Projection.h:49
Definition: Polygon.h:98
Definition: Object.h:18
Definition: Domain.h:19
Represents a set of fields, where order is preserved.
Definition: FieldSet.h:146
Definition: Metadata.h:23
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
FunctionSpace class helps to interprete Fields.
Definition: FunctionSpaceImpl.h:44