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-2022 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_(coordinateSystem::NewIfPresent(obr, dict)),
47  scale_(label(vector::nComponents)),
48  active_(bool(coordSys_))
49 {
50  for (direction dir = 0; dir < vector::nComponents; ++dir)
51  {
52  const word key("scale" + Foam::name(dir+1));
53 
54  auto scaling = Function1<Type>::NewIfPresent(key, dict);
55 
56  if (scaling)
57  {
58  scale_.set(dir, std::move(scaling));
59  active_ = true;
60  }
61  }
62 }
63 
64 
65 template<class Type>
66 Foam::coordinateScaling<Type>::coordinateScaling(const coordinateScaling& rhs)
67 :
68  coordSys_(rhs.coordSys_.clone()),
69  scale_(rhs.scale_),
70  active_(rhs.active_)
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
76 template<class Type>
78 (
79  const pointField& globalPos
80 ) const
81 {
82  if (coordSys_)
83  {
84  return coordSys_->localPosition(globalPos);
85  }
86 
87  return globalPos;
88 }
89 
90 
91 template<class Type>
93 (
94  const pointField& pos,
95  const Field<Type>& p0
96 ) const
97 {
98  auto tfld = tmp<Field<Type>>::New(p0);
99  auto& fld = tfld.ref();
100 
101  if (coordSys_)
102  {
103  const vectorField local(coordSys_->localPosition(pos));
104  for (direction dir = 0; dir < vector::nComponents; ++dir)
105  {
106  if (scale_.set(dir))
107  {
108  fld = cmptMultiply
109  (
110  fld,
111  scale_[dir].value(local.component(dir))
112  );
113  }
114  }
115 
116  return coordSys_->transform(pos, fld);
117  }
118  else if (scale_.size())
119  {
120  for (direction dir = 0; dir < vector::nComponents; ++dir)
121  {
122  if (scale_.set(dir))
123  {
124  fld = cmptMultiply
125  (
126  fld,
127  scale_[dir].value(pos.component(dir))
128  );
129  }
130  }
131  }
132 
133  return tfld;
134 }
135 
136 
137 template<class Type>
139 {
140  if (coordSys_)
141  {
142  coordSys_->writeEntry(os);
143  }
144  forAll(scale_, dir)
145  {
146  if (scale_.set(dir))
147  {
148  scale_[dir].writeData(os);
149  }
150  }
151 }
152 
153 
154 // ************************************************************************* //
Base class for coordinate system specification, the default coordinate system type is cartesian ...
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
dimensioned< cmptType > component(const direction d) const
Return a component as a dimensioned<cmptType>
dictionary dict
uint8_t direction
Definition: direction.H:46
tmp< pointField > localPosition(const pointField &globalPos) const
Convert to local coordinates, pass-through if no coordinate system is active.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
dimensionedScalar pos(const dimensionedScalar &ds)
coordinateScaling()
Default construct.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool local
Definition: EEqn.H:20
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
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))
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
virtual tmp< Field< Type > > transform(const pointField &pos, const Field< Type > &local) const
Evaluate.
virtual void writeEntry(Ostream &os) const
Write dictionary entry.
const volScalarField & p0
Definition: EEqn.H:36