SphericalTensor2DI.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-2023 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 "Vector2D.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Cmpt>
35 :
37 {}
38 
39 
40 template<class Cmpt>
42 (
43  const VectorSpace<SphericalTensor2D<Cmpt>, Cmpt, 1>& vs
44 )
45 :
47 {}
48 
49 
50 template<class Cmpt>
52 {
53  this->v_[II] = stii;
54 }
55 
56 
57 template<class Cmpt>
59 :
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
66 template<class Cmpt>
67 inline Foam::scalar Foam::SphericalTensor2D<Cmpt>::diagSqr() const
68 {
69  return 2*Foam::magSqr(this->ii());
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
75 namespace Foam
76 {
77 
78 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
79 
80 //- Return the trace of a SphericalTensor2D
81 template<class Cmpt>
82 inline Cmpt tr(const SphericalTensor2D<Cmpt>& st)
83 {
84  return 2*st.ii();
85 }
86 
87 
88 //- Return the spherical part of a SphericalTensor2D, i.e. itself
89 template<class Cmpt>
91 {
92  return st;
93 }
94 
95 
96 //- Return the determinant of a SphericalTensor2D
97 template<class Cmpt>
98 inline Cmpt det(const SphericalTensor2D<Cmpt>& st)
99 {
100  return st.ii()*st.ii();
101 }
102 
103 
104 //- Return the inverse of a SphericalTensor2D
105 template<class Cmpt>
106 inline SphericalTensor2D<Cmpt> inv(const SphericalTensor2D<Cmpt>& st)
107 {
108  #ifdef FULLDEBUG
109  if (mag(st.ii()) < VSMALL)
110  {
112  << "SphericalTensor2D not invertible, determinant:"
113  << det(st) << " tensor:" << st << nl
114  << abort(FatalError);
115  }
116  #endif
117 
118  return SphericalTensor2D<Cmpt>(1/st.ii());
119 }
120 
121 
122 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
123 
124 //- Division of a Cmpt by a SphericalTensor2D
125 template<class Cmpt>
126 inline SphericalTensor2D<Cmpt>
127 operator/(const Cmpt s, const SphericalTensor2D<Cmpt>& st)
128 {
129  #ifdef FULLDEBUG
130  if (mag(st.ii()) < VSMALL)
131  {
133  << "Cmpt = " << s
134  << " is not divisible due to a zero element in SphericalTensor2D:"
135  << "SphericalTensor2D = " << st
136  << abort(FatalError);
137  }
138  #endif
139 
140  return SphericalTensor2D<Cmpt>(s/st.ii());
141 }
142 
143 
144 //- Division of a SphericalTensor2D by a Cmpt
145 template<class Cmpt>
146 inline SphericalTensor2D<Cmpt>
147 operator/(const SphericalTensor2D<Cmpt>& st, const Cmpt s)
148 {
149  #ifdef FULLDEBUG
150  if (mag(s) < VSMALL)
151  {
153  << "SphericalTensor2D = " << st
154  << " is not divisible due to a zero value in Cmpt:"
155  << "Cmpt = " << s
156  << abort(FatalError);
157  }
158  #endif
159 
160  return SphericalTensor2D<Cmpt>(st.ii()/s);
161 }
162 
163 
164 //- Inner-product of a SphericalTensor2D and a SphericalTensor2D
165 template<class Cmpt>
166 inline SphericalTensor2D<Cmpt>
167 operator&
168 (
169  const SphericalTensor2D<Cmpt>& st1,
170  const SphericalTensor2D<Cmpt>& st2
171 )
172 {
173  return SphericalTensor2D<Cmpt>(st1.ii()*st2.ii());
174 }
176 
177 //- Inner-product of a SphericalTensor2D and a Vector2D
178 template<class Cmpt>
179 inline Vector2D<Cmpt>
181 {
182  return Vector2D<Cmpt>
183  (
184  st.ii()*v.x(),
185  st.ii()*v.y()
186  );
187 }
188 
190 //- Inner-product of a Vector2D and a SphericalTensor2D
191 template<class Cmpt>
192 inline Vector2D<Cmpt>
194 {
195  return Vector2D<Cmpt>
196  (
197  v.x()*st.ii(),
198  v.y()*st.ii()
199  );
200 }
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 template<class Cmpt>
206 class outerProduct<SphericalTensor2D<Cmpt>, Cmpt>
207 {
208 public:
209 
211 };
212 
213 template<class Cmpt>
214 class outerProduct<Cmpt, SphericalTensor2D<Cmpt>>
215 {
216 public:
219 };
220 
222 template<class Cmpt>
224 {
225 public:
226 
228 };
230 
231 template<class Cmpt>
232 class innerProduct<SphericalTensor2D<Cmpt>, Vector2D<Cmpt>>
233 {
234 public:
235 
236  typedef Vector2D<Cmpt> type;
237 };
239 template<class Cmpt>
240 class innerProduct<Vector2D<Cmpt>, SphericalTensor2D<Cmpt>>
241 {
242 public:
244  typedef Vector2D<Cmpt> type;
245 };
246 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 
250 } // End namespace Foam
252 // ************************************************************************* //
SphericalTensor2D()=default
Default construct.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
const Cmpt & y() const noexcept
Access to the vector y component.
Definition: Vector2D.H:132
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
const Cmpt & ii() const noexcept
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
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Templated vector space.
Definition: VectorSpace.H:52
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:110
scalar diagSqr() const
The L2-norm squared of the diagonal.
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
errorManip< error > abort(error &err)
Definition: errorManip.H:139
const Cmpt & x() const noexcept
Access to the vector x component.
Definition: Vector2D.H:127
A templated (2 x 2) diagonal tensor of objects of <T>, effectively containing 1 element, derived from VectorSpace.
tmp< GeometricField< Type, faPatchField, areaMesh > > operator &(const faMatrix< Type > &, const DimensionedField< Type, areaMesh > &)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
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))
Templated 2D Vector derived from VectorSpace adding construction from 2 components, element access using x() and y() member functions and the inner-product (dot-product).
Definition: Vector2D.H:51
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) - 2 >::type type
Definition: products.H:155
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127