SquareMatrixI.H
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 // * * * * * * * * * * * * * * * * 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 (
46  const ConstMatrixBlock<MatrixType>& block
47 )
48 :
49  Matrix<SquareMatrix<Type>, Type>(block)
50 {}
51 
52 
53 template<class Type>
54 template<class MatrixType>
56 (
57  const MatrixBlock<MatrixType>& block
58 )
59 :
60  Matrix<SquareMatrix<Type>, Type>(block)
61 {}
62 
63 
64 template<class Type>
66 (
67  const label n,
68  const zero
69 )
70 :
72 {}
73 
74 
75 template<class Type>
77 (
78  const label m,
79  const label n,
80  const zero
81 )
82 :
83  Matrix<SquareMatrix<Type>, Type>(m, n, Zero)
84 {
85  if (m != n)
86  {
88  << "Attempt to construct a square matrix "
89  << m << " x " << n << nl
90  << abort(FatalError);
91  }
92 }
93 
94 
95 template<class Type>
97 (
98  const label n,
99  const Identity<Type>
100 )
101 :
103 {
104  for (label i=0; i<n; i++)
105  {
106  this->operator()(i, i) = Type(I);
107  }
108 }
109 
110 
111 template<class Type>
113 (
114  const label n,
115  const Type& t
116 )
117 :
118  Matrix<SquareMatrix<Type>, Type>(n, n, t)
119 {}
120 
121 
122 template<class Type>
124 (
125  const RectangularMatrix<Type>& RM
126 )
127 :
128  Matrix<SquareMatrix<Type>, Type>(RM)
129 {
130  if (this->m() != this->n())
131  {
133  << "Attempt to construct a square matrix from a rectangular matrix "
134  << this->m() << " x " << this->n() << nl
135  << abort(FatalError);
136  }
137 }
138 
139 
140 template<class Type>
142 :
143  Matrix<SquareMatrix<Type>, Type>(is)
144 {}
145 
146 
147 template<class Type>
150 {
152 }
153 
154 
155 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
156 
157 template<class Type>
159 {
161 }
162 
163 
164 template<class Type>
166 {
167  Matrix<SquareMatrix<Type>, Type>::shallowResize(m, m);
168 }
169 
170 
171 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
172 
173 template<class Type>
175 {
176  Matrix<SquareMatrix<Type>, Type>::operator=(Zero);
177 }
178 
179 
180 template<class Type>
182 {
183  Matrix<SquareMatrix<Type>, Type>::operator=(Zero);
184  for (label i=0; i<this->n(); i++)
185  {
186  this->operator()(i, i) = Type(I);
187  }
188 }
189 
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 namespace Foam
194 {
195 
196 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
197 
198 template<class Type>
200 (
201  const Field<Type>& f1,
202  const Field<Type>& f2
203 )
204 {
205  SquareMatrix<Type> f1f2T(f1.size());
206 
207  for (label i=0; i<f1f2T.m(); i++)
208  {
209  for (label j=0; j<f1f2T.n(); j++)
210  {
211  f1f2T(i, j) = f1[i]*f2[j];
212  }
213  }
214 
215  return f1f2T;
216 }
217 
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 } // End namespace Foam
222 
223 // ************************************************************************* //
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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
autoPtr< SquareMatrix< Type > > clone() const
Clone.
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:71
void operator=(const zero)
Assignment of all elements to zero.
void shallowResize(const label m)
Resize the matrix without reallocating storage (unsafe)
scalar f1
Definition: createFields.H:28
points setSize(newPointi)
static const Identity< scalar > I
Definition: Identity.H:93
Pre-declare SubField and related Field type.
Definition: Field.H:57
static const zero Zero
Definition: zero.H:91
A templated 2D rectangular m x n matrix of objects of <Type>.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A templated (m x n) matrix of objects of <T>.
static const char nl
Definition: Ostream.H:262
void setSize(const label m)
Resize the matrix preserving the elements.
Foam::SquareMatrix< Type > symmOuter(const Field< Type > &f1, const Field< Type > &f2)
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
label n
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:47
A templated 2D square matrix of objects of <T>, where the n x n matrix dimension is known and used fo...
Definition: SquareMatrix.H:58
SquareMatrix()
Null constructor.
Definition: SquareMatrixI.H:29
Namespace for OpenFOAM.