| 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 |
#include <memory> |
| 17 |
|
| 18 |
#include "atlas/functionspace/HaloDescription.h" |
| 19 |
#include "atlas/library/config.h" |
| 20 |
#include "atlas/util/Object.h" |
| 21 |
|
| 22 |
namespace eckit { |
| 23 |
class Configuration; |
| 24 |
} |
| 25 |
|
| 26 |
namespace atlas { |
| 27 |
class FieldSet; |
| 28 |
class Field; |
| 29 |
class Grid; |
| 30 |
class Projection; |
| 31 |
namespace util { |
| 32 |
class Metadata; |
| 33 |
class PartitionPolygon; |
| 34 |
class PartitionPolygons; |
| 35 |
} // namespace util |
| 36 |
namespace parallel { |
| 37 |
class GatherScatter; |
| 38 |
} // namespace parallel |
| 39 |
|
| 40 |
} // namespace atlas |
| 41 |
|
| 42 |
namespace atlas { |
| 43 |
namespace functionspace { |
| 44 |
|
| 45 |
#define FunctionspaceT_nonconst typename std::remove_const<FunctionSpaceT>::type |
| 46 |
#define FunctionspaceT_const typename std::add_const<FunctionSpaceT>::type |
| 47 |
|
| 48 |
/// @brief FunctionSpace class helps to interprete Fields. |
| 49 |
/// @note Abstract base class |
| 50 |
class FunctionSpaceImpl : public util::Object { |
| 51 |
public: |
| 52 |
FunctionSpaceImpl(); |
| 53 |
virtual ~FunctionSpaceImpl(); |
| 54 |
virtual std::string type() const = 0; |
| 55 |
virtual operator bool() const { return true; } |
| 56 |
virtual size_t footprint() const = 0; |
| 57 |
|
| 58 |
virtual atlas::Field createField(const eckit::Configuration&) const = 0; |
| 59 |
|
| 60 |
virtual atlas::Field createField(const atlas::Field&, const eckit::Configuration&) const = 0; |
| 61 |
|
| 62 |
atlas::Field createField(const atlas::Field&) const; |
| 63 |
|
| 64 |
template <typename DATATYPE> |
| 65 |
atlas::Field createField(const eckit::Configuration&) const; |
| 66 |
|
| 67 |
template <typename DATATYPE> |
| 68 |
atlas::Field createField() const; |
| 69 |
|
| 70 |
const util::Metadata& metadata() const { return *metadata_; } |
| 71 |
util::Metadata& metadata() { return *metadata_; } |
| 72 |
|
| 73 |
template <typename FunctionSpaceT> |
| 74 |
FunctionspaceT_nonconst* cast(); |
| 75 |
|
| 76 |
template <typename FunctionSpaceT> |
| 77 |
FunctionspaceT_const* cast() const; |
| 78 |
|
| 79 |
virtual std::string distribution() const = 0; |
| 80 |
|
| 81 |
virtual void haloExchange(const FieldSet&, bool /*on_device*/ = false) const; |
| 82 |
virtual void haloExchange(const Field&, bool /* on_device*/ = false) const; |
| 83 |
|
| 84 |
virtual void adjointHaloExchange(const FieldSet&, bool /*on_device*/ = false) const; |
| 85 |
virtual void adjointHaloExchange(const Field&, bool /* on_device*/ = false) const; |
| 86 |
|
| 87 |
virtual void gather(const FieldSet&, FieldSet&) const; |
| 88 |
virtual void gather(const Field&, Field&) const; |
| 89 |
|
| 90 |
virtual void scatter(const FieldSet&, FieldSet&) const; |
| 91 |
virtual void scatter(const Field&, Field&) const; |
| 92 |
|
| 93 |
virtual const parallel::GatherScatter& gather() const; |
| 94 |
virtual const parallel::GatherScatter& scatter() const; |
| 95 |
|
| 96 |
virtual idx_t size() const = 0; |
| 97 |
|
| 98 |
virtual idx_t part() const; |
| 99 |
|
| 100 |
virtual idx_t nb_parts() const; |
| 101 |
|
| 102 |
virtual const util::PartitionPolygon& polygon(idx_t halo = 0) const; |
| 103 |
|
| 104 |
virtual const atlas::Grid& grid() const; |
| 105 |
|
| 106 |
virtual atlas::Field lonlat() const; |
| 107 |
|
| 108 |
virtual atlas::Field ghost() const; |
| 109 |
|
| 110 |
virtual atlas::Field remote_index() const; |
| 111 |
|
| 112 |
virtual atlas::Field partition() const; |
| 113 |
|
| 114 |
virtual atlas::Field global_index() const; |
| 115 |
|
| 116 |
virtual const util::PartitionPolygons& polygons() const; |
| 117 |
|
| 118 |
virtual const Projection& projection() const; |
| 119 |
|
| 120 |
virtual std::string mpi_comm() const; |
| 121 |
|
| 122 |
virtual const HaloDescription& halo_description() const; |
| 123 |
|
| 124 |
private: |
| 125 |
util::Metadata* metadata_; |
| 126 |
mutable std::unique_ptr<HaloDescription> halo_description_; |
| 127 |
}; |
| 128 |
|
| 129 |
template <typename FunctionSpaceT> |
| 130 |
inline FunctionspaceT_nonconst* FunctionSpaceImpl::cast() { |
| 131 |
return dynamic_cast<FunctionspaceT_nonconst*>(this); |
| 132 |
} |
| 133 |
|
| 134 |
template <typename FunctionSpaceT> |
| 135 |
inline FunctionspaceT_const* FunctionSpaceImpl::cast() const { |
| 136 |
return dynamic_cast<FunctionspaceT_const*>(this); |
| 137 |
} |
| 138 |
|
| 139 |
#undef FunctionspaceT_const |
| 140 |
#undef FunctionspaceT_nonconst |
| 141 |
|
| 142 |
//------------------------------------------------------------------------------------------------------ |
| 143 |
|
| 144 |
/// @brief Dummy Functionspace class that evaluates to false |
| 145 |
class NoFunctionSpace : public FunctionSpaceImpl { |
| 146 |
public: |
| 147 |
NoFunctionSpace(): FunctionSpaceImpl() {} |
| 148 |
virtual ~NoFunctionSpace() {} |
| 149 |
virtual std::string type() const { return "NoFunctionSpace"; } |
| 150 |
virtual operator bool() const { return false; } |
| 151 |
virtual size_t footprint() const { return sizeof(*this); } |
| 152 |
virtual std::string distribution() const { return std::string(); } |
| 153 |
|
| 154 |
virtual Field createField(const eckit::Configuration&) const; |
| 155 |
virtual Field createField(const Field&, const eckit::Configuration&) const; |
| 156 |
virtual idx_t size() const { return 0; } |
| 157 |
}; |
| 158 |
|
| 159 |
//------------------------------------------------------------------------------------------------------ |
| 160 |
|
| 161 |
} // namespace functionspace |
| 162 |
|
| 163 |
//------------------------------------------------------------------------------------------------------ |
| 164 |
|
| 165 |
} // namespace atlas |