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 | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "manualRenumber.H"
28 #include "IFstream.H"
29 #include "labelIOList.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(manualRenumber, 0);
36 
38  (
39  renumberMethod,
40  manualRenumber,
41  dictionary
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
48 Foam::manualRenumber::manualRenumber(const dictionary& renumberDict)
49 :
50  renumberMethod(renumberDict),
51  dataFile_
52  (
53  renumberDict.subDict(typeName+"Coeffs").lookup("dataFile")
54  )
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59 
61 (
62  const polyMesh& mesh,
63  const pointField& points
64 ) const
65 {
66  labelIOList newToOld
67  (
68  IOobject
69  (
70  dataFile_,
71  mesh.facesInstance(),
72  mesh,
75  false
76  )
77  );
78 
79  // check if the final renumbering is OK
80 
81  if (newToOld.size() != points.size())
82  {
84  << "Size of renumber list does not correspond "
85  << "to the number of points. Size: "
86  << newToOld.size() << " Number of points: "
87  << points.size()
88  << ".\n" << "Manual renumbering data read from file "
89  << dataFile_ << "." << endl
90  << exit(FatalError);
91  }
92 
93  // Invert to see if one to one
94  labelList oldToNew(points.size(), -1);
95  forAll(newToOld, i)
96  {
97  label origCelli = newToOld[i];
98 
99  if (origCelli < 0 || origCelli >= points.size())
100  {
102  << "Renumbering is not one-to-one. Index "
103  << i << " maps onto original cell " << origCelli
104  << ".\n" << "Manual renumbering data read from file "
105  << dataFile_ << "." << endl
106  << exit(FatalError);
107  }
108 
109  if (oldToNew[origCelli] == -1)
110  {
111  oldToNew[origCelli] = i;
112  }
113  else
114  {
116  << "Renumbering is not one-to-one. Both index "
117  << oldToNew[origCelli]
118  << " and " << i << " map onto " << origCelli
119  << ".\n" << "Manual renumbering data read from file "
120  << dataFile_ << "." << endl
121  << exit(FatalError);
122  }
123  }
124 
125  return newToOld;
126 }
127 
128 
129 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:778
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Macros for easy insertion into run-time selection tables.
Abstract base class for renumbering.
stressControl lookup("compactNormalStress") >> compactNormalStress
dynamicFvMesh & mesh
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual labelList renumber(const pointField &) const
Return the order in which cells need to be visited, i.e.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Namespace for OpenFOAM.