Flow123d  jenkins-Flow123d-windows-release-multijob-285
accessors.hh
Go to the documentation of this file.
1 /*
2  * Accessors.hh
3  *
4  * Created on: Dec 4, 2012
5  * Author: jb
6  */
7 
8 #ifndef ACCESSORS_HH_
9 #define ACCESSORS_HH_
10 
11 #include "mesh/bounding_box.hh"
12 #include "mesh/mesh_types.hh"
13 #include "mesh/region.hh"
14 #include "mesh/elements.h"
15 #include "mesh/mesh.h"
16 #include <armadillo>
17 
18 /**
19  * Element accessor templated just by dimension of the embedding space, used by Fields.
20  * This should allow algorithms over elements where dimension of particular element is runtime parameter.
21  *
22  * This class suites as interface of Fields to the mesh elements, in particular this accessor knows directly
23  * the region, and also can be used as an accessor that works on the whole region if used by Fields that do not depend on
24  * particular elements as FieldConstant, FiledFormula, and FieldPython.
25  *
26  * TODO:
27  * - make this kind of accessor subclass of FieldCommonBase or at least move it into src/fields
28  * since it has functionality particular for Fields
29  *
30  * Ideas:
31  * need function to calculate intersection (object) of two ElementAccessors, but this definitely should be templated by
32  * dimension of the ref. element (or rather shape of ref. element), here we can have case dispatch
33  *
34  */
35 template <int spacedim>
37 public:
38  /**
39  * Default invalid accessor.
40  */
42  : mesh_(NULL)
43  {}
44 
45  /**
46  * Regional accessor.
47  */
48  ElementAccessor(const Mesh *mesh, RegionIdx r_idx)
49  : dim_(undefined_dim_), mesh_(mesh), r_idx_(r_idx)
50  {}
51 
52  /**
53  * Element accessor.
54  */
55  ElementAccessor(const Mesh *mesh, unsigned int idx, bool boundary)
56  : mesh_(mesh), boundary_(boundary), element_idx_(idx), r_idx_(element()->region_idx())
57  {
58  dim_=element()->dim();
59  }
60 
61  inline bool is_regional() const {
62  return dim_ == undefined_dim_;
63  }
64 
65  inline bool is_elemental() const {
66  return ( is_valid() && ! is_regional() );
67  }
68 
69  inline bool is_valid() const {
70  return mesh_ != NULL;
71  }
72 
73  inline unsigned int dim() const
74  { return dim_; }
75 
76  inline const Element * element() const {
77  if (boundary_) return (Element *)(mesh_->bc_elements(element_idx_)) ;
78  else return (Element *)(mesh_->element(element_idx_)) ;
79  }
80 
81  inline arma::vec::fixed<spacedim> centre() const {
82  ASSERT(is_valid(), "Invalid element accessor.");
83  if (is_regional() ) return arma::vec::fixed<spacedim>();
84  else return element()->centre();
85  }
86 
87 
88  inline Region region() const
89  { return Region( r_idx_, mesh_->region_db()); }
90 
91  inline RegionIdx region_idx() const
92  { return r_idx_; }
93 
94  /// We need this method after replacing Region by RegionIdx, and movinf RegionDB instance into particular mesh
95  //inline unsigned int region_id() const {
96  // return region().id();
97  //}
98 
99  inline bool is_boundary() const {
100  return boundary_;
101  }
102 
103  inline unsigned int idx() const {
104  return element_idx_;
105  }
106 private:
107  /**
108  * When dim_ == undefined_dim_ ; the value of element_idx_ is invalid.
109  * Is used for ElementAccessors for whole region
110  */
111  static const unsigned int undefined_dim_ = 100;
112 
113  /// Dimension of reference element.
114  unsigned int dim_;
115 
116  /// Pointer to the mesh owning the element.
117  const Mesh *mesh_;
118  /// True if the element is boundary, i.e. stored in Mesh::bc_elements, bulk elements are stored in Mesh::element
119  bool boundary_;
120 
121  /// Index into Mesh::bc_elements or Mesh::element array.
122  unsigned int element_idx_;
123 
124  /// Region index.
126 };
127 
128 
129 
130 
131 /******************************************************************* implementations
132  *
133  *
134  */
135 /*
136 template<int spacedim>
137 const BoundingBox &ElementAccessor<spacedim>::bounding_box() {
138  return box_;
139 }
140 */
141 
142 #endif /* ACCESSORS_HH_ */
const Element * element() const
Definition: accessors.hh:76
unsigned int dim_
Dimension of reference element.
Definition: accessors.hh:114
bool is_boundary() const
We need this method after replacing Region by RegionIdx, and movinf RegionDB instance into particular...
Definition: accessors.hh:99
???
Definition: mesh.h:109
bool is_valid() const
Definition: accessors.hh:69
const Mesh * mesh_
Pointer to the mesh owning the element.
Definition: accessors.hh:117
const RegionDB & region_db() const
Definition: mesh.h:155
unsigned int element_idx_
Index into Mesh::bc_elements or Mesh::element array.
Definition: accessors.hh:122
unsigned int dim() const
static const unsigned int undefined_dim_
Definition: accessors.hh:111
bool is_elemental() const
Definition: accessors.hh:65
#define ASSERT(...)
Definition: global_defs.h:121
ElementVector bc_elements
Definition: mesh.h:213
bool boundary_
True if the element is boundary, i.e. stored in Mesh::bc_elements, bulk elements are stored in Mesh::...
Definition: accessors.hh:119
Region region() const
Definition: accessors.hh:88
RegionIdx r_idx_
Region index.
Definition: accessors.hh:125
ElementAccessor(const Mesh *mesh, unsigned int idx, bool boundary)
Definition: accessors.hh:55
arma::vec3 centre() const
Definition: elements.cc:132
RegionIdx region_idx() const
Definition: accessors.hh:91
arma::vec::fixed< spacedim > centre() const
Definition: accessors.hh:81
ElementAccessor(const Mesh *mesh, RegionIdx r_idx)
Definition: accessors.hh:48
unsigned int dim() const
Definition: accessors.hh:73
unsigned int idx() const
Definition: accessors.hh:103
ElementVector element
Vector of elements of the mesh.
Definition: mesh.h:205
bool is_regional() const
Definition: accessors.hh:61