atlas
Elements.h
Go to the documentation of this file.
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 
16 
17 #pragma once
18 
19 #include "atlas/array/ArrayView.h"
20 #include "atlas/array/IndexView.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 
37 class Elements : public util::Object {
38 public:
39  //-- Constructors
40 
42  Elements( HybridElements& elements, idx_t type_idx );
43 
46  Elements( ElementType*, idx_t nb_elements, const std::vector<idx_t>& node_connectivity );
47 
50  Elements( ElementType*, idx_t nb_elements, const idx_t node_connectivity[], bool fortran_array = false );
51 
53  virtual ~Elements();
54 
55  //-- Accessors
56 
58  idx_t size() const;
59 
61  const std::string& name() const;
62 
64  idx_t nb_nodes() const;
65 
67  idx_t nb_edges() const;
68 
70  const BlockConnectivity& node_connectivity() const;
71  BlockConnectivity& node_connectivity();
72 
74  const BlockConnectivity& edge_connectivity() const;
75  BlockConnectivity& edge_connectivity();
76 
78  const BlockConnectivity& cell_connectivity() const;
79  BlockConnectivity& cell_connectivity();
80 
82  const ElementType& element_type() const;
83 
86  // const HybridElements& hybrid_elements() const;
87 
89  // idx_t type_idx() const;
90 
92  idx_t begin() const;
93 
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>
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 
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 
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 
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 
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 
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 
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
A Field contains an Array, Metadata, and a reference to a FunctionSpace.
Definition: Field.h:59
Describe elements of a single type.
Definition: Elements.h:37
idx_t size() const
Number of elements.
Definition: Elements.h:151
Definition: GridToolsIndexView.h:136
This file contains the IndexView class, a class that allows to wrap any contiguous raw data into a vi...
This file contains the ArrayView class, a class that allows to wrap any contiguous raw data into a vi...
const ElementType & element_type() const
Element type of these Elements.
Definition: Elements.h:233
idx_t nb_edges() const
Number of edges for each element type.
Definition: Elements.h:159
idx_t end() const
End of elements in hybrid_elements.
Definition: Elements.h:241
const BlockConnectivity & edge_connectivity() const
Element to Edge connectivity table.
Definition: Elements.h:193
Definition: Object.h:18
const BlockConnectivity & cell_connectivity() const
Element to Cell connectivity table.
Definition: Elements.h:213
ElementType class (abstract) that provides access to geometric information of an element.
Definition: ElementType.h:29
idx_t nb_nodes() const
Number of nodes for each element type.
Definition: Elements.h:155
Multi-dimensional access existing POD array pointer.
Definition: ArraySlicer.h:23
Block Connectivity table.
Definition: Connectivity.h:515
HybridElements class that describes elements of different types.
Definition: HybridElements.h:64
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
Definition: FieldImpl.h:40
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42
idx_t begin() const
Access hybrid_elements HybridElements can contain more Elements, and holds the data.
Definition: Elements.h:237
const BlockConnectivity & node_connectivity() const
Element to Node connectivity table.
Definition: Elements.h:173