Flow123d  release_2.2.0-914-gf1a3a4f
sides.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 sides.cc
15  * @ingroup mesh
16  * @brief Some side related functions - should be made strictly geometric.
17  */
18 
19 #include "system/system.hh"
20 #include "mesh/mesh.h"
21 #include "sides.h"
22 #include "mesh/mesh_types.hh"
23 
24 
25 //=============================================================================
26 // CALCULATE METRICS OF THE SIDE
27 //=============================================================================
28 
29 double Side::measure() const {
30  switch ( dim() ) {
31  case 0:
32  return 1.0;
33  case 1: {
34  arma::vec3 diff = node(1)->point();
35  diff -= node(0)->point();
36  return arma::norm( diff , 2 );
37  }
38  case 2: {
39  arma::vec3 diff0 = node(1)->point() - node(0)->point();
40  arma::vec3 diff1 = node(2)->point() - node(0)->point();
41  return 0.5*arma::norm( arma::cross(diff0, diff1), 2);
42  }
43  }
44 
45  return 0.0;
46 }
47 
48 //=============================================================================
49 // CALCULATE NORMAL OF THE SIDE
50 //=============================================================================
51 
53  switch ( dim() ) {
54  case 0:
55  return normal_point();
56  case 1:
57  return normal_line();
58  case 2:
59  return normal_triangle();
60  }
61 
62  return arma::vec3("0 0 0");
63 }
64 //=============================================================================
65 //
66 //=============================================================================
67 
69  const Element * ele = element_;
70 
71  arma::vec3 normal(ele->node[1]->point());
72  normal -= ele->node[0] ->point();
73 
74  normal /=arma::norm(normal,2);
75  if ( node( 0 ) == ele->node[ 0 ] )
76  return -normal;
77  else
78  return normal;
79 }
80 //=============================================================================
81 //
82 //=============================================================================
83 
85  const Element * ele=element_;
86 
87  // At first, we need vector of the normal of the element
88  arma::vec3 elem_normal=arma::cross( ele->node[1]->point() - ele->node[0]->point(),
89  ele->node[2]->point() - ele->node[0]->point() );
90  elem_normal /= norm( elem_normal, 2);
91 
92  // Now we can calculate the "normal" of our side
93  arma::vec3 side_normal = arma::cross( node(1)->point() - node(0)->point() , elem_normal );
94  side_normal /= norm( side_normal, 2);
95 
96  if ( dot( side_normal, ele->centre() - node(0)->point() ) > 0.0)
97  return -side_normal;
98  else
99  return side_normal;
100 }
101 //=============================================================================
102 //
103 //=============================================================================
104 
106  const Element * ele=element_;
107 
108  arma::vec3 side_normal=arma::cross( node(1)->point() - node(0)->point(),
109  node(2)->point() - node(0)->point() );
110  side_normal /= norm( side_normal, 2);
111 
112  if ( dot(side_normal, ele->centre() - node(0)->point() ) > 0.0)
113  return -side_normal;
114  else
115  return side_normal;
116 }
117 
118 //=============================================================================
119 // CALCULATE CENTRE OF THE SIDE
120 //=============================================================================
121 
123  arma::vec3 barycenter;
124  barycenter.zeros();
125 
126  for(unsigned int i=0; i < n_nodes() ; i++)
127  barycenter += node( i )->point();
128 
129  barycenter /= (double) n_nodes();
130  return barycenter;
131 }
132 
133 
134 //-----------------------------------------------------------------------------
135 // vim: set cindent:
arma::vec3 normal_line() const
Definition: sides.cc:84
arma::vec3 centre() const
Definition: sides.cc:122
Node ** node
Definition: elements.h:90
arma::vec3 normal_point() const
Definition: sides.cc:68
unsigned int dim() const
Definition: side_impl.hh:37
arma::vec3 normal_triangle() const
Definition: sides.cc:105
double measure() const
Definition: sides.cc:29
arma::vec3 centre() const
Computes the barycenter.
Definition: elements.cc:130
arma::vec3 normal() const
Definition: sides.cc:52
const Element * element_
Definition: sides.h:108
const Node * node(unsigned int i) const
Definition: side_impl.hh:46
arma::vec3 & point()
Definition: nodes.hh:68
unsigned int n_nodes() const
Definition: side_impl.hh:33