Flow123d  JS_before_hm-2198-g122e1f2e2
mapping.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 mapping.hh
15  * @brief Class Mapping calculates data related to the mapping
16  * of the reference cell to the actual cell, such as Jacobian
17  * and normal vectors.
18  * @author Jan Stebel
19  */
20 
21 #ifndef MAPPING_HH_
22 #define MAPPING_HH_
23 
24 #include <armadillo>
25 #include <vector>
26 #include "system/fmt/posix.h" // for FMT_UNUSED
27 
28 
29 
30 
31 
32 
33 /**
34  * @brief Calculates determinant of a rectangular matrix.
35  */
36 template<class T>
37 double determinant(const T &M);
38 
39 
40 template<> inline double determinant(const arma::mat::fixed<1,2> &M)
41 {
42  return sqrt(M(0,0)*M(0,0)+M(0,1)*M(0,1));
43 }
44 
45 template<> inline double determinant(const arma::mat::fixed<2,1> &M)
46 {
47  return sqrt(M(0,0)*M(0,0)+M(1,0)*M(1,0));
48 }
49 
50 template<> inline double determinant(FMT_UNUSED const arma::mat::fixed<0,3> &M)
51 {
52  return 0;
53 }
54 
55 template<> inline double determinant(FMT_UNUSED const arma::mat::fixed<3,0> &M)
56 {
57  return 0;
58 }
59 
60 template<> inline double determinant(const arma::mat::fixed<1,3> &M)
61 {
62  return sqrt(M(0,0)*M(0,0)+M(0,1)*M(0,1)+M(0,2)*M(0,2));
63 }
64 
65 template<> inline double determinant(const arma::mat::fixed<3,1> &M)
66 {
67  return sqrt(M(0,0)*M(0,0)+M(1,0)*M(1,0)+M(2,0)*M(2,0));
68 }
69 
70 template<> inline double determinant(const arma::mat::fixed<2,3> &M)
71 {
72  return sqrt((M(0,0)*M(0,0)+M(0,1)*M(0,1)+M(0,2)*M(0,2))*(M(1,0)*M(1,0)+M(1,1)*M(1,1)+M(1,2)*M(1,2))
73  -(M(0,0)*M(1,0)+M(0,1)*M(1,1)+M(0,2)*M(1,2))*(M(0,0)*M(1,0)+M(0,1)*M(1,1)+M(0,2)*M(1,2)));
74 }
75 
76 template<> inline double determinant(const arma::mat::fixed<3,2> &M)
77 {
78  return sqrt((M(0,0)*M(0,0)+M(1,0)*M(1,0)+M(2,0)*M(2,0))*(M(0,1)*M(0,1)+M(1,1)*M(1,1)+M(2,1)*M(2,1))
79  -(M(0,0)*M(0,1)+M(1,0)*M(1,1)+M(2,0)*M(2,1))*(M(0,0)*M(0,1)+M(1,0)*M(1,1)+M(2,0)*M(2,1)));
80 }
81 
82 template<arma::uword n> inline double determinant(const arma::mat::fixed<n,n> &M)
83 {
84  return det(M);
85 }
86 
87 
88 
89 
90 
91 
92 #endif /* MAPPING_HH_ */
determinant
double determinant(const T &M)
Calculates determinant of a rectangular matrix.
posix.h
FMT_UNUSED
#define FMT_UNUSED
Definition: posix.h:75