symmTensorField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 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 "symmTensorField.H"
27 #include "transformField.H"
28 
29 #define TEMPLATE
30 #include "FieldFunctionsM.C"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * global functions * * * * * * * * * * * * * //
38 
41 
50 
51 void inv(Field<symmTensor>& tf, const UList<symmTensor>& tf1)
52 {
53  if (tf.empty())
54  {
55  return;
56  }
57 
58  scalar scale = magSqr(tf1[0]);
59  Vector<bool> removeCmpts
60  (
61  magSqr(tf1[0].xx())/scale < small,
62  magSqr(tf1[0].yy())/scale < small,
63  magSqr(tf1[0].zz())/scale < small
64  );
65 
66  if (removeCmpts.x() || removeCmpts.y() || removeCmpts.z())
67  {
68  symmTensorField tf1Plus(tf1);
69 
70  if (removeCmpts.x())
71  {
72  tf1Plus += symmTensor(1,0,0,0,0,0);
73  }
74 
75  if (removeCmpts.y())
76  {
77  tf1Plus += symmTensor(0,0,0,1,0,0);
78  }
79 
80  if (removeCmpts.z())
81  {
82  tf1Plus += symmTensor(0,0,0,0,0,1);
83  }
84 
86 
87  if (removeCmpts.x())
88  {
89  tf -= symmTensor(1,0,0,0,0,0);
90  }
91 
92  if (removeCmpts.y())
93  {
94  tf -= symmTensor(0,0,0,1,0,0);
95  }
96 
97  if (removeCmpts.z())
98  {
99  tf -= symmTensor(0,0,0,0,0,1);
100  }
101  }
102  else
103  {
105  }
106 }
107 
109 {
111  inv(result.ref(), tf);
112  return result;
113 }
114 
116 {
118  inv(result.ref(), tf);
119  return result;
120 }
121 
123 {
124  tmp<symmTensorField> tRes = New(tf);
125  inv(tRes.ref(), tf());
126  tf.clear();
127  return tRes;
128 }
129 
130 
131 template<>
132 tmp<Field<symmTensor>> transformFieldMask<symmTensor>
133 (
134  const tensorField& tf
135 )
136 {
137  return symm(tf);
138 }
139 
140 template<>
141 tmp<Field<symmTensor>> transformFieldMask<symmTensor>
142 (
143  const tmp<tensorField>& ttf
144 )
145 {
146  tmp<Field<symmTensor>> ret = transformFieldMask<symmTensor>(ttf());
147  ttf.clear();
148  return ret;
149 }
150 
151 
152 template<>
153 tmp<Field<symmTensor>> transformFieldMask<symmTensor>
154 (
155  const symmTensorField& stf
156 )
157 {
158  return stf;
159 }
160 
161 template<>
162 tmp<Field<symmTensor>> transformFieldMask<symmTensor>
163 (
164  const tmp<symmTensorField>& tstf
165 )
166 {
167  return tstf;
168 }
169 
170 
171 // * * * * * * * * * * * * * * * global operators * * * * * * * * * * * * * //
172 
174 
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Foam
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #include "undefFieldFunctionsM.H"
186 
187 // ************************************************************************* //
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
#define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2)
Definition: FieldM.H:112
Pre-declare SubField and related Field type.
Definition: Field.H:83
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
Pre-declare related SubField type.
Definition: SubField.H:63
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:60
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
const Cmpt & x() const
Definition: VectorI.H:75
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
const tensorField & tf
Namespace for OpenFOAM.
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars.
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
SymmTensor< scalar > symmTensor
SymmTensor of scalars.
Definition: symmTensor.H:48
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a diagonal tensor.
Definition: DiagTensorI.H:353
void dev2(pointPatchField< tensor > &, const pointPatchField< tensor > &)
void tr(pointPatchField< scalar > &, const pointPatchField< tensor > &)
tmp< Field< symmTensor > > transformFieldMask< symmTensor >(const tensorField &tf)
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void inv(pointPatchField< tensor > &, const pointPatchField< tensor > &)
void dev(pointPatchField< tensor > &, const pointPatchField< tensor > &)
void symm(pointPatchField< tensor > &, const pointPatchField< tensor > &)
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
void hdual(pointPatchField< vector > &, const pointPatchField< tensor > &)
void det(pointPatchField< scalar > &, const pointPatchField< tensor > &)
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
void twoSymm(pointPatchField< tensor > &, const pointPatchField< tensor > &)
dimensionedSymmTensor innerSqr(const dimensionedSymmTensor &dt)
tmp< DimensionedField< scalar, GeoMesh, Field > > magSqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
void dot(GeometricField< typename innerProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
Spatial transformation functions for primitive fields.