| 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 |
/// @file Nodes.h |
| 12 |
/// @author Willem Deconinck |
| 13 |
/// @date August 2015 |
| 14 |
|
| 15 |
#pragma once |
| 16 |
|
| 17 |
#include <map> |
| 18 |
#include <string> |
| 19 |
|
| 20 |
#include "atlas/util/Object.h" |
| 21 |
#include "atlas/util/ObjectHandle.h" |
| 22 |
|
| 23 |
#include "atlas/field/Field.h" |
| 24 |
#include "atlas/util/Metadata.h" |
| 25 |
#include "atlas/util/Topology.h" |
| 26 |
|
| 27 |
namespace atlas { |
| 28 |
namespace mesh { |
| 29 |
template <class T> |
| 30 |
class ConnectivityInterface; |
| 31 |
class IrregularConnectivityImpl; |
| 32 |
using IrregularConnectivity = ConnectivityInterface<IrregularConnectivityImpl>; |
| 33 |
} // namespace mesh |
| 34 |
} // namespace atlas |
| 35 |
|
| 36 |
namespace atlas { |
| 37 |
namespace mesh { |
| 38 |
|
| 39 |
/** |
| 40 |
* \brief Nodes class that owns a collection of fields defined in nodes of the |
| 41 |
* mesh |
| 42 |
*/ |
| 43 |
class Nodes : public util::Object { |
| 44 |
public: |
| 45 |
using Connectivity = IrregularConnectivity; |
| 46 |
|
| 47 |
using Topology = util::Topology; |
| 48 |
|
| 49 |
public: // methods |
| 50 |
//-- Constructors |
| 51 |
/// @brief Construct "size" nodes |
| 52 |
Nodes(); |
| 53 |
// Nodes(idx_t size); |
| 54 |
|
| 55 |
//-- Accessors |
| 56 |
|
| 57 |
const Field& field(const std::string& name) const; |
| 58 |
Field& field(const std::string& name); |
| 59 |
bool has_field(const std::string& name) const { return (fields_.find(name) != fields_.end()); } |
| 60 |
|
| 61 |
const Field& field(idx_t) const; |
| 62 |
Field& field(idx_t); |
| 63 |
idx_t nb_fields() const { return static_cast<idx_t>(fields_.size()); } |
| 64 |
|
| 65 |
const util::Metadata& metadata() const { return metadata_; } |
| 66 |
util::Metadata& metadata() { return metadata_; } |
| 67 |
|
| 68 |
const Field& global_index() const { return global_index_; } |
| 69 |
Field& global_index() { return global_index_; } |
| 70 |
|
| 71 |
const Field& remote_index() const { return remote_index_; } |
| 72 |
Field& remote_index() { return remote_index_; } |
| 73 |
|
| 74 |
const Field& partition() const { return partition_; } |
| 75 |
Field& partition() { return partition_; } |
| 76 |
|
| 77 |
const Field& xy() const { return xy_; } |
| 78 |
Field& xy() { return xy_; } |
| 79 |
|
| 80 |
const Field& lonlat() const { return lonlat_; } |
| 81 |
Field& lonlat() { return lonlat_; } |
| 82 |
|
| 83 |
const Field& ghost() const { return ghost_; } |
| 84 |
Field& ghost() { return ghost_; } |
| 85 |
|
| 86 |
const Field& flags() const { return flags_; } |
| 87 |
Field& flags() { return flags_; } |
| 88 |
|
| 89 |
const Field& halo() const { return halo_; } |
| 90 |
Field& halo() { return halo_; } |
| 91 |
|
| 92 |
/// @brief Node to Edge connectivity table |
| 93 |
const Connectivity& edge_connectivity() const; |
| 94 |
Connectivity& edge_connectivity(); |
| 95 |
|
| 96 |
/// @brief Node to Cell connectivity table |
| 97 |
const Connectivity& cell_connectivity() const; |
| 98 |
Connectivity& cell_connectivity(); |
| 99 |
|
| 100 |
const Connectivity& connectivity(const std::string& name) const; |
| 101 |
Connectivity& connectivity(const std::string& name); |
| 102 |
|
| 103 |
bool has_connectivity(std::string name) const { return connectivities_.count(name); } |
| 104 |
|
| 105 |
idx_t size() const { return size_; } |
| 106 |
|
| 107 |
// -- Modifiers |
| 108 |
|
| 109 |
Field add(const Field&); |
| 110 |
|
| 111 |
void resize(idx_t); |
| 112 |
|
| 113 |
void remove_field(const std::string& name); |
| 114 |
|
| 115 |
Connectivity& add(Connectivity*); |
| 116 |
|
| 117 |
/// @brief Return the memory footprint of the Nodes |
| 118 |
size_t footprint() const; |
| 119 |
|
| 120 |
void updateDevice() const; |
| 121 |
|
| 122 |
void updateHost() const; |
| 123 |
|
| 124 |
void syncHostDevice() const; |
| 125 |
|
| 126 |
private: |
| 127 |
void print(std::ostream&) const; |
| 128 |
|
| 129 |
friend std::ostream& operator<<(std::ostream& s, const Nodes& p) { |
| 130 |
p.print(s); |
| 131 |
return s; |
| 132 |
} |
| 133 |
|
| 134 |
private: |
| 135 |
typedef std::map<std::string, Field> FieldMap; |
| 136 |
typedef std::map<std::string, util::ObjectHandle<Connectivity>> ConnectivityMap; |
| 137 |
|
| 138 |
private: |
| 139 |
idx_t size_; |
| 140 |
FieldMap fields_; |
| 141 |
ConnectivityMap connectivities_; |
| 142 |
|
| 143 |
util::Metadata metadata_; |
| 144 |
|
| 145 |
// Cached shortcuts to specific fields in fields_ |
| 146 |
Field global_index_; |
| 147 |
Field remote_index_; |
| 148 |
Field partition_; |
| 149 |
Field xy_; |
| 150 |
Field lonlat_; |
| 151 |
Field ghost_; |
| 152 |
Field flags_; |
| 153 |
Field halo_; |
| 154 |
|
| 155 |
// Cached shortcuts to specific connectivities in connectivities_ |
| 156 |
Connectivity* edge_connectivity_; |
| 157 |
Connectivity* cell_connectivity_; |
| 158 |
}; |
| 159 |
|
| 160 |
inline const Nodes::Connectivity& Nodes::edge_connectivity() const { |
| 161 |
return *edge_connectivity_; |
| 162 |
} |
| 163 |
|
| 164 |
inline Nodes::Connectivity& Nodes::edge_connectivity() { |
| 165 |
return *edge_connectivity_; |
| 166 |
} |
| 167 |
|
| 168 |
inline const Nodes::Connectivity& Nodes::cell_connectivity() const { |
| 169 |
return *cell_connectivity_; |
| 170 |
} |
| 171 |
|
| 172 |
inline Nodes::Connectivity& Nodes::cell_connectivity() { |
| 173 |
return *cell_connectivity_; |
| 174 |
} |
| 175 |
|
| 176 |
extern "C" { |
| 177 |
Nodes* atlas__mesh__Nodes__create(); |
| 178 |
void atlas__mesh__Nodes__delete(Nodes* This); |
| 179 |
idx_t atlas__mesh__Nodes__size(Nodes* This); |
| 180 |
void atlas__mesh__Nodes__resize(Nodes* This, idx_t size); |
| 181 |
idx_t atlas__mesh__Nodes__nb_fields(Nodes* This); |
| 182 |
void atlas__mesh__Nodes__add_field(Nodes* This, field::FieldImpl* field); |
| 183 |
void atlas__mesh__Nodes__remove_field(Nodes* This, char* name); |
| 184 |
int atlas__mesh__Nodes__has_field(Nodes* This, char* name); |
| 185 |
field::FieldImpl* atlas__mesh__Nodes__field_by_name(Nodes* This, char* name); |
| 186 |
field::FieldImpl* atlas__mesh__Nodes__field_by_idx(Nodes* This, idx_t idx); |
| 187 |
util::Metadata* atlas__mesh__Nodes__metadata(Nodes* This); |
| 188 |
void atlas__mesh__Nodes__str(Nodes* This, char*& str, int& size); |
| 189 |
IrregularConnectivity* atlas__mesh__Nodes__edge_connectivity(Nodes* This); |
| 190 |
IrregularConnectivity* atlas__mesh__Nodes__cell_connectivity(Nodes* This); |
| 191 |
IrregularConnectivity* atlas__mesh__Nodes__connectivity(Nodes* This, char* name); |
| 192 |
void atlas__mesh__Nodes__add_connectivity(Nodes* This, IrregularConnectivity* connectivity); |
| 193 |
field::FieldImpl* atlas__mesh__Nodes__xy(Nodes* This); |
| 194 |
field::FieldImpl* atlas__mesh__Nodes__lonlat(Nodes* This); |
| 195 |
field::FieldImpl* atlas__mesh__Nodes__global_index(Nodes* This); |
| 196 |
field::FieldImpl* atlas__mesh__Nodes__remote_index(Nodes* This); |
| 197 |
field::FieldImpl* atlas__mesh__Nodes__partition(Nodes* This); |
| 198 |
field::FieldImpl* atlas__mesh__Nodes__ghost(Nodes* This); |
| 199 |
} |
| 200 |
|
| 201 |
//------------------------------------------------------------------------------------------------------ |
| 202 |
|
| 203 |
} // namespace mesh |
| 204 |
} // namespace atlas |