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