zoneMotion.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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "zoneMotion.H"
29 #include "syncTools.H"
30 #include "cellZoneMesh.H"
31 #include "cellSet.H"
32 #include "boolList.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 Foam::zoneMotion::zoneMotion
37 (
38  const dictionary& dict,
39  const polyMesh& mesh
40 )
41 :
42  pointIDs_(),
43  moveAllCells_(false)
44 {
45  word cellZoneName =
46  dict.lookupOrDefault<word>("cellZone", "none");
47 
48  word cellSetName =
49  dict.lookupOrDefault<word>("cellSet", "none");
50 
51  if ((cellZoneName != "none") && (cellSetName != "none"))
52  {
54  << "Either cellZone OR cellSet can be supplied, but not both. "
55  << "If neither is supplied, all cells will be included"
56  << exit(FatalIOError);
57  }
58 
59  labelList cellIDs;
60  if (cellZoneName != "none")
61  {
62  Info<< "Applying solid body motion to cellZone " << cellZoneName
63  << endl;
64 
65  label zoneID = mesh.cellZones().findZoneID(cellZoneName);
66 
67  if (zoneID == -1)
68  {
70  << "Unable to find cellZone " << cellZoneName
71  << ". Valid cellZones are:"
72  << mesh.cellZones().names()
73  << exit(FatalError);
74  }
75 
76  cellIDs = mesh.cellZones()[zoneID];
77  }
78 
79  if (cellSetName != "none")
80  {
81  Info<< "Applying solid body motion to cellSet " << cellSetName
82  << endl;
83 
84  cellSet set(mesh, cellSetName);
85 
86  cellIDs = set.toc();
87  }
88 
89  label nCells = returnReduce(cellIDs.size(), sumOp<label>());
90  moveAllCells_ = (nCells == 0);
91 
92  if (moveAllCells_)
93  {
94  Info<< "Applying solid body motion to entire mesh" << endl;
95  }
96  else
97  {
98  boolList movePts(mesh.nPoints(), false);
99 
100  forAll(cellIDs, i)
101  {
102  label celli = cellIDs[i];
103  const cell& c = mesh.cells()[celli];
104  forAll(c, j)
105  {
106  const face& f = mesh.faces()[c[j]];
107  forAll(f, k)
108  {
109  label pointi = f[k];
110  movePts[pointi] = true;
111  }
112  }
113  }
114 
115  syncTools::syncPointList(mesh, movePts, orEqOp<bool>(), false);
116 
117  DynamicList<label> ptIDs(mesh.nPoints());
118  forAll(movePts, i)
119  {
120  if (movePts[i])
121  {
122  ptIDs.append(i);
123  }
124  }
125 
126  pointIDs_.transfer(ptIDs);
127  }
128 }
129 
130 
131 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * * Members * * * * * * * * * * * * * * //
138 
140 {
141  return pointIDs_;
142 }
143 
144 
146 {
147  return moveAllCells_;
148 }
149 
150 // ************************************************************************* //
boolList.H
cellZoneMesh.H
Foam::cellZoneMesh.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::HashTable::toc
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:121
Foam::DynamicList< label >
Foam::zoneMotion::pointIDs
const labelList & pointIDs() const
Return pointsID.
Definition: zoneMotion.C:139
Foam::orEqOp
Definition: ops.H:86
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::zoneMotion::~zoneMotion
virtual ~zoneMotion()
Destructor.
Definition: zoneMotion.C:133
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:62
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
zoneMotion.H
f
labelList f(nPoints)
Foam::List< label >
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
cellSet.H
Foam::zoneMotion::moveAllCells
bool moveAllCells() const
Return flag.
Definition: zoneMotion.C:145
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54