Flow123d  JS_before_hm-929-gaeebe69
node_accessor.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file node_accessor.hh
15  * @brief
16  */
17 
18 #ifndef NODE_ACCESSOR_HH_
19 #define NODE_ACCESSOR_HH_
20 
21 #include "system/armor.hh"
22 #include "mesh/point.hh"
23 #include "mesh/mesh.h"
24 
25 
26 /**
27  * Node accessor templated just by dimension of the embedding space, used for access to nodes out of Mesh.
28  * This should allow algorithms over nodes.
29  */
30 template <int spacedim>
31 class NodeAccessor {
32 public:
33  typedef typename Space<spacedim>::Point Point;
34 
35  /**
36  * Default invalid accessor.
37  */
39  : mesh_(NULL)
40  {}
41 
42  /**
43  * Node accessor.
44  */
45  NodeAccessor(const Mesh *mesh, unsigned int idx)
46  : mesh_(mesh), node_idx_(idx)
47  {}
48 
49  inline bool is_valid() const {
50  return mesh_ != NULL;
51  }
52 
53  inline unsigned int idx() const {
54  return node_idx_;
55  }
56 
57  // TODO: rename to gmsh_id
58  inline unsigned int index() const {
59  return (unsigned int)mesh_->find_node_id(node_idx_);
60  }
61 
62  inline void inc() {
63  ASSERT(is_valid()).error("Do not call inc() for invalid accessor!");
64  node_idx_++;
65  }
66 
67  bool operator==(const NodeAccessor<spacedim>& other) {
68  return (node_idx_ == other.node_idx_);
69  }
70 
71  inline Point operator*() const
72  { return mesh_->nodes_.vec<spacedim>(node_idx_); }
73 
74 
75 private:
76  /// Pointer to the mesh owning the node.
77  const Mesh *mesh_;
78 
79  /// Index into Mesh::node_vec_ array.
80  unsigned int node_idx_;
81 };
82 
83 
84 #endif /* NODE_ACCESSOR_HH_ */
Point operator*() const
NodeAccessor(const Mesh *mesh, unsigned int idx)
Armor::ArmaVec< double, spacedim > Point
Definition: point.hh:42
unsigned int node_idx_
Index into Mesh::node_vec_ array.
Definition: mesh.h:78
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:807
bool operator==(const NodeAccessor< spacedim > &other)
Armor::Array< double > nodes_
Definition: mesh.h:527
const Mesh * mesh_
Pointer to the mesh owning the node.
bool is_valid() const
unsigned int index() const
Space< spacedim >::Point Point
unsigned int idx() const
int find_node_id(unsigned int pos) const
Return node id (in GMSH file) of node of given position in node vector.
Definition: mesh.h:364