DiagTensorI.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-2018 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 "SphericalTensor.H"
27 #include "SymmTensor.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Cmpt>
33 {}
34 
35 
36 template<class Cmpt>
38 :
39  VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(Zero)
40 {}
41 
42 
43 template<class Cmpt>
44 template<class Cmpt2>
46 (
47  const VectorSpace<DiagTensor<Cmpt2>, Cmpt2, 3>& vs
48 )
49 :
50  VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(vs)
51 {}
52 
53 
54 template<class Cmpt>
56 (
57  const Cmpt& vxx,
58  const Cmpt& vyy,
59  const Cmpt& vzz
60 )
61 {
62  this->v_[XX] = vxx;
63  this->v_[YY] = vyy;
64  this->v_[ZZ] = vzz;
65 }
66 
67 
68 template<class Cmpt>
70 :
71  VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>(is)
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 template<class Cmpt>
78 inline const Cmpt& Foam::DiagTensor<Cmpt>::xx() const
79 {
80  return this->v_[XX];
81 }
82 
83 template<class Cmpt>
84 inline const Cmpt& Foam::DiagTensor<Cmpt>::yy() const
85 {
86  return this->v_[YY];
87 }
88 
89 template<class Cmpt>
90 inline const Cmpt& Foam::DiagTensor<Cmpt>::zz() const
91 {
92  return this->v_[ZZ];
93 }
94 
95 
96 template<class Cmpt>
98 {
99  return this->v_[XX];
100 }
101 
102 template<class Cmpt>
104 {
105  return this->v_[YY];
106 }
107 
108 template<class Cmpt>
110 {
111  return this->v_[ZZ];
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 namespace Foam
118 {
119 
120 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
121 
122 template<class Cmpt>
123 inline Tensor<Cmpt>
125 {
126  return Tensor<Cmpt>
127  (
128  dt1.xx() + t2.xx(), t2.xy(), t2.xz(),
129  t2.yx(), dt1.yy() + t2.yy(), t2.yz(),
130  t2.zx(), t2.zy(), dt1.zz() + t2.zz()
131  );
132 }
133 
134 
135 template<class Cmpt>
136 inline Tensor<Cmpt>
138 {
139  return Tensor<Cmpt>
140  (
141  t1.xx() + dt2.xx(), t1.xy(), t1.xz(),
142  t1.yx(), t1.yy() + dt2.yy(), t1.yz(),
143  t1.zx(), t1.zy(), t1.zz() + dt2.zz()
144  );
145 }
146 
147 
148 template<class Cmpt>
149 inline Tensor<Cmpt>
151 {
152  return Tensor<Cmpt>
153  (
154  dt1.xx() - t2.xx(), -t2.xy(), -t2.xz(),
155  -t2.yx(), dt1.yy() - t2.yy(), -t2.yz(),
156  -t2.zx(), -t2.zy(), dt1.zz() - t2.zz()
157  );
158 }
159 
160 
161 template<class Cmpt>
162 inline Tensor<Cmpt>
164 {
165  return Tensor<Cmpt>
166  (
167  t1.xx() - dt2.xx(), t1.xy(), t1.xz(),
168  t1.yx(), t1.yy() - dt2.yy(), t1.yz(),
169  t1.zx(), t1.zy(), t1.zz() - dt2.zz()
170  );
171 }
172 
173 
174 //- Inner-product between two diagonal tensors
175 template<class Cmpt>
176 inline DiagTensor<Cmpt>
178 {
179  return DiagTensor<Cmpt>
180  (
181  dt1.xx()*dt2.xx(),
182  dt1.yy()*dt2.yy(),
183  dt1.zz()*dt2.zz()
184  );
185 }
186 
187 
188 //- Inner-product between a diagonal tensor and a tensor
189 template<class Cmpt>
190 inline Tensor<Cmpt>
192 {
193  return Tensor<Cmpt>
194  (
195  dt1.xx()*t2.xx(),
196  dt1.xx()*t2.xy(),
197  dt1.xx()*t2.xz(),
198 
199  dt1.yy()*t2.yx(),
200  dt1.yy()*t2.yy(),
201  dt1.yy()*t2.yz(),
202 
203  dt1.zz()*t2.zx(),
204  dt1.zz()*t2.zy(),
205  dt1.zz()*t2.zz()
206  );
207 }
208 
209 
210 //- Inner-product between a tensor and a diagonal tensor
211 template<class Cmpt>
212 inline Tensor<Cmpt>
214 {
215  return Tensor<Cmpt>
216  (
217  t1.xx()*dt2.xx(),
218  t1.xy()*dt2.yy(),
219  t1.xz()*dt2.zz(),
220 
221  t1.yx()*dt2.xx(),
222  t1.yy()*dt2.yy(),
223  t1.yz()*dt2.zz(),
224 
225  t1.zx()*dt2.xx(),
226  t1.zy()*dt2.yy(),
227  t1.zz()*dt2.zz()
228  );
229 }
230 
231 
232 //- Inner-product between a diagonal tensor and a vector
233 template<class Cmpt>
234 inline Vector<Cmpt>
236 {
237  return Vector<Cmpt>
238  (
239  dt.xx()*v.x(),
240  dt.yy()*v.y(),
241  dt.zz()*v.z()
242  );
243 }
244 
245 
246 //- Inner-product between a vector and a diagonal tensor
247 template<class Cmpt>
248 inline Vector<Cmpt>
250 {
251  return Vector<Cmpt>
252  (
253  v.x()*dt.xx(),
254  v.y()*dt.yy(),
255  v.z()*dt.zz()
256  );
257 }
258 
259 
260 //- Division of a scalar by a diagonalTensor
261 template<class Cmpt>
262 inline DiagTensor<Cmpt>
263 operator/(const scalar s, const DiagTensor<Cmpt>& dt)
264 {
265  return DiagTensor<Cmpt>(s/dt.xx(), s/dt.yy(), s/dt.zz());
266 }
267 
268 
269 //- Division of a vector by a diagonalTensor
270 template<class Cmpt>
271 inline Vector<Cmpt>
273 {
274  return Vector<Cmpt>(v.x()/dt.xx(), v.y()/dt.yy(), v.z()/dt.zz());
275 }
276 
277 
278 //- Return the trace of a diagonal tensor
279 template<class Cmpt>
280 inline Cmpt tr(const DiagTensor<Cmpt>& dt)
281 {
282  return dt.xx() + dt.yy() + dt.zz();
283 }
284 
285 
286 //- Return the spherical part of a diagonal tensor
287 template<class Cmpt>
289 {
290  return 0.5*tr(dt);
291 }
292 
293 
294 //- Return the determinant of a diagonal tensor
295 template<class Cmpt>
296 inline Cmpt det(const DiagTensor<Cmpt>& t)
297 {
298  return t.xx()*t.yy()*t.zz();
299 }
300 
301 
302 //- Return the inverse of a diagonal tensor
303 template<class Cmpt>
305 {
306  return DiagTensor<Cmpt>(1.0/dt.xx(), 1.0/dt.yy(), 1.0/dt.zz());
307 }
308 
309 
310 //- Return the diagonal of a symmetric tensor as a diagonal tensor
311 template<class Cmpt>
313 {
314  return DiagTensor<Cmpt>(t.xx(), t.yy(), t.zz());
315 }
316 
317 
318 //- Return the diagonal of a tensor as a diagonal tensor
319 template<class Cmpt>
321 {
322  return DiagTensor<Cmpt>(t.xx(), t.yy(), t.zz());
323 }
324 
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 } // End namespace Foam
329 
330 // ************************************************************************* //
const Cmpt & yx() const
Definition: TensorI.H:184
const Cmpt & xx() const
Definition: DiagTensorI.H:78
DiagTensor< Cmpt > diag(const Tensor< Cmpt > &t)
Return the diagonal of a tensor as a diagonal tensor.
Definition: DiagTensorI.H:320
const Cmpt & yy() const
Definition: DiagTensorI.H:84
const Cmpt & zy() const
Definition: TensorI.H:212
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components...
Definition: SymmTensor.H:53
const Cmpt & xz() const
Definition: TensorI.H:177
DiagTensor< Cmpt > inv(const DiagTensor< Cmpt > &dt)
Return the inverse of a diagonal tensor.
Definition: DiagTensorI.H:304
const Cmpt & xx() const
Definition: SymmTensorI.H:87
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const Cmpt & yy() const
Definition: TensorI.H:191
const Cmpt & xx() const
Definition: TensorI.H:163
const Cmpt & yz() const
Definition: TensorI.H:198
const Cmpt & zz() const
Definition: DiagTensorI.H:90
Templated vector space.
Definition: VectorSpace.H:53
const Cmpt & z() const
Definition: VectorI.H:87
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a diagonal tensor.
Definition: DiagTensorI.H:288
const Cmpt & yy() const
Definition: SymmTensorI.H:105
const Cmpt & y() const
Definition: VectorI.H:81
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component, element access using th ii() member function and the inner-product (dot-product) and outer-product operators.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Vector< Cmpt > operator/(const Vector< Cmpt > v, const DiagTensor< Cmpt > &dt)
Division of a vector by a diagonalTensor.
Definition: DiagTensorI.H:272
const Cmpt & zz() const
Definition: SymmTensorI.H:117
Tensor< Cmpt > operator+(const Tensor< Cmpt > &t1, const DiagTensor< Cmpt > &dt2)
Definition: DiagTensorI.H:137
Templated 3D DiagTensor derived from VectorSpace.
Definition: DiagTensor.H:53
static const zero Zero
Definition: zero.H:97
const Cmpt & x() const
Definition: VectorI.H:75
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross product operators.
Definition: Vector.H:57
DiagTensor()
Construct null.
Definition: DiagTensorI.H:32
Cmpt tr(const DiagTensor< Cmpt > &dt)
Return the trace of a diagonal tensor.
Definition: DiagTensorI.H:280
Vector< Cmpt > operator &(const Vector< Cmpt > &v, const DiagTensor< Cmpt > &dt)
Inner-product between a vector and a diagonal tensor.
Definition: DiagTensorI.H:249
const Cmpt & zx() const
Definition: TensorI.H:205
Cmpt det(const DiagTensor< Cmpt > &t)
Return the determinant of a diagonal tensor.
Definition: DiagTensorI.H:296
Tensor< Cmpt > operator-(const Tensor< Cmpt > &t1, const DiagTensor< Cmpt > &dt2)
Definition: DiagTensorI.H:163
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
Templated 3D tensor derived from MatrixSpace adding construction from 9 components, element access using xx(), xy() etc. member functions and the inner-product (dot-product) and outer-product of two Vectors (tensor-product) operators.
Definition: complexI.H:215
const Cmpt & xy() const
Definition: TensorI.H:170
const Cmpt & zz() const
Definition: TensorI.H:219
Namespace for OpenFOAM.