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-2022 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 "bitSet.H"
32 #include "cellSet.H"
33 #include "cellZoneMesh.H"
34 #include "dictionary.H"
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 (
40  const dictionary& dict,
41  const polyMesh& mesh
42 )
43 :
44  pointIDs_(),
45  moveAllCells_(true)
46 {
47  // Specified cellSet?
48  word cellSetName;
49 
50  if
51  (
52  dict.readIfPresent("cellSet", cellSetName)
53  && cellSetName == "none" // Compat: ignore 'none' placeholder
54  )
55  {
56  cellSetName.clear();
57  }
58 
60  if (!cellSetName.empty())
61  {
62  Info<< "Applying motion to cellSet: " << cellSetName << endl;
63 
64  cellIDs = cellSet(mesh, cellSetName).toc();
65  }
66 
67 
68  // Specified cellZone(s) ?
69  wordRe cellZoneName;
70 
71  if
72  (
73  dict.readIfPresent("cellZone", cellZoneName)
74  && cellZoneName == "none" // Compat: ignore 'none' placeholder
75  )
76  {
77  cellZoneName.clear();
78  }
79 
81  if (!cellZoneName.empty())
82  {
83  Info<< "Applying motion to cellZone: " << cellZoneName << endl;
84 
85  // Also handles groups, multiple zones (as wordRe match) ...
86  zoneIDs = mesh.cellZones().indices(cellZoneName);
87 
88  if (zoneIDs.empty())
89  {
91  << "No matching cellZones: " << cellZoneName << nl
92  << " Valid zones : "
93  << flatOutput(mesh.cellZones().names()) << nl
94  << " Valid groups: "
95  << flatOutput(mesh.cellZones().groupNames())
96  << nl
97  << exit(FatalIOError);
98  }
99  }
100 
101  if (!cellSetName.empty() || !cellZoneName.empty())
102  {
103  bitSet movePts(mesh.nPoints());
104 
105  // Markup points associated with cell zone(s)
106  for (const label zoneID : zoneIDs)
107  {
108  for (const label celli : mesh.cellZones()[zoneID])
109  {
110  for (const label facei : mesh.cells()[celli])
111  {
112  movePts.set(mesh.faces()[facei]);
113  }
114  }
115  }
116 
117  // Markup points associated with cellSet
118  for (const label celli : cellIDs)
119  {
120  for (const label facei : mesh.cells()[celli])
121  {
122  movePts.set(mesh.faces()[facei]);
123  }
124  }
125 
127 
128  pointIDs_ = movePts.sortedToc();
129  }
130 
131 
132  // No cell points selected (as set or zones) => move all points
133 
134  moveAllCells_ = returnReduceAnd(pointIDs_.empty());
135 
136  if (moveAllCells_)
137  {
138  Info<< "Applying motion to entire mesh" << endl;
139  }
140 }
141 
142 
143 // ************************************************************************* //
dictionary dict
const labelIOList & zoneIDs
Definition: correctPhi.H:59
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:504
zoneMotion(const dictionary &dict, const polyMesh &mesh)
Construct from dictionary.
Definition: zoneMotion.C:32
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Foam::cellZoneMesh.
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
void clear()
Clear string and regular expression.
Definition: wordReI.H:186
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
A collection of cell labels.
Definition: cellSet.H:47
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:124
labelList cellIDs
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...