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  labelIOList newToOld
70  (
71  IOobject
72  (
73  dataFile_,
75  mesh,
78  false
79  )
80  );
81 
82  // Check if the final renumbering is OK
83  if (newToOld.size() != points.size())
84  {
86  << "Size of renumber list does not correspond "
87  << "to the number of points. Size: "
88  << newToOld.size() << " Number of points: "
89  << points.size()
90  << ".\n" << "Manual renumbering data read from file "
91  << dataFile_ << "." << endl
92  << exit(FatalError);
93  }
94 
95  // Invert to see if one to one
96  labelList oldToNew(points.size(), -1);
97  forAll(newToOld, i)
98  {
99  const label origCelli = newToOld[i];
100 
101  if (origCelli < 0 || origCelli >= points.size())
102  {
104  << "Renumbering is not one-to-one. Index "
105  << i << " maps onto original cell " << origCelli
106  << ".\n" << "Manual renumbering data read from file "
107  << dataFile_ << "." << endl
108  << exit(FatalError);
109  }
110 
111  if (oldToNew[origCelli] == -1)
112  {
113  oldToNew[origCelli] = i;
114  }
115  else
116  {
118  << "Renumbering is not one-to-one. Both index "
119  << oldToNew[origCelli]
120  << " and " << i << " map onto " << origCelli
121  << ".\n" << "Manual renumbering data read from file "
122  << dataFile_ << "." << endl
123  << exit(FatalError);
124  }
125  }
126 
127  return std::move(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:118
A class for handling file names.
Definition: fileName.H:71
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:853
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:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
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)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Automatically write from objectRegistry::writeObject()
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
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:166
Namespace for OpenFOAM.