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-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 "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  scalar scale = magSqr(tf1[0]);
61  Vector<bool> removeCmpts
62  (
63  magSqr(tf1[0].xx())/scale < SMALL,
64  magSqr(tf1[0].yy())/scale < SMALL,
65  magSqr(tf1[0].zz())/scale < SMALL
66  );
67 
68  if (removeCmpts.x() || removeCmpts.y() || removeCmpts.z())
69  {
70  tensorField tf1Plus(tf1);
71 
72  if (removeCmpts.x())
73  {
74  tf1Plus += tensor(1,0,0,0,0,0,0,0,0);
75  }
76 
77  if (removeCmpts.y())
78  {
79  tf1Plus += tensor(0,0,0,0,1,0,0,0,0);
80  }
81 
82  if (removeCmpts.z())
83  {
84  tf1Plus += tensor(0,0,0,0,0,0,0,0,1);
85  }
86 
87  TFOR_ALL_F_OP_FUNC_F(tensor, tf, =, inv, tensor, tf1Plus)
88 
89  if (removeCmpts.x())
90  {
91  tf -= tensor(1,0,0,0,0,0,0,0,0);
92  }
93 
94  if (removeCmpts.y())
95  {
96  tf -= tensor(0,0,0,0,1,0,0,0,0);
97  }
98 
99  if (removeCmpts.z())
100  {
101  tf -= tensor(0,0,0,0,0,0,0,0,1);
102  }
103  }
104  else
105  {
106  TFOR_ALL_F_OP_FUNC_F(tensor, tf, =, inv, tensor, tf1)
107  }
108 }
109 
111 {
112  auto tres = tmp<tensorField>::New(tf.size());
113  inv(tres.ref(), tf);
114  return tres;
115 }
116 
118 {
119  auto tres = New(tf);
120  inv(tres.ref(), tf());
121  tf.clear();
122  return tres;
123 }
124 
127 
128 
129 template<>
130 tmp<Field<tensor>> transformFieldMask<tensor>
131 (
132  const symmTensorField& stf
133 )
134 {
135  auto tres = tmp<tensorField>::New(stf.size());
136  auto& res = tres.ref();
137  TFOR_ALL_F_OP_F(tensor, res, =, symmTensor, stf)
138  return tres;
139 }
140 
141 template<>
142 tmp<Field<tensor>> transformFieldMask<tensor>
143 (
144  const tmp<symmTensorField>& tstf
145 )
146 {
148  tstf.clear();
149  return ret;
150 }
151 
152 
153 // * * * * * * * * * * * * * * * global operators * * * * * * * * * * * * * //
154 
157 
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #include "undefFieldFunctionsM.H"
169 
170 // ************************************************************************* //
BINARY_OPERATOR
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Definition: DimensionedFieldFunctionsM.C:412
Foam::Tensor
A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
Definition: complexI.H:275
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::symm
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:84
Foam::sphericalTensor
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
Definition: sphericalTensor.H:54
Foam::SymmTensor< scalar >
UNARY_FUNCTION
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
Definition: DimensionedFieldFunctionsM.C:33
Foam::tmp::clear
void clear() const noexcept
Definition: tmpI.H:287
Foam::skew
dimensionedTensor skew(const dimensionedTensor &dt)
Definition: dimensionedTensor.C:138
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::eigenValues
dimensionedVector eigenValues(const dimensionedSymmTensor &dt)
Definition: dimensionedTensor.C:149
TFOR_ALL_F_OP_F
#define TFOR_ALL_F_OP_F(typeF1, f1, OP, typeF2, f2)
Definition: FieldM.H:324
Foam::eigenVectors
dimensionedTensor eigenVectors(const dimensionedSymmTensor &dt)
Definition: dimensionedTensor.C:160
BINARY_TYPE_OPERATOR
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
Definition: DimensionedFieldFunctionsM.C:674
undefFieldFunctionsM.H
Foam::dev2
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:117
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
transformField.H
Spatial transformation functions for primitive fields.
TFOR_ALL_F_OP_FUNC_F
#define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2)
Definition: FieldM.H:116
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::divide
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
Foam::transformFieldMask< tensor >
tmp< Field< tensor > > transformFieldMask< tensor >(const symmTensorField &)
Definition: tensorField.C:131
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::symmTensor
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:59
Foam::sph
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:130
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::cof
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:139
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
tensorField.H
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
UNARY_OPERATOR
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
Definition: DimensionedFieldFunctionsM.C:87
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
Foam::UList
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:103
FieldFunctionsM.C
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::tr
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:51
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:62
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::hdual
void hdual(pointPatchField< vector > &, const pointPatchField< tensor > &)
Definition: pointPatchFieldFunctions.H:273
Foam::twoSymm
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:95
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars, i.e. Tensor<scalar>.
Definition: symmTensor.H:61
Foam::dev
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:106