SphericalTensorI.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "Vector.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Cmpt>
35 :
37 {}
38 
39 
40 template<class Cmpt>
41 template<class Cmpt2>
43 (
44  const VectorSpace<SphericalTensor<Cmpt2>, Cmpt2, 1>& vs
45 )
46 :
48 {}
49 
50 
51 template<class Cmpt>
53 {
54  this->v_[II] = stii;
55 }
56 
57 
58 template<class Cmpt>
60 :
61  SphericalTensor::vsType(is)
62 {}
63 
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
67 template<class Cmpt>
68 inline const Foam::SphericalTensor<Cmpt>&
70 {
71  return *this;
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77 namespace Foam
78 {
79 
80 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
81 
82 //- Return the trace of a SphericalTensor
83 template<class Cmpt>
84 inline Cmpt tr(const SphericalTensor<Cmpt>& st)
85 {
86  return 3*st.ii();
87 }
88 
89 
90 //- Return the spherical part of a SphericalTensor, i.e. itself
91 template<class Cmpt>
93 {
94  return st;
95 }
96 
97 
98 //- Return the determinant of a SphericalTensor
99 template<class Cmpt>
100 inline Cmpt det(const SphericalTensor<Cmpt>& st)
101 {
102  return st.ii()*st.ii()*st.ii();
103 }
104 
105 
106 //- Return the inverse of a SphericalTensor
107 template<class Cmpt>
108 inline SphericalTensor<Cmpt> inv(const SphericalTensor<Cmpt>& st)
109 {
110  #ifdef FULLDEBUG
111  if (mag(st.ii()) < VSMALL)
112  {
114  << "SphericalTensor is not invertible due to the zero determinant:"
115  << "det(SphericalTensor) = " << det(st)
116  << abort(FatalError);
117  }
118  #endif
119 
120  return SphericalTensor<Cmpt>(1/st.ii());
121 }
122 
123 
124 //- Return the square of Frobenius norm of a SphericalTensor as a Cmpt
125 template<class Cmpt>
126 inline Cmpt magSqr(const SphericalTensor<Cmpt>& st)
127 {
128  return Cmpt(3*mag(st.ii()*st.ii()));
129 }
130 
131 
132 //- Return the max component of a SphericalTensor
133 template<class Cmpt>
134 inline Cmpt cmptMax(const SphericalTensor<Cmpt>& st)
135 {
136  return st.ii();
137 }
138 
140 //- Return the min component of a SphericalTensor
141 template<class Cmpt>
142 inline Cmpt cmptMin(const SphericalTensor<Cmpt>& st)
143 {
144  return st.ii();
145 }
146 
147 
148 //- Return the sum of components of a SphericalTensor
149 template<class Cmpt>
150 inline Cmpt cmptSum(const SphericalTensor<Cmpt>& st)
151 {
152  return 3*st.ii();
153 }
154 
155 
156 //- Return the arithmetic average of components of a SphericalTensor
157 template<class Cmpt>
158 inline Cmpt cmptAv(const SphericalTensor<Cmpt>& st)
159 {
160  return st.ii();
161 }
162 
163 
164 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
165 
166 //- Division of a Cmpt by a SphericalTensor
167 template<class Cmpt>
168 inline SphericalTensor<Cmpt>
169 operator/(const Cmpt s, const SphericalTensor<Cmpt>& st)
170 {
171  #ifdef FULLDEBUG
172  if (mag(st.ii()) < VSMALL)
173  {
175  << "Cmpt = " << s
176  << " is not divisible due to a zero element in SphericalTensor:"
177  << "SphericalTensor = " << st
178  << abort(FatalError);
179  }
180  #endif
181 
182  return SphericalTensor<Cmpt>(s/st.ii());
183 }
184 
185 
186 //- Division of a SphericalTensor by a Cmpt
187 template<class Cmpt>
188 inline SphericalTensor<Cmpt>
189 operator/(const SphericalTensor<Cmpt>& st, const Cmpt s)
190 {
191  #ifdef FULLDEBUG
192  if (mag(s) < VSMALL)
193  {
195  << "SphericalTensor = " << st
196  << " is not divisible due to a zero value in Cmpt:"
197  << "Cmpt = " << s
198  << abort(FatalError);
199  }
200  #endif
201 
202  return SphericalTensor<Cmpt>(st.ii()/s);
203 }
205 
206 //- Inner-product of a SphericalTensor and a SphericalTensor
207 template<class Cmpt>
210 {
211  return SphericalTensor<Cmpt>(st1.ii()*st2.ii());
212 }
213 
214 
215 //- Inner-product of a SphericalTensor and a Vector
216 template<class Cmpt>
217 inline Vector<Cmpt>
218 operator&(const SphericalTensor<Cmpt>& st, const Vector<Cmpt>& v)
219 {
220  return Vector<Cmpt>
221  (
222  st.ii()*v.x(),
223  st.ii()*v.y(),
224  st.ii()*v.z()
225  );
226 }
227 
228 
229 //- Inner-product of a Vector and a SphericalTensor
230 template<class Cmpt>
231 inline Vector<Cmpt>
232 operator&(const Vector<Cmpt>& v, const SphericalTensor<Cmpt>& st)
233 {
234  return Vector<Cmpt>
235  (
236  v.x()*st.ii(),
237  v.y()*st.ii(),
238  v.z()*st.ii()
239  );
240 }
241 
242 
243 //- Double-inner-product of a SphericalTensor and a SphericalTensor
244 template<class Cmpt>
245 inline Cmpt
246 operator&&(const SphericalTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& st2)
247 {
248  return 3*st1.ii()*st2.ii();
249 }
250 
251 
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 template<class Cmpt>
255 class outerProduct<SphericalTensor<Cmpt>, Cmpt>
256 {
257 public:
258 
259  typedef SphericalTensor<Cmpt> type;
260 };
261 
262 template<class Cmpt>
263 class outerProduct<Cmpt, SphericalTensor<Cmpt>>
264 {
265 public:
266 
267  typedef SphericalTensor<Cmpt> type;
268 };
270 
271 template<class Cmpt>
272 class innerProduct<SphericalTensor<Cmpt>, SphericalTensor<Cmpt>>
273 {
274 public:
275 
276  typedef SphericalTensor<Cmpt> type;
277 };
279 
280 template<class Cmpt>
281 class innerProduct<SphericalTensor<Cmpt>, Vector<Cmpt>>
282 {
283 public:
284 
285  typedef Vector<Cmpt> type;
286 };
287 
288 template<class Cmpt>
289 class innerProduct<Vector<Cmpt>, SphericalTensor<Cmpt>>
290 {
291 public:
292 
293  typedef Vector<Cmpt> type;
294 };
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 } // End namespace Foam
300 
301 // ************************************************************************* //
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
Cmpt cmptSum(const SphericalTensor< Cmpt > &st)
Return the sum of components of a SphericalTensor.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Templated vector space.
Definition: VectorSpace.H:52
dimensionSet operator &&(const dimensionSet &ds1, const dimensionSet &ds2)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
dimensionedScalar det(const dimensionedSphericalTensor &dt)
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:87
A templated (3 x 3) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
const Cmpt & ii() const noexcept
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
errorManip< error > abort(error &err)
Definition: errorManip.H:139
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:58
tmp< GeometricField< Type, faPatchField, areaMesh > > operator &(const faMatrix< Type > &, const DimensionedField< Type, areaMesh > &)
const SphericalTensor< Cmpt > & T() const
Return non-Hermitian transpose (no-op)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:58
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) - 2 >::type type
Definition: products.H:155
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
SphericalTensor()=default
Default construct.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157