tensorField.C
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) 2019-2022 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 "tensorField.H"
30 #include "transformField.H"
31 
32 #define TEMPLATE
33 #include "FieldFunctionsM.C"
34 
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
42 
43 UNARY_FUNCTION(scalar, tensor, tr)
50 UNARY_FUNCTION(scalar, tensor, det)
52 
53 void inv(Field<tensor>& tf, const UList<tensor>& tf1)
54 {
55  if (tf.empty())
56  {
57  return;
58  }
59 
60  // Attempting to identify 2-D cases
61  const scalar minThreshold = SMALL*magSqr(tf1[0]);
62  const Vector<bool> removeCmpts
63  (
64  magSqr(tf1[0].xx()) < minThreshold,
65  magSqr(tf1[0].yy()) < minThreshold,
66  magSqr(tf1[0].zz()) < minThreshold
67  );
68 
69  if (removeCmpts.x() || removeCmpts.y() || removeCmpts.z())
70  {
71  tensor adjust(Zero);
72 
73  if (removeCmpts.x()) adjust.xx() = 1;
74  if (removeCmpts.y()) adjust.yy() = 1;
75  if (removeCmpts.z()) adjust.zz() = 1;
76 
77  tensorField tf1Plus(tf1);
78 
79  tf1Plus += adjust;
80 
81  TFOR_ALL_F_OP_FUNC_F(tensor, tf, =, inv, tensor, tf1Plus)
82 
83  tf -= adjust;
84  }
85  else
86  {
87  TFOR_ALL_F_OP_FUNC_F(tensor, tf, =, inv, tensor, tf1)
88  }
89 }
90 
92 {
93  auto tres = tmp<tensorField>::New(tf.size());
94  inv(tres.ref(), tf);
95  return tres;
96 }
97 
98 tmp<tensorField> inv(const tmp<tensorField>& tf)
99 {
100  auto tres = New(tf);
101  inv(tres.ref(), tf());
102  tf.clear();
103  return tres;
104 }
105 
110 
111 
112 template<>
114 (
115  const symmTensorField& stf
116 )
117 {
118  auto tres = tmp<tensorField>::New(stf.size());
119  auto& res = tres.ref();
120  TFOR_ALL_F_OP_F(tensor, res, =, symmTensor, stf)
121  return tres;
122 }
123 
124 template<>
125 tmp<Field<tensor>> transformFieldMask<tensor>
126 (
127  const tmp<symmTensorField>& tstf
128 )
129 {
130  tmp<Field<tensor>> ret = transformFieldMask<tensor>(tstf());
131  tstf.clear();
132  return ret;
133 }
134 
135 
136 // * * * * * * * * * * * * * * * global operators * * * * * * * * * * * * * //
137 
140 
143 
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #include "undefFieldFunctionsM.H"
152 
153 // ************************************************************************* //
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
dimensionedTensor skew(const dimensionedTensor &dt)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Tensor< scalar > tensor
Definition: symmTensor.H:57
const Cmpt & y() const noexcept
Access to the vector y component.
Definition: Vector.H:140
dimensionedScalar det(const dimensionedSphericalTensor &dt)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
#define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2)
Definition: FieldM.H:111
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:87
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
dimensionedTensor eigenVectors(const dimensionedSymmTensor &dt)
tmp< Field< Type1 > > transformFieldMask(const Field< Type2 > &fld)
Spatial transformation functions for primitive fields.
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
Generic templated field type.
Definition: Field.H:61
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:55
symmTensor pinv(const symmTensor &st)
Return inverse of a given symmTensor, and fall back to pseudo-inverse if the symmTensor is singular...
Definition: symmTensor.C:334
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:203
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Vector< scalar > vector
Definition: vector.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:99
void hdual(pointPatchField< vector > &, const pointPatchField< tensor > &)
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
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
const Cmpt & x() const noexcept
Access to the vector x component.
Definition: Vector.H:135
const Cmpt & z() const noexcept
Access to the vector z component.
Definition: Vector.H:145
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
tmp< Field< tensor > > transformFieldMask< tensor >(const symmTensorField &)
Definition: tensorField.C:107
dimensionedVector eigenValues(const dimensionedSymmTensor &dt)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
#define TFOR_ALL_F_OP_F(typeF1, f1, OP, typeF2, f2)
Definition: FieldM.H:357
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Tensor of scalars, i.e. Tensor<scalar>.
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157