SquareMatrixI.H
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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class Type>
30 :
31  Matrix<SquareMatrix<Type>, Type>()
32 {}
33 
34 
35 template<class Type>
37 :
38  Matrix<SquareMatrix<Type>, Type>(n, n)
39 {}
40 
41 
42 template<class Type>
43 template<class MatrixType>
45 (
47 )
48 :
49  Matrix<SquareMatrix<Type>, Type>(block)
50 {}
51 
52 
53 template<class Type>
54 template<class MatrixType>
56 (
58 )
59 :
60  Matrix<SquareMatrix<Type>, Type>(block)
61 {}
62 
63 
64 template<class Type>
66 :
67  Matrix<SquareMatrix<Type>, Type>(n, n, Zero)
68 {}
69 
70 
71 template<class Type>
73 (
74  const label m,
75  const label n,
76  const zero
77 )
78 :
79  Matrix<SquareMatrix<Type>, Type>(m, n, Zero)
80 {
81  if (m != n)
82  {
84  << "Attempt to construct a square matrix "
85  << m << " x " << n << nl
86  << abort(FatalError);
87  }
88 }
89 
90 
91 template<class Type>
93 (
94  const label n,
96 )
97 :
98  Matrix<SquareMatrix<Type>, Type>(n, n, Zero)
99 {
100  for (label i=0; i<n; i++)
101  {
102  this->operator()(i, i) = Type(I);
103  }
104 }
105 
106 
107 template<class Type>
109 (
110  const label n,
111  const Type& t
112 )
113 :
114  Matrix<SquareMatrix<Type>, Type>(n, n, t)
115 {}
116 
117 
118 template<class Type>
119 template<class InputIterator>
121 (
122  const label n,
123  InputIterator first,
124  InputIterator last
125 )
126 :
127  Matrix<SquareMatrix<Type>, Type>(n, n, first, last)
128 {}
129 
130 
131 template<class Type>
133 (
134  const label n,
135  std::initializer_list<Type> lst
136 )
137 :
138  Matrix<SquareMatrix<Type>, Type>(n, n, lst)
139 {}
140 
141 
142 template<class Type>
143 inline Foam::SquareMatrix<Type>::SquareMatrix(std::initializer_list<Type> lst)
144 :
145  SquareMatrix<Type>(sqrt(scalar(lst.size())), lst)
146 {}
147 
148 
149 template<class Type>
151 (
152  std::initializer_list<std::initializer_list<Type>> lstLst
153 )
154 :
155  Matrix<SquareMatrix<Type>, Type>(lstLst)
156 {
157  if (this->m() != this->n())
158  {
160  << "Attempt to construct a square matrix from a rectangular matrix "
161  << this->m() << " x " << this->n() << nl
162  << abort(FatalError);
163  }
164 }
165 
166 
167 template<class Type>
169 (
170  const RectangularMatrix<Type>& RM
171 )
172 :
173  Matrix<SquareMatrix<Type>, Type>(RM)
174 {
175  if (this->m() != this->n())
176  {
178  << "Attempt to construct a square matrix from a rectangular matrix "
179  << this->m() << " x " << this->n() << nl
180  << abort(FatalError);
181  }
182 }
183 
184 
185 template<class Type>
187 :
188  Matrix<SquareMatrix<Type>, Type>(is)
189 {}
190 
191 
192 template<class Type>
195 {
197 }
198 
199 
200 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
201 
202 template<class Type>
204 {
206 }
207 
208 
209 template<class Type>
211 {
212  Matrix<SquareMatrix<Type>, Type>::shallowResize(m, m);
213 }
214 
215 
216 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
217 
218 template<class Type>
220 {
221  Matrix<SquareMatrix<Type>, Type>::operator=(Zero);
222 }
223 
224 
225 template<class Type>
227 {
228  Matrix<SquareMatrix<Type>, Type>::operator=(Zero);
229  for (label i=0; i<this->n(); i++)
230  {
231  this->operator()(i, i) = Type(I);
232  }
233 }
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 namespace Foam
239 {
240 
241 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
242 
243 template<class Type>
245 (
246  const Field<Type>& f1,
247  const Field<Type>& f2
248 )
249 {
250  SquareMatrix<Type> f1f2T(f1.size());
251 
252  for (label i=0; i<f1f2T.m(); i++)
253  {
254  for (label j=0; j<f1f2T.n(); j++)
255  {
256  f1f2T(i, j) = f1[i]*f2[j];
257  }
258  }
259 
260  return f1f2T;
261 }
262 
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 } // End namespace Foam
267 
268 // ************************************************************************* //
label n
Pre-declare SubField and related Field type.
Definition: Field.H:83
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:50
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: MatrixBlock.H:116
A templated (m x n) matrix of objects of <T>.
Definition: Matrix.H:83
label n() const
Return the number of columns.
Definition: MatrixI.H:64
label m() const
Return the number of rows.
Definition: MatrixI.H:57
A templated 2D rectangular m x n matrix of objects of <Type>.
A templated 2D square matrix of objects of <T>, where the n x n matrix dimension is known and used fo...
Definition: SquareMatrix.H:61
SquareMatrix()
Null constructor.
Definition: SquareMatrixI.H:29
autoPtr< SquareMatrix< Type > > clone() const
Clone.
void setSize(const label m)
Resize the matrix preserving the elements.
void shallowResize(const label m)
Resize the matrix without reallocating storage (unsafe)
void operator=(const zero)
Assignment of all elements to zero.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:66
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
static const Identity< scalar > I
Definition: Identity.H:93
labelList first(const UList< labelPair > &p)
Definition: patchToPatch.C:39
Foam::SquareMatrix< Type > symmOuter(const Field< Type > &f1, const Field< Type > &f2)
error FatalError
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
static const char nl
Definition: Ostream.H:267
points setSize(newPointi)