Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
30template<class Type>
32:
33 coordSys_(nullptr),
34 scale_(),
35 active_(false)
36{}
37
38
39template<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, &obr);
55
56 if (scaling)
57 {
58 scale_.set(dir, std::move(scaling));
59 active_ = true;
60 }
61 }
62}
63
64
65template<class Type>
67:
68 coordSys_(rhs.coordSys_.clone()),
69 scale_(rhs.scale_),
70 active_(rhs.active_)
71{}
72
73
74// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75
76template<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
91template<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 {
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 {
125 (
126 fld,
127 scale_[dir].value(pos.component(dir))
128 );
129 }
132
133 return tfld;
134}
135
136
137template<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// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
static autoPtr< Function1< Type > > NewIfPresent(const word &entryName, const dictionary &dict, const word &redirectType, const objectRegistry *obrPtr=nullptr)
An optional selector, with fallback redirection.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
static constexpr direction nComponents
Number of components in this vector space.
Helper class to wrap coordinate system and component-wise scaling.
virtual tmp< Field< Type > > transform(const pointField &pos, const Field< Type > &local) const
Evaluate.
tmp< pointField > localPosition(const pointField &globalPos) const
Convert to local coordinates, pass-through if no coordinate system is active.
coordinateScaling()
Default construct.
virtual void writeEntry(Ostream &os) const
Write dictionary entry.
Base class for coordinate system specification, the default coordinate system type is cartesian .
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Registry of regIOobjects.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
bool local
Definition EEqn.H:20
const volScalarField & p0
Definition EEqn.H:36
OBJstream os(runTime.globalPath()/outputName)
dimensionedScalar pos(const dimensionedScalar &ds)
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.
Field< vector > vectorField
Specialisation of Field<T> for vector.
uint8_t direction
Definition direction.H:49
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299