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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "DiagonalMatrix.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 :
36  List<Type>()
37 {}
38 
39 
40 template<class Type>
42 :
43  List<Type>(n)
44 {}
45 
46 
47 template<class Type>
49 :
50  List<Type>(n, Zero)
51 {}
52 
53 
54 template<class Type>
56 :
57  List<Type>(n, val)
58 {}
59 
60 
61 template<class Type>
62 template<class Form>
64 :
65  List<Type>(min(mat.m(), mat.n()))
66 {
67  label i = 0;
68 
69  for (Type& val : *this)
70  {
71  val = mat(i, i);
72  ++i;
73  }
74 }
75 
76 
77 template<class Type>
79 {
80  for (Type& val : *this)
81  {
82  if (mag(val) < VSMALL)
83  {
84  val = Zero;
85  }
86  else
87  {
88  val = Type(1)/val;
89  }
90  }
91 
92  return this;
93 }
94 
95 
96 template<class Type>
98 {
99  DiagonalMatrix<Type> Ainv(mat.size());
100 
101  Type* iter = Ainv.begin();
102 
103  for (const Type& val : mat)
104  {
105  if (mag(val) < VSMALL)
106  {
107  *iter = Zero;
108  }
109  else
110  {
111  *iter = Type(1)/val;
112  }
113 
114  ++iter;
115  }
116 
117  return Ainv;
118 }
119 
120 
121 // ************************************************************************* //
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::DiagonalMatrix::invert
DiagonalMatrix< Type > & invert()
Invert the diagonal matrix and return itself.
Definition: DiagonalMatrix.C:78
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
DiagonalMatrix.H
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::Matrix
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: DiagonalMatrix.H:48
Foam::DiagonalMatrix
A 2D diagonal matrix of objects of type <Type>, size (N x N)
Definition: DiagonalMatrix.H:55
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::label
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:62
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::DiagonalMatrix::DiagonalMatrix
DiagonalMatrix()
Construct null.
Definition: DiagonalMatrix.C:34
Foam::zero
A class representing the concept of 0 (zero), which can be used to avoid manipulating objects that ar...
Definition: zero.H:61