solidBodyMotionFvMesh.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 | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "solidBodyMotionFvMesh.H"
28 #include "volFields.H"
29 #include "transformField.H"
30 #include "cellZoneMesh.H"
31 #include "cellSet.H"
32 #include "boolList.H"
33 #include "syncTools.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(solidBodyMotionFvMesh, 0);
40  addToRunTimeSelectionTable(dynamicFvMesh, solidBodyMotionFvMesh, IOobject);
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 Foam::solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject& io)
47 :
48  dynamicFvMesh(io),
49  dynamicMeshCoeffs_
50  (
52  (
53  IOobject
54  (
55  "dynamicMeshDict",
56  io.time().constant(),
57  *this,
58  IOobject::MUST_READ_IF_MODIFIED,
59  IOobject::NO_WRITE,
60  false
61  )
62  ).subDict(typeName + "Coeffs")
63  ),
64  SBMFPtr_(solidBodyMotionFunction::New(dynamicMeshCoeffs_, io.time())),
65  undisplacedPoints_
66  (
67  IOobject
68  (
69  "points",
70  io.time().constant(),
71  meshSubDir,
72  *this,
73  IOobject::MUST_READ,
74  IOobject::NO_WRITE,
75  false
76  )
77  ),
78  pointIDs_(),
79  moveAllCells_(false),
80  UName_(dynamicMeshCoeffs_.lookupOrDefault<word>("U", "U"))
81 {
82  if (undisplacedPoints_.size() != nPoints())
83  {
84  FatalIOErrorInFunction(dynamicMeshCoeffs_)
85  << "Read " << undisplacedPoints_.size()
86  << " undisplaced points from " << undisplacedPoints_.objectPath()
87  << " but the current mesh has " << nPoints()
88  << exit(FatalIOError);
89  }
90 
91  word cellZoneName =
92  dynamicMeshCoeffs_.lookupOrDefault<word>("cellZone", "none");
93 
94  word cellSetName =
95  dynamicMeshCoeffs_.lookupOrDefault<word>("cellSet", "none");
96 
97  if ((cellZoneName != "none") && (cellSetName != "none"))
98  {
99  FatalIOErrorInFunction(dynamicMeshCoeffs_)
100  << "Either cellZone OR cellSet can be supplied, but not both. "
101  << "If neither is supplied, all cells will be included"
102  << exit(FatalIOError);
103  }
104 
105 
106  labelList cellIDs;
107  if (cellZoneName != "none")
108  {
109  Info<< "Applying solid body motion to cellZone " << cellZoneName
110  << endl;
111 
112  label zoneID = cellZones().findZoneID(cellZoneName);
113 
114  if (zoneID == -1)
115  {
117  << "Unable to find cellZone " << cellZoneName
118  << ". Valid cellZones are:"
119  << cellZones().names()
120  << exit(FatalError);
121  }
122 
123  cellIDs = cellZones()[zoneID];
124  }
125 
126  if (cellSetName != "none")
127  {
128  Info<< "Applying solid body motion to cellSet " << cellSetName
129  << endl;
130 
131  cellSet set(*this, cellSetName);
132 
133  cellIDs = set.toc();
134  }
135 
136  label nCells = returnReduce(cellIDs.size(), sumOp<label>());
137  moveAllCells_ = nCells == 0;
138 
139  if (moveAllCells_)
140  {
141  Info<< "Applying solid body motion to entire mesh" << endl;
142  }
143  else
144  {
145  // collect point IDs of points in cell zone
146 
147  boolList movePts(nPoints(), false);
148 
149  forAll(cellIDs, i)
150  {
151  label celli = cellIDs[i];
152  const cell& c = cells()[celli];
153  forAll(c, j)
154  {
155  const face& f = faces()[c[j]];
156  forAll(f, k)
157  {
158  label pointi = f[k];
159  movePts[pointi] = true;
160  }
161  }
162  }
163 
164  syncTools::syncPointList(*this, movePts, orEqOp<bool>(), false);
165 
166  DynamicList<label> ptIDs(nPoints());
167  forAll(movePts, i)
168  {
169  if (movePts[i])
170  {
171  ptIDs.append(i);
172  }
173  }
174 
175  pointIDs_.transfer(ptIDs);
176  }
177 }
178 
179 
180 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
181 
183 {}
184 
185 
186 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
187 
189 {
190  static bool hasWarned = false;
191 
192  if (moveAllCells_)
193  {
195  (
197  (
198  SBMFPtr_().transformation(),
199  undisplacedPoints_
200  )
201  );
202  }
203  else
204  {
205  pointField transformedPts(undisplacedPoints_);
206 
207  UIndirectList<point>(transformedPts, pointIDs_) =
209  (
210  SBMFPtr_().transformation(),
211  pointField(transformedPts, pointIDs_)
212  );
213 
214  fvMesh::movePoints(transformedPts);
215  }
216 
217 
218  if (foundObject<volVectorField>(UName_))
219  {
220  const volVectorField& U = lookupObject<volVectorField>(UName_);
221 
223  }
224  else if (!hasWarned)
225  {
226  hasWarned = true;
227 
229  << "Did not find volVectorField " << UName_
230  << " Not updating " << UName_ << "boundary conditions."
231  << endl;
232  }
233 
234  return true;
235 }
236 
237 
238 // ************************************************************************* //
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:363
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
U
Definition: pEqn.H:83
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void transformPoints(vectorField &, const septernion &, const vectorField &)
Transform given vectorField of coordinates with the given septernion.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool movePoints()
Do what is neccessary if the mesh has moved.
label k
Boltzmann constant.
const cellList & cells() const
Macros for easy insertion into run-time selection tables.
label nCells() const
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Spatial transformation functions for primitive fields.
Foam::cellZoneMesh.
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:341
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Base class for defining solid-body motions.
A class for handling words, derived from string.
Definition: word.H:59
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:256
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:292
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
#define WarningInFunction
Report a warning using Foam::Warning.
Constant dispersed-phase particle diameter model.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
U correctBoundaryConditions()
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Abstract base class for geometry and/or topology changing fvMesh.
Definition: dynamicFvMesh.H:51
A collection of cell labels.
Definition: cellSet.H:48
A List with indirect addressing.
Definition: fvMatrix.H:106
const dimensionedScalar c
Speed of light in a vacuum.
virtual bool update()
Update the mesh for both mesh motion and topology change.
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
label nPoints() const
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:365
Namespace for OpenFOAM.
IOerror FatalIOError