manualRenumber.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-2024 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 "manualRenumber.H"
31 #include "labelIOList.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeName(manualRenumber);
38 
40  (
41  renumberMethod,
42  manualRenumber,
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 :
53  dataFile_(file)
54 {}
55 
56 
58 :
60  dataFile_
61  (
62  dict.optionalSubDict(typeName + "Coeffs").get<fileName>("dataFile")
63  )
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
70 (
71  const polyMesh& mesh
72 ) const
73 {
74  const label nCells = mesh.nCells();
75 
76  labelList newToOld
77  (
79  (
80  IOobject
81  (
82  dataFile_,
84  mesh.thisDb(),
86  )
87  )
88  );
89 
90  // Check if the final renumbering is OK
91  if (newToOld.size() != nCells)
92  {
94  << "Size of renumber list: "
95  << newToOld.size() << " != number of cells: " << nCells << nl
96  << "Renumbering data read from file " << dataFile_ << endl
97  << exit(FatalError);
98  }
99 
100  // Invert to see if one to one
101  labelList oldToNew(nCells, -1);
102  forAll(newToOld, i)
103  {
104  const label origCelli = newToOld[i];
105 
106  if (origCelli < 0 || origCelli >= nCells)
107  {
109  << "Renumbering range error. Index " << i
110  << " maps to cell " << origCelli << " from " << nCells << nl
111  << "Renumbering data read from file " << dataFile_ << endl
112  << exit(FatalError);
113  }
114 
115  if (oldToNew[origCelli] == -1)
116  {
117  oldToNew[origCelli] = i;
118  }
119  else
120  {
122  << "Renumbering is not one-to-one. Index " << i << " and "
123  << oldToNew[origCelli] << " map onto " << origCelli << nl
124  << "Renumbering data read from file " << dataFile_ << endl
125  << exit(FatalError);
126  }
127  }
128 
129  return newToOld;
130 }
131 
132 
133 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
A class for handling file names.
Definition: fileName.H:72
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:859
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
manualRenumber(const fileName &file)
Construct with given data file.
Macros for easy insertion into run-time selection tables.
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:376
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
defineTypeName(manifoldCellsMeshObject)
Abstract base class for renumbering.
static List< label > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
Definition: IOList.C:125
dynamicFvMesh & mesh
virtual labelList renumber(const polyMesh &mesh) const
Return the cell visit order (from ordered back to original cell id) using the mesh for its IOobject a...
label nCells() const noexcept
Number of mesh cells.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
List< label > labelList
A List of labels.
Definition: List.H:62
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)