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-2025 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>
65 Foam::DiagonalMatrix<Type>::DiagonalMatrix(std::initializer_list<Type> lst)
66 :
67  List<Type>(lst)
68 {}
69 
70 
71 template<class Type>
73 :
74  List<Type>(is)
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
80 template<class Type>
82 {
83  forAll(*this, i)
84  {
85  Type x = this->operator[](i);
86  if (mag(x) < vSmall)
87  {
88  this->operator[](i) = Type(0);
89  }
90  else
91  {
92  this->operator[](i) = Type(1)/x;
93  }
94  }
95 
96  return this;
97 }
98 
99 
100 template<class Type>
101 Foam::DiagonalMatrix<Type> Foam::inv(const DiagonalMatrix<Type>& A)
102 {
103  DiagonalMatrix<Type> Ainv = A;
104 
105  forAll(A, i)
106  {
107  Type x = A[i];
108  if (mag(x) < vSmall)
109  {
110  Ainv[i] = Type(0);
111  }
112  else
113  {
114  Ainv[i] = Type(1)/x;
115  }
116  }
117 
118  return Ainv;
119 }
120 
121 
122 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
DiagonalMatrix<Type> is a 2D diagonal matrix of objects of type Type, size nxn.
DiagonalMatrix< Type > & invert()
Invert the diagonal matrix and return itself.
DiagonalMatrix()
Null constructor.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
A templated (m x n) matrix of objects of <T>.
Definition: Matrix.H:83
Type & operator[](const label)
Return element of UList.
Definition: UListI.H:167
static const coefficient A("A", dimPressure, 611.21)
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
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void inv(LagrangianPatchField< tensor > &f, const LagrangianPatchField< tensor > &f1)