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-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 "manualRenumber.H"
31 #include "IFstream.H"
32 #include "labelIOList.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(manualRenumber, 0);
39 
41  (
42  renumberMethod,
43  manualRenumber,
45  );
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::manualRenumber::manualRenumber(const dictionary& dict)
52 :
54  dataFile_
55  (
56  dict.optionalSubDict(typeName+"Coeffs").get<fileName>("dataFile")
57  )
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
64 (
65  const polyMesh& mesh,
66  const pointField& points
67 ) const
68 {
69  labelList newToOld
70  (
71  labelIOList::readContents
72  (
73  IOobject
74  (
75  dataFile_,
77  mesh.thisDb(),
79  )
80  )
81  );
82 
83  // Check if the final renumbering is OK
84  if (newToOld.size() != points.size())
85  {
87  << "Size of renumber list does not correspond "
88  << "to the number of points. Size: "
89  << newToOld.size() << " Number of points: "
90  << points.size()
91  << ".\n" << "Manual renumbering data read from file "
92  << dataFile_ << "." << endl
93  << exit(FatalError);
94  }
95 
96  // Invert to see if one to one
97  labelList oldToNew(points.size(), -1);
98  forAll(newToOld, i)
99  {
100  const label origCelli = newToOld[i];
101 
102  if (origCelli < 0 || origCelli >= points.size())
103  {
105  << "Renumbering is not one-to-one. Index "
106  << i << " maps onto original cell " << origCelli
107  << ".\n" << "Manual renumbering data read from file "
108  << dataFile_ << nl
109  << exit(FatalError);
110  }
111 
112  if (oldToNew[origCelli] == -1)
113  {
114  oldToNew[origCelli] = i;
115  }
116  else
117  {
119  << "Renumbering is not one-to-one. Index " << i << " and "
120  << oldToNew[origCelli] << " map onto " << origCelli << nl
121  << "Manual renumbering data read from file "
122  << dataFile_ << nl
123  << exit(FatalError);
124  }
125  }
126 
127  return newToOld;
128 }
129 
130 
131 // ************************************************************************* //
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
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
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:598
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
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
Abstract base class for renumbering.
dynamicFvMesh & mesh
const pointField & points
virtual labelList renumber(const pointField &) const
Return the order in which cells need to be visited (ie. from ordered back to original cell label)...
defineTypeNameAndDebug(combustionModel, 0)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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:172
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)