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