tensorField.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-2018 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 "tensorField.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 
39 UNARY_FUNCTION(scalar, tensor, tr)
46 UNARY_FUNCTION(scalar, tensor, det)
48 
49 void inv(Field<tensor>& tf, const UList<tensor>& tf1)
50 {
51  if (tf.empty())
52  {
53  return;
54  }
55 
56  scalar scale = magSqr(tf1[0]);
57  Vector<bool> removeCmpts
58  (
59  magSqr(tf1[0].xx())/scale < small,
60  magSqr(tf1[0].yy())/scale < small,
61  magSqr(tf1[0].zz())/scale < small
62  );
63 
64  if (removeCmpts.x() || removeCmpts.y() || removeCmpts.z())
65  {
66  tensorField tf1Plus(tf1);
67 
68  if (removeCmpts.x())
69  {
70  tf1Plus += tensor(1,0,0,0,0,0,0,0,0);
71  }
72 
73  if (removeCmpts.y())
74  {
75  tf1Plus += tensor(0,0,0,0,1,0,0,0,0);
76  }
77 
78  if (removeCmpts.z())
79  {
80  tf1Plus += tensor(0,0,0,0,0,0,0,0,1);
81  }
82 
83  TFOR_ALL_F_OP_FUNC_F(tensor, tf, =, inv, tensor, tf1Plus)
84 
85  if (removeCmpts.x())
86  {
87  tf -= tensor(1,0,0,0,0,0,0,0,0);
88  }
89 
90  if (removeCmpts.y())
91  {
92  tf -= tensor(0,0,0,0,1,0,0,0,0);
93  }
94 
95  if (removeCmpts.z())
96  {
97  tf -= tensor(0,0,0,0,0,0,0,0,1);
98  }
99  }
100  else
101  {
102  TFOR_ALL_F_OP_FUNC_F(tensor, tf, =, inv, tensor, tf1)
103  }
104 }
105 
107 {
108  tmp<tensorField> result(new tensorField(tf.size()));
109  inv(result.ref(), tf);
110  return result;
111 }
112 
114 {
115  tmp<tensorField> tRes = New(tf);
116  inv(tRes.ref(), tf());
117  tf.clear();
118  return tRes;
119 }
120 
123 
126 
127 
128 template<>
130 (
131  const symmTensorField& stf
132 )
133 {
134  tmp<tensorField> tRes(new tensorField(stf.size()));
135  tensorField& res = tRes.ref();
136  TFOR_ALL_F_OP_F(tensor, res, =, symmTensor, stf)
137  return tRes;
138 }
139 
140 template<>
142 (
143  const tmp<symmTensorField>& tstf
144 )
145 {
147  tstf.clear();
148  return ret;
149 }
150 
151 
152 // * * * * * * * * * * * * * * * global operators * * * * * * * * * * * * * //
153 
156 
159 
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 } // End namespace Foam
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 #include "undefFieldFunctionsM.H"
168 
169 // ************************************************************************* //
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:237
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
dimensionedTensor skew(const dimensionedTensor &dt)
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
dimensionedVector eigenValues(const dimensionedTensor &dt)
const Cmpt & z() const
Definition: VectorI.H:87
dimensionedScalar det(const dimensionedSphericalTensor &dt)
#define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2)
Definition: FieldM.H:112
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a diagonal tensor.
Definition: DiagTensorI.H:288
const tensorField & tf
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
const Cmpt & y() const
Definition: VectorI.H:81
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Spatial transformation functions for primitive fields.
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
Pre-declare SubField and related Field type.
Definition: Field.H:56
SymmTensor< scalar > symmTensor
SymmTensor of scalars.
Definition: symmTensor.H:48
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
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:60
const Cmpt & x() const
Definition: VectorI.H:75
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:57
dimensioned< scalar > magSqr(const dimensioned< Type > &)
dimensionedTensor eigenVectors(const dimensionedTensor &dt)
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
tmp< Field< tensor > > transformFieldMask< tensor >(const symmTensorField &)
Definition: tensorField.C:130
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars.
#define TFOR_ALL_F_OP_F(typeF1, f1, OP, typeF2, f2)
Definition: FieldM.H:312
A class for managing temporary objects.
Definition: PtrList.H:53
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
dimensionedSymmTensor cof(const dimensionedSymmTensor &dt)
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
Namespace for OpenFOAM.