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 -------------------------------------------------------------------------------
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);
40  (
41  functionObject,
42  fieldCoordinateSystemTransform,
43  dictionary
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::functionObjects::fieldCoordinateSystemTransform::
52 fieldCoordinateSystemTransform
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 
78 Foam::functionObjects::fieldCoordinateSystemTransform::transformFieldName
79 (
80  const word& fieldName
81 ) const
82 {
83  return IOobject::scopedName(fieldName, "Transformed");
84 }
85 
86 
88 Foam::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 
133 Foam::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 
178 (
179  const dictionary& dict
180 )
181 {
183  {
184  fieldSet_.read(dict);
185  return true;
186  }
187 
188  return false;
189 }
190 
191 
192 bool 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 
214 {
215  for (const word& fieldName : fieldSet_.selectionNames())
216  {
217  writeObject(transformFieldName(fieldName));
218  }
219 
220  return true;
221 }
222 
223 
224 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::volTensorField
GeometricField< tensor, fvPatchField, volMesh > volTensorField
Definition: volFieldsFwd.H:66
fieldCoordinateSystemTransform.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::surfaceTensorField
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
Definition: surfaceFieldsFwd.H:64
Foam::tensorField
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
Definition: primitiveFieldsFwd.H:57
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::functionObjects::fieldAverage::read
virtual bool read(const dictionary &)
Read the field average data.
Definition: fieldAverage.C:294
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
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::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::IOobject::scopedName
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189