transformer.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-2020 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 "transformer.H"
27 #include "IOstreams.H"
28 #include "OStringStream.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 const char* const Foam::transformer::typeName =
33  "transformer";
34 
36 (
37  Zero,
38  false,
39  Zero,
40  false,
41  false
42 );
43 
45 (
46  Zero,
47  false,
48  tensor::I,
49  false,
50  false
51 );
52 
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
59 {
60  is >> *this;
61 }
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
67 {
68  OStringStream buf;
69 
70  buf << '(' << s.t() << ',' << s.T() << ')';
71 
72  return buf.str();
73 }
74 
75 
77 (
78  pointField& res,
79  const pointField& pts
80 ) const
81 {
82  if (translates_ && !transforms())
83  {
84  res = pts + t();
85  }
86  else if (!translates_ && transforms())
87  {
88  res = T() & pts;
89  }
90  else if (translates_ && transforms())
91  {
92  res = (T() & pts) + t();
93  }
94 }
95 
96 
98 (
99  const pointField& pts
100 ) const
101 {
102  if (translates_ && !transforms())
103  {
104  return pts + t();
105  }
106  else if (!translates_ && transforms())
107  {
108  return T() & pts;
109  }
110  else if (translates_ && transforms())
111  {
112  return (T() & pts) + t();
113  }
114  else
115  {
116  return pts;
117  }
118 }
119 
120 
122 (
123  const pointField& pts
124 ) const
125 {
126  if (translates_ && !transforms())
127  {
128  return pts - t();
129  }
130  else if (!translates_ && transforms())
131  {
132  return T().T() & pts;
133  }
134  else if (translates_ && transforms())
135  {
136  return (T().T() & (pts - t()));
137  }
138  else
139  {
140  return pts;
141  }
142 }
143 
144 
146 (
147  pointField& res,
148  const pointField& pts
149 ) const
150 {
151  if (translates_ && !transforms())
152  {
153  res = pts - t();
154  }
155  else if (!translates_ && transforms())
156  {
157  res = T().T() & pts;
158  }
159  else if (translates_ && transforms())
160  {
161  res = (T().T() & (pts - t()));
162  }
163 }
164 
165 
166 template<>
168 (
169  const Field<bool>& fld
170 ) const
171 {
172  return fld;
173 }
174 
175 
176 template<>
178 (
179  const tmp<Field<bool>>& tfld
180 ) const
181 {
182  return tfld;
183 }
184 
185 
186 template<>
188 (
189  const Field<label>& fld
190 ) const
191 {
192  return fld;
193 }
194 
195 
196 template<>
198 (
199  const tmp<Field<label>>& tfld
200 ) const
201 {
202  return tfld;
203 }
204 
205 
206 template<>
208 (
209  const Field<scalar>& fld
210 ) const
211 {
212  return fld;
213 }
214 
215 
216 template<>
218 (
219  const tmp<Field<scalar>>& tfld
220 ) const
221 {
222  return tfld;
223 }
224 
225 
226 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
227 
229 {
230  // Read beginning of transformer
231  is.readBegin("transformer");
232 
233  is >> tr.translates_ >> tr.t_ >> tr.scales_ >> tr.rotates_ >> tr.T_;
234 
235  // Read end of transformer
236  is.readEnd("transformer");
237 
238  // Check state of Istream
239  is.check("operator>>(Istream&, transformer&)");
240 
241  return is;
242 }
243 
244 
246 {
247  os << token::BEGIN_LIST
248  << tr.translates_ << token::SPACE << tr.t_ << token::SPACE
249  << tr.scales_ << token::SPACE << tr.rotates_ << token::SPACE << tr.T_
250  << token::END_LIST;
251 
252  return os;
253 }
254 
255 
256 // ************************************************************************* //
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
Vector-tensor class used to perform translations and rotations in 3D space.
Definition: transformer.H:83
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
bool transforms() const
Return true if the transformer transforms a type.
Definition: transformerI.H:133
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Tensor< Cmpt > T() const
Return transpose.
Definition: TensorI.H:331
static const transformer null
Null transformer.
Definition: transformer.H:128
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
const vector & t() const
Return the translation vector.
Definition: transformerI.H:82
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
vector invTransformPosition(const vector &v) const
Inverse transform the given position.
Definition: transformerI.H:177
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static const Identity< scalar > I
Definition: Identity.H:93
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
static const zero Zero
Definition: zero.H:97
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
static const transformer I
Definition: transformer.H:125
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const tensor & T() const
Return the transformation tensor.
Definition: transformerI.H:94
static const char *const typeName
Definition: transformer.H:121
transformer()
Construct null (i.e., no transformation)
Definition: transformerI.H:70
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Ostream & operator<<(Ostream &, const ensightPart &)
string str() const
Return the string.
static const transformer zero
Definition: transformer.H:123
Type transform(const Type &) const
Transform the given type.
vector transformPosition(const vector &v) const
Transform the given position.
Definition: transformerI.H:153
A class for managing temporary objects.
Definition: PtrList.H:53
Output to memory buffer stream.
Definition: OStringStream.H:49