fieldCoordinateSystemTransform.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2017-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace functionObjects
37{
38 defineTypeNameAndDebug(fieldCoordinateSystemTransform, 0);
40 (
42 fieldCoordinateSystemTransform,
44 );
45}
46}
47
48
49// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50
51Foam::functionObjects::fieldCoordinateSystemTransform::
52fieldCoordinateSystemTransform
53(
54 const word& name,
55 const Time& runTime,
56 const dictionary& dict
57)
58:
59 fvMeshFunctionObject(name, runTime, dict),
60 fieldSet_(mesh_),
61 csysPtr_
62 (
63 coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_())
64 )
65{
66 read(dict);
67
68 Info<< type() << " " << name << ":" << nl
69 << " Applying " << (csysPtr_->uniform() ? "" : "non-")
70 << "uniform transformation from global Cartesian to local "
71 << *csysPtr_ << nl << endl;
72}
73
74
75// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76
78Foam::functionObjects::fieldCoordinateSystemTransform::transformFieldName
79(
80 const word& fieldName
81) const
82{
83 return IOobject::scopedName(fieldName, "Transformed");
84}
85
86
88Foam::functionObjects::fieldCoordinateSystemTransform::srotTensor() const
89{
90 typedef surfaceTensorField FieldType;
91 typedef surfaceTensorField::Boundary BoundaryType;
92
93 if (!rotTensorSurface_)
94 {
95 tensorField rotations(csysPtr_->R(mesh_.faceCentres()));
96
97 rotTensorSurface_.reset
98 (
99 new FieldType
100 (
101 IOobject
102 (
103 "surfRotation",
104 mesh_.objectRegistry::instance(),
105 mesh_.objectRegistry::db(),
108 false // no register
109 ),
110 mesh_,
111 dimless,
112 std::move(rotations)
113 // calculatedType
114 )
115 );
116
117 auto& rot = *rotTensorSurface_;
118
119 // Boundaries
120 BoundaryType& bf = const_cast<BoundaryType&>(rot.boundaryField());
121
122 forAll(bf, patchi)
123 {
124 bf[patchi] = csysPtr_->R(bf[patchi].patch().patch().faceCentres());
125 }
126 }
127
128 return *rotTensorSurface_;
129}
130
131
133Foam::functionObjects::fieldCoordinateSystemTransform::vrotTensor() const
134{
135 typedef volTensorField FieldType;
136 typedef volTensorField::Boundary BoundaryType;
137
138 if (!rotTensorVolume_)
139 {
140 tensorField rotations(csysPtr_->R(mesh_.cellCentres()));
141
142 rotTensorVolume_.reset
143 (
144 new FieldType
145 (
146 IOobject
147 (
148 "volRotation",
149 mesh_.objectRegistry::instance(),
150 mesh_.objectRegistry::db(),
153 false // no register
154 ),
155 mesh_,
156 dimless,
157 std::move(rotations)
158 // calculatedType
159 )
160 );
161
162 auto& rot = *rotTensorVolume_;
163
164 // Boundaries
165 BoundaryType& bf = const_cast<BoundaryType&>(rot.boundaryField());
166
167 forAll(bf, patchi)
168 {
169 bf[patchi] = csysPtr_->R(bf[patchi].patch().patch().faceCentres());
170 }
171 }
172
173 return *rotTensorVolume_;
174}
175
176
177bool Foam::functionObjects::fieldCoordinateSystemTransform::read
178(
179 const dictionary& dict
180)
181{
182 if (fvMeshFunctionObject::read(dict))
183 {
184 fieldSet_.read(dict);
185 return true;
186 }
187
188 return false;
189}
190
191
192bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
193{
194 fieldSet_.updateSelection();
195
196 for (const word& fieldName : fieldSet_.selectionNames())
197 {
198 transform<scalar>(fieldName);
199 transform<vector>(fieldName);
200 transform<sphericalTensor>(fieldName);
201 transform<symmTensor>(fieldName);
202 transform<tensor>(fieldName);
203 }
204
205 // Finished with these
206 rotTensorSurface_.clear();
207 rotTensorVolume_.clear();
208
209 return true;
210}
211
212
213bool Foam::functionObjects::fieldCoordinateSystemTransform::write()
214{
215 for (const word& fieldName : fieldSet_.selectionNames())
216 {
217 writeObject(transformFieldName(fieldName));
218 }
219
220 return true;
221}
222
223
224// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Generic GeometricField class.
GeometricBoundaryField< Type, PatchField, GeoMesh > Boundary
Type of boundary fields.
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
const std::string patch
OpenFOAM patch number as a std::string.
Namespace for OpenFOAM.
const dimensionSet dimless
Dimensionless.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
GeometricField< tensor, fvPatchField, volMesh > volTensorField
Definition: volFieldsFwd.H:87
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333