symmTensorField.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 "symmTensorField.H"
30 #include "transformField.H"
31 
32 #define TEMPLATE
33 #include "FieldFunctionsM.C"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
41 
44 
53 
54 void inv(Field<symmTensor>& tf, const UList<symmTensor>& tf1)
55 {
56  if (tf.empty())
57  {
58  return;
59  }
60 
61  // Attempting to identify 2-D cases
62  const scalar minThreshold = SMALL*magSqr(tf1[0]);
63  const Vector<bool> removeCmpts
64  (
65  magSqr(tf1[0].xx()) < minThreshold,
66  magSqr(tf1[0].yy()) < minThreshold,
67  magSqr(tf1[0].zz()) < minThreshold
68  );
69 
70  if (removeCmpts.x() || removeCmpts.y() || removeCmpts.z())
71  {
72  symmTensor adjust(Zero);
73 
74  if (removeCmpts.x()) adjust.xx() = 1;
75  if (removeCmpts.y()) adjust.yy() = 1;
76  if (removeCmpts.z()) adjust.zz() = 1;
77 
78  symmTensorField tf1Plus(tf1);
79 
80  tf1Plus += adjust;
81 
83 
84  tf -= adjust;
85  }
86  else
87  {
89  }
90 }
91 
93 {
94  auto tresult = tmp<symmTensorField>::New(tf.size());
95  inv(tresult.ref(), tf);
96  return tresult;
97 }
98 
99 tmp<symmTensorField> inv(const tmp<symmTensorField>& tf)
100 {
101  tmp<symmTensorField> tresult = New(tf);
102  inv(tresult.ref(), tf());
103  tf.clear();
104  return tresult;
105 }
106 
107 
108 template<>
109 tmp<Field<symmTensor>> transformFieldMask<symmTensor>
110 (
111  const tensorField& tf
112 )
113 {
114  return symm(tf);
115 }
116 
117 template<>
118 tmp<Field<symmTensor>> transformFieldMask<symmTensor>
119 (
120  const tmp<tensorField>& ttf
121 )
122 {
123  tmp<Field<symmTensor>> ret = transformFieldMask<symmTensor>(ttf());
124  ttf.clear();
125  return ret;
126 }
127 
128 
129 template<>
130 tmp<Field<symmTensor>> transformFieldMask<symmTensor>
131 (
132  const symmTensorField& stf
133 )
134 {
135  return stf;
136 }
137 
138 template<>
139 tmp<Field<symmTensor>> transformFieldMask<symmTensor>
140 (
141  const tmp<symmTensorField>& tstf
142 )
143 {
144  return tstf;
145 }
146 
148 
149 
150 // * * * * * * * * * * * * * * * global operators * * * * * * * * * * * * * //
151 
153 
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #include "undefFieldFunctionsM.H"
165 
166 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
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)
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
const Cmpt & zz() const noexcept
Definition: SymmTensor.H:158
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
const Cmpt & xx() const noexcept
Definition: SymmTensor.H:150
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
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
const Cmpt & x() const noexcept
Access to the vector x component.
Definition: Vector.H:135
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
const Cmpt & z() const noexcept
Access to the vector z component.
Definition: Vector.H:145
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
const Cmpt & yy() const noexcept
Definition: SymmTensor.H:154
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
tmp< Field< symmTensor > > transformFieldMask< symmTensor >(const tensorField &tf)
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