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 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 :
34  active_(false)
35 {}
36 
37 
38 template<class Type>
40 (
41  const objectRegistry& obr,
42  const dictionary& dict
43 )
44 :
45  coordSys_
46  (
47  dict.found(coordinateSystem::typeName_())
49  : nullptr
50  ),
51  scale_(3),
52  active_(coordSys_.valid())
53 {
54  for (direction dir = 0; dir < vector::nComponents; dir++)
55  {
56  const word key("scale" + Foam::name(dir+1));
57 
58  if (dict.found(key))
59  {
60  scale_.set(dir, Function1<Type>::New(key, dict));
61  active_ = true;
62  }
63  }
64 }
65 
66 
67 template<class Type>
69 :
70  coordSys_(cs.coordSys_.clone()),
71  scale_(cs.scale_),
72  active_(cs.active_)
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
77 
78 template<class Type>
80 {}
81 
82 
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 
85 template<class Type>
87 (
88  const pointField& pos,
89  const Field<Type>& p0
90 ) const
91 {
92  tmp<Field<Type>> tfld(new Field<Type>(p0));
93  Field<Type>& fld = tfld.ref();
94 
95  if (coordSys_.valid())
96  {
97  const vectorField local(coordSys_->localPosition(pos));
98  for (direction dir = 0; dir < vector::nComponents; dir++)
99  {
100  if (scale_.set(dir))
101  {
102  fld = cmptMultiply
103  (
104  fld,
105  scale_[dir].value(local.component(dir))
106  );
107  }
108  }
109 
110  return coordSys_->transform(pos, fld);
111  }
112  else
113  {
114  for (direction dir = 0; dir < vector::nComponents; dir++)
115  {
116  if (scale_.set(dir))
117  {
118  fld = cmptMultiply
119  (
120  fld,
121  scale_[dir].value(pos.component(dir))
122  );
123  }
124  }
125  return fld;
126  }
127 }
128 
129 
130 template<class Type>
132 {
133  if (coordSys_.valid())
134  {
135  coordSys_->writeEntry(coordinateSystem::typeName_(), os);
136  }
137  forAll(scale_, dir)
138  {
139  if (scale_.set(dir))
140  {
141  scale_[dir].writeData(os);
142  }
143  }
144 }
145 
146 
147 // ************************************************************************* //
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:59
Foam::coordinateScaling::transform
virtual tmp< Field< Type > > transform(const pointField &pos, const Field< Type > &local) const
Evaluate.
Definition: coordinateScaling.C:87
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:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
Foam::Field< vector >
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::coordinateScaling::~coordinateScaling
virtual ~coordinateScaling()
Destructor.
Definition: coordinateScaling.C:79
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()
Construct null.
Definition: coordinateScaling.C:32
Foam::dimensioned::component
dimensioned< cmptType > component(const direction d) const
Return a component as a dimensioned<cmptType>
Definition: dimensionedType.C:420
Foam::direction
uint8_t direction
Definition: direction.H:47
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::coordinateScaling::writeEntry
virtual void writeEntry(Ostream &) const
Write dictionary entry.
Definition: coordinateScaling.C:131
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177