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-2015 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 
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>("UName", "U"))
81 {
82  if (undisplacedPoints_.size() != nPoints())
83  {
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  {
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  (
196  transform
197  (
198  SBMFPtr_().transformation(),
199  undisplacedPoints_
200  )
201  );
202  }
203  else
204  {
205  pointField transformedPts(undisplacedPoints_);
206 
207  UIndirectList<point>(transformedPts, pointIDs_) =
208  transform
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 // ************************************************************************* //
volFields.H
Foam::solidBodyMotionFvMesh::~solidBodyMotionFvMesh
~solidBodyMotionFvMesh()
Destructor.
Definition: solidBodyMotionFvMesh.C:182
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
boolList.H
cellZoneMesh.H
Foam::cellZoneMesh.
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:86
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
Foam::dynamicFvMesh
Abstract base class for geometry and/or topology changing fvMesh.
Definition: dynamicFvMesh.H:51
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
solidBodyMotionFvMesh.H
syncTools.H
Foam::solidBodyMotionFvMesh::dynamicMeshCoeffs_
const dictionary dynamicMeshCoeffs_
Dictionary of motion control parameters.
Definition: solidBodyMotionFvMesh.H:59
transformField.H
Spatial transformation functions for primitive fields.
Foam::transform
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
U
U
Definition: pEqn.H:46
constant
Constant dispersed-phase particle diameter model.
Foam::IOobject::objectPath
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:376
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
Foam::solidBodyMotionFvMesh::pointIDs_
labelList pointIDs_
Points to move when cell zone is supplied.
Definition: solidBodyMotionFvMesh.H:68
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::label
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
Foam::solidBodyMotionFvMesh::solidBodyMotionFvMesh
solidBodyMotionFvMesh(const solidBodyMotionFvMesh &)
Disallow default bitwise copy construct.
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::solidBodyMotionFunction
Base class for defining solid-body motions.
Definition: solidBodyMotionFunction.H:60
Foam::orEqOp
Definition: ops.H:82
Foam::solidBodyMotionFvMesh::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: solidBodyMotionFvMesh.C:188
Foam::FatalError
error FatalError
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::surfaceInterpolation::movePoints
bool movePoints()
Do what is neccessary if the mesh has moved.
Definition: surfaceInterpolation.C:125
Foam::solidBodyMotionFvMesh::undisplacedPoints_
pointIOField undisplacedPoints_
The reference points which are transformed.
Definition: solidBodyMotionFvMesh.H:65
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:48
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:348
Foam::ZoneMesh::names
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:263
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sumOp
Definition: ops.H:162
correctBoundaryConditions
U correctBoundaryConditions()
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
cellSet.H
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::syncTools::syncPointList
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
Definition: syncToolsTemplates.C:984
Foam::solidBodyMotionFvMesh::moveAllCells_
bool moveAllCells_
Flag to indicate whether all cells should move.
Definition: solidBodyMotionFvMesh.H:71
Foam::dictionary::set
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:856