coordinateSystemTemplates.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) 2018 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "coordinateSystem.H"
29 #include "transform.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
33 template<class PointField>
35 Foam::coordinateSystem::rotationsImpl(const PointField& global) const
36 {
37  const label len = global.size();
38 
39  auto tresult = tmp<tensorField>::New(len);
40  auto& result = tresult.ref();
41 
42  for (label i=0; i<len; ++i)
43  {
44  result[i] = this->R(global[i]);
45  }
46 
47  return tresult;
48 }
49 
50 
51 template<class PointField>
53 Foam::coordinateSystem::transformPointImpl(const PointField& localCart) const
54 {
55  const label len = localCart.size();
56 
57  auto tresult = tmp<pointField>::New(len);
58  auto& result = tresult.ref();
59 
60  for (label i=0; i<len; ++i)
61  {
62  result[i] = Foam::transform(rot_, localCart[i]) + origin_;
63  }
64 
65  return tresult;
66 }
67 
68 
69 template<class PointField>
71 Foam::coordinateSystem::invTransformPointImpl(const PointField& global) const
72 {
73  const label len = global.size();
74 
75  auto tresult = tmp<pointField>::New(len);
76  auto& result = tresult.ref();
77 
78  for (label i=0; i<len; ++i)
79  {
80  result[i] = Foam::invTransform(rot_, global[i] - origin_);
81  }
82 
83  return tresult;
84 }
85 
86 
87 template<class RetType, class Type, class BinaryOp>
90 (
91  const tensor& tt,
92  const UList<Type>& input,
93  const BinaryOp& bop
94 )
95 {
96  const label len = input.size();
97 
98  auto tresult = tmp<Field<RetType>>::New(len);
99  auto& result = tresult.ref();
100 
101  for (label i=0; i<len; ++i)
102  {
103  result[i] = bop(tt, input[i]);
104  }
105 
106  return tresult;
107 }
108 
109 
110 template<class RetType, class PointField, class Type, class BinaryOp>
113 (
114  const PointField& global,
115  const UList<Type>& input,
116  const BinaryOp& bop
117 ) const
118 {
119  const label len = input.size();
120 
121  if (len != global.size())
122  {
124  << "positions has different size from input field"
125  << abort(FatalError);
126  }
127 
128  auto tresult = tmp<Field<RetType>>::New(len);
129  auto& result = tresult.ref();
130 
131  for (label i=0; i<len; ++i)
132  {
133  result[i] = bop(this->R(global[i]), input[i]);
134  }
135 
136  return tresult;
137 }
138 
139 
140 template<class RetType, class PointField, class Type, class BinaryOp>
143 (
144  const PointField& global,
145  const Type& input,
146  const BinaryOp& bop
147 ) const
148 {
149  const label len = global.size();
150 
151  auto tresult = tmp<Field<RetType>>::New(len);
152  auto& result = tresult.ref();
153 
154  for (label i=0; i<len; ++i)
155  {
156  result[i] = bop(this->R(global[i]), input);
157  }
158 
159  return tresult;
160 }
161 
162 
163 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::coordinateSystem::invTransformPointImpl
tmp< pointField > invTransformPointImpl(const PointField &global) const
Implementation for transformPosition() methods.
Foam::coordinateSystem::oneToOneImpl
tmp< Field< RetType > > oneToOneImpl(const PointField &global, const UList< Type > &input, const BinaryOp &bop) const
Use position-dependent transform tensors for multiple inputs.
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
coordinateSystem.H
R
#define R(A, B, C, D, E, F, K, M)
Foam::coordinateSystem::transformPointImpl
tmp< pointField > transformPointImpl(const PointField &localCart) const
Implementation for transformPoint() methods.
Foam::coordinateSystem::manyTimesImpl
static tmp< Field< RetType > > manyTimesImpl(const tensor &tt, const UList< Type > &input, const BinaryOp &bop)
Apply single transform tensor for multiple inputs.
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::coordinateSystem::oneToManyImpl
tmp< Field< RetType > > oneToManyImpl(const PointField &global, const Type &input, const BinaryOp &bop) const
Use position-dependent transform tensors for single input.
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
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::UList< Type >
Foam::invTransform
dimensionSet invTransform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:527
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
Foam::coordinateSystem::rotationsImpl
tmp< tensorField > rotationsImpl(const PointField &global) const
Implementation for R() methods.
transform.H
3D tensor transformation operations.
Foam::coordinateSystem::R
virtual const tensor & R() const
Return const reference to the rotation tensor.
Definition: coordinateSystem.H:475