Flow123d  release_3.0.0-1263-g7cf53c1
accessors.cc
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 accessors.cc
15  * @brief Implementation of other functions of the mesh accessors.
16  */
17 
18 #include "mesh/accessors.hh"
19 #include "system/system.hh"
20 #include "mesh/mesh.h"
21 
22 
23 //=============================================================================
24 // CALCULATE METRICS OF THE SIDE
25 //=============================================================================
26 
27 double Side::measure() const {
28  switch ( dim() ) {
29  case 0:
30  return 1.0;
31  case 1: {
32  arma::vec3 diff = node(1)->point();
33  diff -= node(0)->point();
34  return arma::norm( diff , 2 );
35  }
36  case 2: {
37  arma::vec3 diff0 = node(1)->point() - node(0)->point();
38  arma::vec3 diff1 = node(2)->point() - node(0)->point();
39  return 0.5*arma::norm( arma::cross(diff0, diff1), 2);
40  }
41  }
42 
43  return 0.0;
44 }
45 
46 //=============================================================================
47 // CALCULATE NORMAL OF THE SIDE
48 //=============================================================================
49 
51  switch ( dim() ) {
52  case 0:
53  return normal_point();
54  case 1:
55  return normal_line();
56  case 2:
57  return normal_triangle();
58  }
59 
60  return arma::vec3("0 0 0");
61 }
62 //=============================================================================
63 //
64 //=============================================================================
65 
68 
69  arma::vec3 normal(ele.node(1)->point());
70  normal -= ele.node(0) ->point();
71 
72  normal /=arma::norm(normal,2);
73  if ( node( 0 ) == ele.node_accessor( 0 ) )
74  return -normal;
75  else
76  return normal;
77 }
78 //=============================================================================
79 //
80 //=============================================================================
81 
84 
85  // At first, we need vector of the normal of the element
86  arma::vec3 elem_normal=arma::cross( ele.node(1)->point() - ele.node(0)->point(),
87  ele.node(2)->point() - ele.node(0)->point() );
88  elem_normal /= norm( elem_normal, 2);
89 
90  // Now we can calculate the "normal" of our side
91  arma::vec3 side_normal = arma::cross( node(1)->point() - node(0)->point() , elem_normal );
92  side_normal /= norm( side_normal, 2);
93 
94  if ( dot( side_normal, ele.centre() - node(0)->point() ) > 0.0)
95  return -side_normal;
96  else
97  return side_normal;
98 }
99 //=============================================================================
100 //
101 //=============================================================================
102 
104  arma::vec3 side_normal=arma::cross( node(1)->point() - node(0)->point(),
105  node(2)->point() - node(0)->point() );
106  side_normal /= norm( side_normal, 2);
107 
108  if ( dot(side_normal, element().centre() - node(0)->point() ) > 0.0)
109  return -side_normal;
110  else
111  return side_normal;
112 }
113 
114 //=============================================================================
115 // CALCULATE CENTRE OF THE SIDE
116 //=============================================================================
117 
119  arma::vec3 barycenter;
120  barycenter.zeros();
121 
122  for(unsigned int i=0; i < n_nodes() ; i++)
123  barycenter += node( i )->point();
124 
125  barycenter /= (double) n_nodes();
126  return barycenter;
127 }
128 
129 
130 //=============================================================================
131 // CALCULATE THE SIDE DIAMETER
132 //=============================================================================
133 
134 double Side::diameter() const {
135  if (dim() == 0)
136  {
137  return 1.0;
138  }
139  else
140  {
141  double h = 0.0;
142  for (unsigned int i=0; i<n_nodes(); i++)
143  for (unsigned int j=i+1; j<n_nodes(); j++)
144  h = max(h, node(i)->distance(*node(j).node()));
145  return h;
146  }
147 }
NodeAccessor< 3 > node_accessor(unsigned int ni) const
Definition: accessors.hh:202
arma::vec3 normal_line() const
Definition: accessors.cc:82
arma::vec3 centre() const
Centre of side.
Definition: accessors.cc:118
ElementAccessor< 3 > element() const
Returns iterator to the element of the side.
arma::vec3 normal_point() const
This is necessary by current DofHandler, should change this.
Definition: accessors.cc:66
arma::vec::fixed< spacedim > centre() const
Computes the barycenter.
unsigned int dim() const
Returns dimension of the side, that is dimension of the element minus one.
arma::vec3 normal_triangle() const
Definition: accessors.cc:103
Type dot(const Mat< Type, nRows, nCols > &a, const Mat< Type, nRows, nCols > &b)
Definition: armor.hh:176
NodeAccessor< 3 > node(unsigned int i) const
Returns node for given local index i on the side.
double measure() const
Calculate metrics of the side.
Definition: accessors.cc:27
double diameter() const
Calculate the side diameter.
Definition: accessors.cc:134
arma::vec3 normal() const
Vector of (generalized) normal.
Definition: accessors.cc:50
arma::vec3 & point()
Definition: nodes.hh:67
unsigned int n_nodes() const
Returns number of nodes of the side.
Definition: accessors.hh:405
const Node * node(unsigned int ni) const
Definition: accessors.hh:198