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  Copyright (C) 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 
29 #include "zoneMotion.H"
30 #include "syncTools.H"
31 #include "cellZoneMesh.H"
32 #include "cellSet.H"
33 #include "boolList.H"
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
37 Foam::zoneMotion::zoneMotion
38 (
39  const dictionary& dict,
40  const polyMesh& mesh
41 )
42 :
43  pointIDs_(),
44  moveAllCells_(false)
45 {
46  word cellZoneName =
47  dict.getOrDefault<word>("cellZone", "none");
48 
49  word cellSetName =
50  dict.getOrDefault<word>("cellSet", "none");
51 
52  if ((cellZoneName != "none") && (cellSetName != "none"))
53  {
55  << "Either cellZone OR cellSet can be supplied, but not both. "
56  << "If neither is supplied, all cells will be included"
57  << exit(FatalIOError);
58  }
59 
60  labelList cellIDs;
61  if (cellZoneName != "none")
62  {
63  Info<< "Applying solid body motion to cellZone " << cellZoneName
64  << endl;
65 
66  label zoneID = mesh.cellZones().findZoneID(cellZoneName);
67 
68  if (zoneID == -1)
69  {
71  << "Unable to find cellZone " << cellZoneName
72  << ". Valid cellZones are:"
73  << mesh.cellZones().names()
74  << exit(FatalError);
75  }
76 
77  cellIDs = mesh.cellZones()[zoneID];
78  }
79 
80  if (cellSetName != "none")
81  {
82  Info<< "Applying solid body motion to cellSet " << cellSetName
83  << endl;
84 
85  cellSet set(mesh, cellSetName);
86 
87  cellIDs = set.toc();
88  }
89 
90  label nCells = returnReduce(cellIDs.size(), sumOp<label>());
91  moveAllCells_ = (nCells == 0);
92 
93  if (moveAllCells_)
94  {
95  Info<< "Applying solid body motion to entire mesh" << endl;
96  }
97  else
98  {
99  boolList movePts(mesh.nPoints(), false);
100 
101  forAll(cellIDs, i)
102  {
103  label celli = cellIDs[i];
104  const cell& c = mesh.cells()[celli];
105  forAll(c, j)
106  {
107  const face& f = mesh.faces()[c[j]];
108  forAll(f, k)
109  {
110  label pointi = f[k];
111  movePts[pointi] = true;
112  }
113  }
114  }
115 
116  syncTools::syncPointList(mesh, movePts, orEqOp<bool>(), false);
117 
118  DynamicList<label> ptIDs(mesh.nPoints());
119  forAll(movePts, i)
120  {
121  if (movePts[i])
122  {
123  ptIDs.append(i);
124  }
125  }
126 
127  pointIDs_.transfer(ptIDs);
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Members * * * * * * * * * * * * * * //
133 
135 {
136  return pointIDs_;
137 }
138 
139 
141 {
142  return moveAllCells_;
143 }
144 
145 
146 // ************************************************************************* //
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
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::DynamicList< label >
Foam::zoneMotion::pointIDs
const labelList & pointIDs() const
Return pointsID.
Definition: zoneMotion.C:134
Foam::orEqOp
Definition: ops.H:86
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
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:296
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:381
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:72
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
cellSet.H
Foam::zoneMotion::moveAllCells
bool moveAllCells() const
Return flag.
Definition: zoneMotion.C:140
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54