DiagonalMatrix.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "DiagonalMatrix.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 :
33  List<Type>()
34 {}
35 
36 
37 template<class Type>
38 template<class Form>
40 :
41  List<Type>(min(a.m(), a.n()))
42 {
43  forAll(*this, i)
44  {
45  this->operator[](i) = a(i, i);
46  }
47 }
48 
49 
50 template<class Type>
52 :
53  List<Type>(size)
54 {}
55 
56 
57 template<class Type>
59 :
60  List<Type>(size, val)
61 {}
62 
63 
64 template<class Type>
66 {
67  forAll(*this, i)
68  {
69  Type x = this->operator[](i);
70  if (mag(x) < VSMALL)
71  {
72  this->operator[](i) = Type(0);
73  }
74  else
75  {
76  this->operator[](i) = Type(1)/x;
77  }
78  }
79 
80  return this;
81 }
82 
83 
84 template<class Type>
86 {
87  DiagonalMatrix<Type> Ainv = A;
88 
89  forAll(A, i)
90  {
91  Type x = A[i];
92  if (mag(x) < VSMALL)
93  {
94  Ainv[i] = Type(0);
95  }
96  else
97  {
98  Ainv[i] = Type(1)/x;
99  }
100  }
101 
102  return Ainv;
103 }
104 
105 
106 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Type & operator[](const label)
Return element of UList.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
DiagonalMatrix<Type> is a 2D diagonal matrix of objects of type Type, size nxn.
A templated (m x n) matrix of objects of <T>.
DiagonalMatrix< Type > & invert()
Invert the diagonal matrix and return itself.
DiagonalMatrix()
Null constructor.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
label size() const
Return the number of elements in the UList.
dimensioned< scalar > mag(const dimensioned< Type > &)
label n