| 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 Elements.h |
| 12 |
/// @author Willem Deconinck |
| 13 |
/// @date October 2015 |
| 14 |
/// |
| 15 |
/// This file describes the Elements class for a Mesh. |
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include "atlas/array/ArrayView.h" |
| 20 |
#include "atlas/array/IndexView.h" |
| 21 |
#include "atlas/mesh/Connectivity.h" |
| 22 |
#include "atlas/mesh/HybridElements.h" |
| 23 |
#include "atlas/util/Object.h" |
| 24 |
|
| 25 |
namespace atlas { |
| 26 |
namespace mesh { |
| 27 |
class ElementType; |
| 28 |
} |
| 29 |
} // namespace atlas |
| 30 |
|
| 31 |
namespace atlas { |
| 32 |
namespace mesh { |
| 33 |
|
| 34 |
// ------------------------------------------------------------------------------------------------------ |
| 35 |
|
| 36 |
/// @brief Describe elements of a single type |
| 37 |
class Elements : public util::Object { |
| 38 |
public: |
| 39 |
//-- Constructors |
| 40 |
|
| 41 |
/// @brief Constructor that treats elements as sub-elements in HybridElements |
| 42 |
Elements(HybridElements& elements, idx_t type_idx); |
| 43 |
|
| 44 |
/// @brief Constructor that internally creates a HybridElements that owns the |
| 45 |
/// data |
| 46 |
Elements(ElementType*, idx_t nb_elements, const std::vector<idx_t>& node_connectivity); |
| 47 |
|
| 48 |
/// @brief Constructor that internally creates a HybridElements that owns the |
| 49 |
/// data |
| 50 |
Elements(ElementType*, idx_t nb_elements, const idx_t node_connectivity[], bool fortran_array = false); |
| 51 |
|
| 52 |
/// @brief Destructor |
| 53 |
virtual ~Elements(); |
| 54 |
|
| 55 |
//-- Accessors |
| 56 |
|
| 57 |
/// @brief Number of elements |
| 58 |
idx_t size() const; |
| 59 |
|
| 60 |
/// @brief Name of this element type |
| 61 |
const std::string& name() const; |
| 62 |
|
| 63 |
/// @brief Number of nodes for each element type |
| 64 |
idx_t nb_nodes() const; |
| 65 |
|
| 66 |
/// @brief Number of edges for each element type |
| 67 |
idx_t nb_edges() const; |
| 68 |
|
| 69 |
/// @brief Element to Node connectivity table |
| 70 |
const BlockConnectivity& node_connectivity() const; |
| 71 |
BlockConnectivity& node_connectivity(); |
| 72 |
|
| 73 |
/// @brief Element to Edge connectivity table |
| 74 |
const BlockConnectivity& edge_connectivity() const; |
| 75 |
BlockConnectivity& edge_connectivity(); |
| 76 |
|
| 77 |
/// @brief Element to Cell connectivity table |
| 78 |
const BlockConnectivity& cell_connectivity() const; |
| 79 |
BlockConnectivity& cell_connectivity(); |
| 80 |
|
| 81 |
/// @brief Element type of these Elements |
| 82 |
const ElementType& element_type() const; |
| 83 |
|
| 84 |
/// @brief Access hybrid_elements |
| 85 |
/// HybridElements can contain more Elements, and holds the data. |
| 86 |
// const HybridElements& hybrid_elements() const; |
| 87 |
|
| 88 |
/// @brief Index of Elements in hybrid_elements |
| 89 |
// idx_t type_idx() const; |
| 90 |
|
| 91 |
/// @brief Begin of elements in hybrid_elements |
| 92 |
idx_t begin() const; |
| 93 |
|
| 94 |
/// @brief End of elements in hybrid_elements |
| 95 |
idx_t end() const; |
| 96 |
|
| 97 |
const Field& field(const std::string& name) const { return hybrid_elements_->field(name); } |
| 98 |
Field& field(const std::string& name) { return hybrid_elements_->field(name); } |
| 99 |
bool has_field(const std::string& name) const { return hybrid_elements_->has_field(name); } |
| 100 |
|
| 101 |
const Field& field(idx_t idx) const { return hybrid_elements_->field(idx); } |
| 102 |
Field& field(idx_t idx) { return hybrid_elements_->field(idx); } |
| 103 |
idx_t nb_fields() const { return hybrid_elements_->nb_fields(); } |
| 104 |
|
| 105 |
const Field& global_index() const { return hybrid_elements_->global_index(); } |
| 106 |
Field& global_index() { return hybrid_elements_->global_index(); } |
| 107 |
|
| 108 |
const Field& remote_index() const { return hybrid_elements_->remote_index(); } |
| 109 |
Field& remote_index() { return hybrid_elements_->remote_index(); } |
| 110 |
|
| 111 |
const Field& partition() const { return hybrid_elements_->partition(); } |
| 112 |
Field& partition() { return hybrid_elements_->partition(); } |
| 113 |
|
| 114 |
const Field& halo() const { return hybrid_elements_->halo(); } |
| 115 |
Field& halo() { return hybrid_elements_->halo(); } |
| 116 |
|
| 117 |
const Field& flags() const { return hybrid_elements_->flags(); } |
| 118 |
Field& flags() { return hybrid_elements_->flags(); } |
| 119 |
|
| 120 |
template <typename DATATYPE, int RANK> |
| 121 |
array::LocalView<const DATATYPE, RANK> view(const Field&) const; |
| 122 |
|
| 123 |
template <typename DATATYPE, int RANK> |
| 124 |
array::LocalView<DATATYPE, RANK> view(Field&) const; |
| 125 |
|
| 126 |
template <typename DATATYPE, int RANK> |
| 127 |
array::LocalIndexView<DATATYPE, RANK> indexview(const Field&) const; |
| 128 |
|
| 129 |
template <typename DATATYPE, int RANK> |
| 130 |
array::LocalIndexView<DATATYPE, RANK> indexview(Field&) const; |
| 131 |
|
| 132 |
idx_t add(const idx_t nb_elements); |
| 133 |
|
| 134 |
private: |
| 135 |
friend class HybridElements; |
| 136 |
void rebuild(); |
| 137 |
|
| 138 |
private: |
| 139 |
bool owns_; |
| 140 |
HybridElements* hybrid_elements_; |
| 141 |
idx_t size_; |
| 142 |
idx_t begin_; |
| 143 |
idx_t end_; |
| 144 |
idx_t type_idx_; |
| 145 |
idx_t nb_nodes_; |
| 146 |
idx_t nb_edges_; |
| 147 |
}; |
| 148 |
|
| 149 |
// ------------------------------------------------------------------------------------------------------ |
| 150 |
|
| 151 |
inline idx_t Elements::size() const { |
| 152 |
return size_; |
| 153 |
} |
| 154 |
|
| 155 |
inline idx_t Elements::nb_nodes() const { |
| 156 |
return nb_nodes_; |
| 157 |
} |
| 158 |
|
| 159 |
inline idx_t Elements::nb_edges() const { |
| 160 |
return nb_edges_; |
| 161 |
} |
| 162 |
|
| 163 |
// inline idx_t Elements::type_idx() const |
| 164 |
//{ |
| 165 |
// return type_idx_; |
| 166 |
//} |
| 167 |
|
| 168 |
// inline const HybridElements& Elements::hybrid_elements() const |
| 169 |
//{ |
| 170 |
// return *hybrid_elements_; |
| 171 |
//} |
| 172 |
|
| 173 |
inline const BlockConnectivity& Elements::node_connectivity() const { |
| 174 |
if (hybrid_elements_->node_connectivity().blocks()) { |
| 175 |
return hybrid_elements_->node_connectivity().block(type_idx_); |
| 176 |
} |
| 177 |
else { |
| 178 |
static BlockConnectivity dummy; |
| 179 |
return dummy; |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
inline BlockConnectivity& Elements::node_connectivity() { |
| 184 |
if (hybrid_elements_->node_connectivity().blocks()) { |
| 185 |
return hybrid_elements_->node_connectivity().block(type_idx_); |
| 186 |
} |
| 187 |
else { |
| 188 |
static BlockConnectivity dummy; |
| 189 |
return dummy; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
inline const BlockConnectivity& Elements::edge_connectivity() const { |
| 194 |
if (hybrid_elements_->edge_connectivity().blocks()) { |
| 195 |
return hybrid_elements_->edge_connectivity().block(type_idx_); |
| 196 |
} |
| 197 |
else { |
| 198 |
static BlockConnectivity dummy; |
| 199 |
return dummy; |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
inline BlockConnectivity& Elements::edge_connectivity() { |
| 204 |
if (hybrid_elements_->edge_connectivity().blocks()) { |
| 205 |
return hybrid_elements_->edge_connectivity().block(type_idx_); |
| 206 |
} |
| 207 |
else { |
| 208 |
static BlockConnectivity dummy; |
| 209 |
return dummy; |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
inline const BlockConnectivity& Elements::cell_connectivity() const { |
| 214 |
if (hybrid_elements_->cell_connectivity().blocks()) { |
| 215 |
return hybrid_elements_->cell_connectivity().block(type_idx_); |
| 216 |
} |
| 217 |
else { |
| 218 |
static BlockConnectivity dummy; |
| 219 |
return dummy; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
inline BlockConnectivity& Elements::cell_connectivity() { |
| 224 |
if (hybrid_elements_->cell_connectivity().blocks()) { |
| 225 |
return hybrid_elements_->cell_connectivity().block(type_idx_); |
| 226 |
} |
| 227 |
else { |
| 228 |
static BlockConnectivity dummy; |
| 229 |
return dummy; |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
inline const ElementType& Elements::element_type() const { |
| 234 |
return hybrid_elements_->element_type(type_idx_); |
| 235 |
} |
| 236 |
|
| 237 |
inline idx_t Elements::begin() const { |
| 238 |
return begin_; |
| 239 |
} |
| 240 |
|
| 241 |
inline idx_t Elements::end() const { |
| 242 |
return end_; |
| 243 |
} |
| 244 |
|
| 245 |
// ------------------------------------------------------------------------------------------------------ |
| 246 |
|
| 247 |
extern "C" { |
| 248 |
void atlas__mesh__Elements__delete(Elements* This); |
| 249 |
idx_t atlas__mesh__Elements__size(const Elements* This); |
| 250 |
idx_t atlas__mesh__Elements__begin(const Elements* This); |
| 251 |
idx_t atlas__mesh__Elements__end(const Elements* This); |
| 252 |
BlockConnectivity* atlas__mesh__Elements__node_connectivity(Elements* This); |
| 253 |
BlockConnectivity* atlas__mesh__Elements__edge_connectivity(Elements* This); |
| 254 |
BlockConnectivity* atlas__mesh__Elements__cell_connectivity(Elements* This); |
| 255 |
int atlas__mesh__Elements__has_field(const Elements* This, char* name); |
| 256 |
int atlas__mesh__Elements__nb_fields(const Elements* This); |
| 257 |
field::FieldImpl* atlas__mesh__Elements__field_by_idx(Elements* This, idx_t idx); |
| 258 |
field::FieldImpl* atlas__mesh__Elements__field_by_name(Elements* This, char* name); |
| 259 |
field::FieldImpl* atlas__mesh__Elements__global_index(Elements* This); |
| 260 |
field::FieldImpl* atlas__mesh__Elements__remote_index(Elements* This); |
| 261 |
field::FieldImpl* atlas__mesh__Elements__partition(Elements* This); |
| 262 |
field::FieldImpl* atlas__mesh__Elements__halo(Elements* This); |
| 263 |
const ElementType* atlas__mesh__Elements__element_type(const Elements* This); |
| 264 |
void atlas__mesh__Elements__add(Elements* This, idx_t nb_elements); |
| 265 |
} |
| 266 |
|
| 267 |
//------------------------------------------------------------------------------------------------------ |
| 268 |
|
| 269 |
} // namespace mesh |
| 270 |
} // namespace atlas |