DiagonalMatrix.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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  List<Type>(is)
68 {}
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
73 template<class Type>
75 {
76  forAll(*this, i)
77  {
78  Type x = this->operator[](i);
79  if (mag(x) < vSmall)
80  {
81  this->operator[](i) = Type(0);
82  }
83  else
84  {
85  this->operator[](i) = Type(1)/x;
86  }
87  }
88 
89  return this;
90 }
91 
92 
93 template<class Type>
95 {
96  DiagonalMatrix<Type> Ainv = A;
97 
98  forAll(A, i)
99  {
100  Type x = A[i];
101  if (mag(x) < vSmall)
102  {
103  Ainv[i] = Type(0);
104  }
105  else
106  {
107  Ainv[i] = Type(1)/x;
108  }
109  }
110 
111  return Ainv;
112 }
113 
114 
115 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
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)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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 > &)
dimensioned< scalar > mag(const dimensioned< Type > &)
label n