Flow123d  jenkins-Flow123d-linux-release-multijob-282
sides.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  *
26  * @file
27  * @ingroup mesh
28  * @brief Some side related functions - should be made strictly geometric.
29  *
30  */
31 
32 #include "system/system.hh"
33 #include "mesh/mesh.h"
34 #include "sides.h"
35 #include "mesh/mesh_types.hh"
36 
37 
38 //=============================================================================
39 // CALCULATE METRICS OF THE SIDE
40 //=============================================================================
41 
42 double Side::measure() const {
43  switch ( dim() ) {
44  case 0:
45  return 1.0;
46  case 1: {
47  arma::vec3 diff = node(1)->point();
48  diff -= node(0)->point();
49  return arma::norm( diff , 2 );
50  }
51  case 2: {
52  arma::vec3 diff0 = node(1)->point() - node(0)->point();
53  arma::vec3 diff1 = node(2)->point() - node(0)->point();
54  return 0.5*arma::norm( arma::cross(diff0, diff1), 2);
55  }
56  }
57 
58  return 0.0;
59 }
60 
61 //=============================================================================
62 // CALCULATE NORMAL OF THE SIDE
63 //=============================================================================
64 
66  switch ( dim() ) {
67  case 0:
68  return normal_point();
69  case 1:
70  return normal_line();
71  case 2:
72  return normal_triangle();
73  }
74 
75  return arma::vec3("0 0 0");
76 }
77 //=============================================================================
78 //
79 //=============================================================================
80 
82  const Element * ele = element_;
83 
84  arma::vec3 normal(ele->node[1]->point());
85  normal -= ele->node[0] ->point();
86 
87  normal /=arma::norm(normal,2);
88  if ( node( 0 ) == ele->node[ 0 ] )
89  return -normal;
90  else
91  return normal;
92 }
93 //=============================================================================
94 //
95 //=============================================================================
96 
98  const Element * ele=element_;
99 
100  // At first, we need vector of the normal of the element
101  arma::vec3 elem_normal=arma::cross( ele->node[1]->point() - ele->node[0]->point(),
102  ele->node[2]->point() - ele->node[0]->point() );
103  elem_normal /= norm( elem_normal, 2);
104 
105  // Now we can calculate the "normal" of our side
106  arma::vec3 side_normal = arma::cross( node(1)->point() - node(0)->point() , elem_normal );
107  side_normal /= norm( side_normal, 2);
108 
109  if ( dot( side_normal, ele->centre() - node(0)->point() ) > 0.0)
110  return -side_normal;
111  else
112  return side_normal;
113 }
114 //=============================================================================
115 //
116 //=============================================================================
117 
119  const Element * ele=element_;
120 
121  arma::vec3 side_normal=arma::cross( node(1)->point() - node(0)->point(),
122  node(2)->point() - node(0)->point() );
123  side_normal /= norm( side_normal, 2);
124 
125  if ( dot(side_normal, ele->centre() - node(0)->point() ) > 0.0)
126  return -side_normal;
127  else
128  return side_normal;
129 }
130 
131 //=============================================================================
132 // CALCULATE CENTRE OF THE SIDE
133 //=============================================================================
134 
136  arma::vec3 barycenter;
137  barycenter.zeros();
138 
139  for(unsigned int i=0; i < n_nodes() ; i++)
140  barycenter += node( i )->point();
141 
142  barycenter /= (double) n_nodes();
143  return barycenter;
144 }
145 
146 
147 //-----------------------------------------------------------------------------
148 // vim: set cindent:
arma::vec3 normal_line() const
Definition: sides.cc:97
arma::vec3 centre() const
Definition: sides.cc:135
???
Node ** node
Definition: elements.h:90
arma::vec3 normal_point() const
Definition: sides.cc:81
unsigned int dim() const
Definition: side_impl.hh:26
arma::vec3 normal_triangle() const
Definition: sides.cc:118
double measure() const
Definition: sides.cc:42
arma::vec3 centre() const
Definition: elements.cc:132
arma::vec3 normal() const
Definition: sides.cc:65
const Element * element_
Definition: sides.h:120
const Node * node(unsigned int i) const
Definition: side_impl.hh:35
arma::vec3 & point()
Definition: nodes.hh:80
unsigned int n_nodes() const
Definition: side_impl.hh:22