Flow123d  JS_before_hm-1716-g9144da4bf
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_ */
Space::Point
Armor::ArmaVec< double, spacedim > Point
Definition: point.hh:42
Mesh::nodes_
Armor::Array< double > nodes_
Definition: mesh.h:584
armor.hh
NodeAccessor::is_valid
bool is_valid() const
Definition: node_accessor.hh:49
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
NodeAccessor::index
unsigned int index() const
Definition: node_accessor.hh:58
point.hh
Armor::Array::vec
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:821
NodeAccessor::mesh_
const Mesh * mesh_
Pointer to the mesh owning the node.
Definition: node_accessor.hh:77
NodeAccessor::operator*
Point operator*() const
Definition: node_accessor.hh:71
NodeAccessor::Point
Space< spacedim >::Point Point
Definition: node_accessor.hh:33
NodeAccessor::operator==
bool operator==(const NodeAccessor< spacedim > &other)
Definition: node_accessor.hh:67
NodeAccessor::NodeAccessor
NodeAccessor()
Definition: node_accessor.hh:38
NodeAccessor::inc
void inc()
Definition: node_accessor.hh:62
mesh.h
NodeAccessor::node_idx_
unsigned int node_idx_
Index into Mesh::node_vec_ array.
Definition: node_accessor.hh:80
Mesh
Definition: mesh.h:77
NodeAccessor
Definition: mesh.h:55
Mesh::find_node_id
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:405
NodeAccessor::idx
unsigned int idx() const
Definition: node_accessor.hh:53
NodeAccessor::NodeAccessor
NodeAccessor(const Mesh *mesh, unsigned int idx)
Definition: node_accessor.hh:45