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-------------------------------------------------------------------------------
11License
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
38namespace Foam
39{
40
41// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
42
43UNARY_FUNCTION(scalar, tensor, tr)
52
53void 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 {
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
129template<>
130tmp<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
141template<>
142tmp<Field<tensor>> transformFieldMask<tensor>
143(
144 const tmp<symmTensorField>& tstf
145)
146{
147 tmp<Field<tensor>> ret = transformFieldMask<tensor>(tstf());
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// ************************************************************************* //
#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:116
#define TFOR_ALL_F_OP_F(typeF1, f1, OP, typeF2, f2)
Definition: FieldM.H:324
Generic templated field type.
Definition: Field.H:82
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
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:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:65
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Tensor of scalars, i.e. Tensor<scalar>.
A class for managing temporary objects.
Definition: tmp.H:65
void clear() const noexcept
Definition: tmpI.H:287
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Namespace for OpenFOAM.
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
dimensionedScalar det(const dimensionedSphericalTensor &dt)
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
dimensionedTensor eigenVectors(const dimensionedSymmTensor &dt)
dimensionedVector eigenValues(const dimensionedSymmTensor &dt)
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:59
Tensor< scalar > tensor
Definition: symmTensor.H:61
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
void hdual(pointPatchField< vector > &, const pointPatchField< tensor > &)
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a DiagTensor as a SphericalTensor.
Definition: DiagTensorI.H:130
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
tmp< Field< tensor > > transformFieldMask< tensor >(const symmTensorField &)
Definition: tensorField.C:131
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dimensionedTensor skew(const dimensionedTensor &dt)
Spatial transformation functions for primitive fields.