coordinateScaling.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-2020 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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 :
33  coordSys_(nullptr),
34  scale_(),
35  active_(false)
36 {}
37 
38 
39 template<class Type>
41 (
42  const objectRegistry& obr,
43  const dictionary& dict
44 )
45 :
46  coordSys_
47  (
48  dict.found(coordinateSystem::typeName_())
50  : nullptr
51  ),
52  scale_(3),
53  active_(bool(coordSys_))
54 {
55  for (direction dir = 0; dir < vector::nComponents; ++dir)
56  {
57  const word key("scale" + Foam::name(dir+1));
58 
59  if (dict.found(key))
60  {
61  scale_.set(dir, Function1<Type>::New(key, dict));
62  active_ = true;
63  }
64  }
65 }
66 
67 
68 template<class Type>
70 :
71  coordSys_(rhs.coordSys_.clone()),
72  scale_(rhs.scale_),
73  active_(rhs.active_)
74 {}
75 
76 
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 
79 template<class Type>
81 (
82  const pointField& pos,
83  const Field<Type>& p0
84 ) const
85 {
86  auto tfld = tmp<Field<Type>>::New(p0);
87  auto& fld = tfld.ref();
88 
89  if (coordSys_)
90  {
91  const vectorField local(coordSys_->localPosition(pos));
92  for (direction dir = 0; dir < vector::nComponents; ++dir)
93  {
94  if (scale_.set(dir))
95  {
97  (
98  fld,
99  scale_[dir].value(local.component(dir))
100  );
101  }
102  }
103 
104  return coordSys_->transform(pos, fld);
105  }
106  else if (scale_.size())
107  {
108  for (direction dir = 0; dir < vector::nComponents; ++dir)
109  {
110  if (scale_.set(dir))
111  {
112  fld = cmptMultiply
113  (
114  fld,
115  scale_[dir].value(pos.component(dir))
116  );
117  }
118  }
119  }
120 
121  return tfld;
122 }
123 
124 
125 template<class Type>
127 {
128  if (coordSys_)
129  {
130  coordSys_->writeEntry(coordinateSystem::typeName_(), os);
131  }
132  forAll(scale_, dir)
133  {
134  if (scale_.set(dir))
135  {
136  scale_[dir].writeData(os);
137  }
138  }
139 }
140 
141 
142 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::coordinateScaling::transform
virtual tmp< Field< Type > > transform(const pointField &pos, const Field< Type > &local) const
Evaluate.
Definition: coordinateScaling.C:81
Foam::coordinateScaling
Helper class to wrap coordinate system and component-wise scaling.
Definition: coordinateScaling.H:55
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:86
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Field< vector >
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
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::coordinateScaling::coordinateScaling
coordinateScaling()
Default construct.
Definition: coordinateScaling.C:31
Foam::dimensioned::component
dimensioned< cmptType > component(const direction d) const
Return a component as a dimensioned<cmptType>
Definition: dimensionedType.C:450
bool
bool
Definition: EEqn.H:20
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::coordinateScaling::writeEntry
virtual void writeEntry(Ostream &os) const
Write dictionary entry.
Definition: coordinateScaling.C:126
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
p0
const volScalarField & p0
Definition: EEqn.H:36
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177