Loading...
Searching...
No Matches
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-2023 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
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 (
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::Boundary BoundaryType;
91
92 if (!rotTensorSurface_)
93 {
94 tensorField rotations(csysPtr_->R(mesh_.faceCentres()));
95
96 rotTensorSurface_.emplace
97 (
99 (
100 "surfRotation",
101 mesh_.objectRegistry::instance(),
102 mesh_.objectRegistry::db(),
106 ),
107 mesh_,
108 dimless,
109 std::move(rotations)
110 // calculatedType
111 );
112
113 auto& rot = *rotTensorSurface_;
114
115 // Boundaries
116 BoundaryType& bf = const_cast<BoundaryType&>(rot.boundaryField());
117
118 forAll(bf, patchi)
119 {
120 bf[patchi] = csysPtr_->R(bf[patchi].patch().patch().faceCentres());
121 }
122 }
123
124 return *rotTensorSurface_;
125}
126
127
129Foam::functionObjects::fieldCoordinateSystemTransform::vrotTensor() const
130{
131 typedef volTensorField::Boundary BoundaryType;
132
133 if (!rotTensorVolume_)
134 {
135 tensorField rotations(csysPtr_->R(mesh_.cellCentres()));
136
137 rotTensorVolume_.emplace
138 (
140 (
141 "volRotation",
142 mesh_.objectRegistry::instance(),
143 mesh_.objectRegistry::db(),
147 ),
148 mesh_,
149 dimless,
150 std::move(rotations)
151 // calculatedType
152 );
153
154 auto& rot = *rotTensorVolume_;
155
156 // Boundaries
157 BoundaryType& bf = const_cast<BoundaryType&>(rot.boundaryField());
158
159 forAll(bf, patchi)
160 {
161 bf[patchi] = csysPtr_->R(bf[patchi].patch().patch().faceCentres());
162 }
163 }
164
165 return *rotTensorVolume_;
166}
167
168
169bool Foam::functionObjects::fieldCoordinateSystemTransform::read
170(
171 const dictionary& dict
172)
173{
174 if (fvMeshFunctionObject::read(dict))
175 {
176 fieldSet_.read(dict);
177 return true;
178 }
179
180 return false;
181}
182
183
184bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
185{
186 fieldSet_.updateSelection();
187
188 for (const word& fieldName : fieldSet_.selectionNames())
189 {
190 transform<scalar>(fieldName);
191 transform<vector>(fieldName);
193 transform<symmTensor>(fieldName);
194 transform<tensor>(fieldName);
195 }
196
197 // Finished with these
198 rotTensorSurface_.clear();
199 rotTensorVolume_.clear();
200
201 return true;
202}
203
204
205bool Foam::functionObjects::fieldCoordinateSystemTransform::write()
206{
207 for (const word& fieldName : fieldSet_.selectionNames())
208 {
209 writeObject(transformFieldName(fieldName));
210 }
211
212 return true;
213}
214
215
216// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
GeometricBoundaryField< tensor, fvsPatchField, surfaceMesh > Boundary
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition IOobjectI.H:50
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
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
Abstract base-class for Time/database function objects.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
engineTime & runTime
auto & name
const std::string patch
OpenFOAM patch number as a std::string.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
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.
const dimensionSet dimless
Dimensionless.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
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 POSIX.C:801
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
GeometricField< tensor, fvPatchField, volMesh > volTensorField
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 expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299