faceAgglomerate.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-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 Application
28  faceAgglomerate
29 
30 Group
31  grpPreProcessingUtilities
32 
33 Description
34  Agglomerate boundary faces using the pairPatchAgglomeration algorithm.
35 
36  It writes a map from the fine to coarse grid.
37 
38 SeeAlso
39  pairPatchAgglomeration.H
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #include "argList.H"
44 #include "fvMesh.H"
45 #include "Time.H"
46 #include "volFields.H"
47 #include "unitConversion.H"
48 #include "pairPatchAgglomeration.H"
49 #include "labelListIOList.H"
50 #include "syncTools.H"
51 #include "globalIndex.H"
52 
53 using namespace Foam;
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 int main(int argc, char *argv[])
58 {
60  (
61  "Agglomerate boundary faces using the pairPatchAgglomeration"
62  " algorithm. Writes a map of fine to coarse grid."
63  );
64 
65  argList::addOption("dict", "file", "Alternative viewFactorsDict");
66  #include "addRegionOption.H"
67 
68  #include "setRootCase.H"
69  #include "createTime.H"
70  #include "createNamedMesh.H"
71 
72  const word dictName("viewFactorsDict");
73 
75 
76  // Read control dictionary
77  const IOdictionary agglomDict(dictIO);
78 
79  const bool writeAgglom(agglomDict.get<bool>("writeFacesAgglomeration"));
80 
82 
83  labelListIOList finalAgglom
84  (
85  IOobject
86  (
87  "finalAgglom",
89  mesh,
92  false
93  ),
94  boundary.size()
95  );
96 
97  label nCoarseFaces = 0;
98 
99  for (const entry& dEntry : agglomDict)
100  {
101  labelList patchids = boundary.indices(dEntry.keyword());
102 
103  for (const label patchi : patchids)
104  {
105  const polyPatch& pp = boundary[patchi];
106 
107  if (!pp.coupled())
108  {
109  Info << "\nAgglomerating patch : " << pp.name() << endl;
110 
111  pairPatchAgglomeration agglomObject
112  (
113  pp.localFaces(),
114  pp.localPoints(),
115  agglomDict.subDict(pp.name())
116  );
117 
118  agglomObject.agglomerate();
119 
120  finalAgglom[patchi] =
121  agglomObject.restrictTopBottomAddressing();
122 
123  if (finalAgglom[patchi].size())
124  {
125  nCoarseFaces += max(finalAgglom[patchi] + 1);
126  }
127  }
128  }
129  }
130 
131 
132  // All patches which are not agglomerated are identity for finalAgglom
133  forAll(boundary, patchi)
134  {
135  if (finalAgglom[patchi].size() == 0)
136  {
137  finalAgglom[patchi] = identity(boundary[patchi].size());
138  }
139  }
140 
141  // Sync agglomeration across coupled patches
142  labelList nbrAgglom(mesh.nBoundaryFaces(), -1);
143 
144  forAll(boundary, patchi)
145  {
146  const polyPatch& pp = boundary[patchi];
147  if (pp.coupled())
148  {
149  finalAgglom[patchi] = identity(pp.size());
150  forAll(pp, i)
151  {
152  const label agglomi = pp.start() - mesh.nInternalFaces() + i;
153  nbrAgglom[agglomi] = finalAgglom[patchi][i];
154  }
155  }
156  }
157 
159  forAll(boundary, patchi)
160  {
161  const polyPatch& pp = boundary[patchi];
162  if (pp.coupled() && !refCast<const coupledPolyPatch>(pp).owner())
163  {
164  forAll(pp, i)
165  {
166  const label agglomi = pp.start() - mesh.nInternalFaces() + i;
167  finalAgglom[patchi][i] = nbrAgglom[agglomi];
168  }
169  }
170  }
171 
172  finalAgglom.write();
173 
174  if (writeAgglom)
175  {
176  globalIndex index(nCoarseFaces);
177  volScalarField facesAgglomeration
178  (
179  IOobject
180  (
181  "facesAgglomeration",
182  mesh.time().timeName(),
183  mesh,
186  ),
187  mesh,
189  );
190 
191  volScalarField::Boundary& facesAgglomerationBf =
192  facesAgglomeration.boundaryFieldRef();
193 
194  label coarsePatchIndex = 0;
195  forAll(boundary, patchi)
196  {
197  const polyPatch& pp = boundary[patchi];
198  if (pp.size() > 0)
199  {
200  fvPatchScalarField& bFacesAgglomeration =
201  facesAgglomerationBf[patchi];
202 
203  forAll(bFacesAgglomeration, j)
204  {
205  bFacesAgglomeration[j] =
206  index.toGlobal
207  (
209  finalAgglom[patchi][j] + coarsePatchIndex
210  );
211  }
212 
213  coarsePatchIndex += max(finalAgglom[patchi]) + 1;
214  }
215  }
216 
217  Info<< "\nWriting facesAgglomeration" << endl;
218  facesAgglomeration.write();
219  }
220 
221  Info<< "End\n" << endl;
222  return 0;
223 }
224 
225 
226 // ************************************************************************* //
Foam::fvPatchField< scalar >
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
volFields.H
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Number of internal faces.
Definition: primitiveMeshI.H:78
globalIndex.H
Foam::polyPatch::coupled
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:328
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:785
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
dictName
const word dictName("blockMeshDict")
Foam::pairPatchAgglomeration
Primitive patch pair agglomerate method.
Definition: pairPatchAgglomeration.H:54
Foam::polyMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:821
unitConversion.H
Unit conversion functions.
Foam::syncTools::swapBoundaryFaceList
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:439
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
syncTools.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
labelListIOList.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:67
argList.H
addRegionOption.H
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::primitiveMesh::nBoundaryFaces
label nBoundaryFaces() const
Number of boundary faces (== nFaces - nInternalFaces)
Definition: primitiveMeshI.H:84
createNamedMesh.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::PrimitivePatch::localFaces
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatch.C:297
dictIO
IOobject dictIO
Definition: setConstantMeshDictionaryIO.H:1
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::PrimitivePatch::localPoints
const Field< point_type > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatch.C:339
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:445
Time.H
setRootCase.H
pairPatchAgglomeration.H
Foam::GeometricField::boundaryFieldRef
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
Definition: GeometricField.C:783
Foam::List< label >
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::IOList< labelList >
createTime.H
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:248
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition: argList.C:336
Foam::patchIdentifier::name
const word & name() const
The patch name.
Definition: patchIdentifier.H:134
boundary
faceListList boundary
Definition: createBlockMesh.H:4
setConstantMeshDictionaryIO.H