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-2019 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 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(fieldCoordinateSystemTransform, 0);
39 
41  (
42  functionObject,
43  fieldCoordinateSystemTransform,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
54 (
55  const word& name,
56  const Time& runTime,
57  const dictionary& dict
58 )
59 :
61  fieldSet_(mesh_),
62  csysPtr_
63  (
64  coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_())
65  )
66 {
67  read(dict);
68 
69  Info<< type() << " " << name << ":" << nl
70  << " Applying " << (csysPtr_->uniform() ? "" : "non-")
71  << "uniform transformation from global Cartesian to local "
72  << *csysPtr_ << nl << endl;
73 }
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
80 (
81  const word& fieldName
82 ) const
83 {
84  return fieldName + ":Transformed";
85 }
86 
87 
90 {
91  typedef surfaceTensorField FieldType;
92  typedef surfaceTensorField::Boundary BoundaryType;
93 
94  if (!rotTensorSurface_.valid())
95  {
96  tensorField rotations(csysPtr_->R(mesh_.faceCentres()));
97 
98  rotTensorSurface_.reset
99  (
100  new FieldType
101  (
102  IOobject
103  (
104  "surfRotation",
105  mesh_.objectRegistry::instance(),
106  mesh_.objectRegistry::db(),
109  false // no register
110  ),
111  mesh_,
112  dimless,
113  std::move(rotations)
114  // calculatedType
115  )
116  );
117 
118  auto& rot = *rotTensorSurface_;
119 
120  // Boundaries
121  BoundaryType& bf = const_cast<BoundaryType&>(rot.boundaryField());
122 
123  forAll(bf, patchi)
124  {
125  bf[patchi] = csysPtr_->R(bf[patchi].patch().patch().faceCentres());
126  }
127  }
128 
129  return *rotTensorSurface_;
130 }
131 
132 
135 {
136  typedef volTensorField FieldType;
137  typedef volTensorField::Boundary BoundaryType;
138 
139  if (!rotTensorVolume_.valid())
140  {
141  tensorField rotations(csysPtr_->R(mesh_.cellCentres()));
142 
143  rotTensorVolume_.reset
144  (
145  new FieldType
146  (
147  IOobject
148  (
149  "volRotation",
150  mesh_.objectRegistry::instance(),
151  mesh_.objectRegistry::db(),
154  false // no register
155  ),
156  mesh_,
157  dimless,
158  std::move(rotations)
159  // calculatedType
160  )
161  );
162 
163  auto& rot = *rotTensorVolume_;
164 
165  // Boundaries
166  BoundaryType& bf = const_cast<BoundaryType&>(rot.boundaryField());
167 
168  forAll(bf, patchi)
169  {
170  bf[patchi] = csysPtr_->R(bf[patchi].patch().patch().faceCentres());
171  }
172  }
173 
174  return *rotTensorVolume_;
175 }
176 
177 
179 (
180  const dictionary& dict
181 )
182 {
184  {
185  fieldSet_.read(dict);
186  return true;
187  }
188 
189  return false;
190 }
191 
192 
194 {
195  fieldSet_.updateSelection();
196 
197  for (const word& fieldName : fieldSet_.selectionNames())
198  {
199  transform<scalar>(fieldName);
200  transform<vector>(fieldName);
201  transform<sphericalTensor>(fieldName);
202  transform<symmTensor>(fieldName);
203  transform<tensor>(fieldName);
204  }
205 
206  // Finished with these
207  rotTensorSurface_.clear();
208  rotTensorVolume_.clear();
209 
210  return true;
211 }
212 
213 
215 {
216  for (const word& fieldName : fieldSet_.selectionNames())
217  {
218  writeObject(transformFieldName(fieldName));
219  }
220 
221  return true;
222 }
223 
224 
225 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
fieldCoordinateSystemTransform.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::fieldCoordinateSystemTransform::vrotTensor
const volTensorField & vrotTensor() const
Demand-driven non-uniform rotation field for volume fields.
Definition: fieldCoordinateSystemTransform.C:134
Foam::functionObjects::fieldCoordinateSystemTransform::csysPtr_
autoPtr< coordinateSystem > csysPtr_
Coordinate system to transform to.
Definition: fieldCoordinateSystemTransform.H:128
Foam::functionObjects::fieldCoordinateSystemTransform::rotTensorSurface_
autoPtr< surfaceTensorField > rotTensorSurface_
Demand-driven non-uniform rotation field (surface fields)
Definition: fieldCoordinateSystemTransform.H:132
Foam::functionObjects::fieldCoordinateSystemTransform::fieldCoordinateSystemTransform
fieldCoordinateSystemTransform(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: fieldCoordinateSystemTransform.C:54
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::functionObjects::fieldCoordinateSystemTransform::execute
virtual bool execute()
Calculate the transformed fields.
Definition: fieldCoordinateSystemTransform.C:193
Foam::functionObjects::fieldCoordinateSystemTransform::read
virtual bool read(const dictionary &)
Read the input data.
Definition: fieldCoordinateSystemTransform.C:179
Foam::Field< tensor >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
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::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
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::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Foam::functionObjects::fieldCoordinateSystemTransform::write
virtual bool write()
Write the transformed fields.
Definition: fieldCoordinateSystemTransform.C:214
Foam::GeometricField::Boundary
Definition: GeometricField.H:114
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::primitiveMesh::faceCentres
const vectorField & faceCentres() const
Definition: primitiveMeshFaceCentresAndAreas.C:145
Foam::functionObjects::fvMeshFunctionObject::mesh_
const fvMesh & mesh_
Reference to the fvMesh.
Definition: fvMeshFunctionObject.H:73
Foam::functionObjects::fieldCoordinateSystemTransform::srotTensor
const surfaceTensorField & srotTensor() const
Demand-driven non-uniform rotation field for surface fields.
Definition: fieldCoordinateSystemTransform.C:89
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::functionObjects::fieldCoordinateSystemTransform::transformFieldName
word transformFieldName(const word &fieldName) const
Return the name of the transformed field.
Definition: fieldCoordinateSystemTransform.C:80