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 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,
44  dictionary
45  );
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::manualRenumber::manualRenumber(const dictionary& renumberDict)
52 :
53  renumberMethod(renumberDict),
54  dataFile_
55  (
56  renumberDict.optionalSubDict(typeName+"Coeffs")
57  .get<fileName>("dataFile")
58  )
59 {}
60 
61 
62 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 
65 (
66  const polyMesh& mesh,
67  const pointField& points
68 ) const
69 {
70  labelIOList newToOld
71  (
72  IOobject
73  (
74  dataFile_,
76  mesh,
79  false
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_ << "." << endl
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. Both index "
120  << oldToNew[origCelli]
121  << " and " << i << " map onto " << origCelli
122  << ".\n" << "Manual renumbering data read from file "
123  << dataFile_ << "." << endl
124  << exit(FatalError);
125  }
126  }
127 
128  return std::move(newToOld);
129 }
130 
131 
132 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::manualRenumber::renumber
virtual labelList renumber(const pointField &) const
Return the order in which cells need to be visited, i.e.
Definition: manualRenumber.H:86
manualRenumber.H
Foam::polyMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:852
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field< vector >
IFstream.H
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::renumberMethod
Abstract base class for renumbering.
Definition: renumberMethod.H:50
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::List< label >
labelIOList.H
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::IOList< label >
Foam::PtrListOps::get
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::IOobject::MUST_READ
Definition: IOobject.H:185