Report patch name instead of index in debug
[foam-extend-3.2.git] / src / foam / meshes / polyMesh / zones / ZoneID / polyPatchID.H
blobd005f77fe8749d87432907a9cc194d6cb00e76bd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::polyPatchID
27 Description
28     A class holds the data needed to identify a patch in a dynamic mesh.
30     The patch is identified by name and its index in the boundary mesh
31     is updated if the mesh has changed.
33 \*---------------------------------------------------------------------------*/
35 #ifndef polyPatchID_H
36 #define polyPatchID_H
38 #include "polyBoundaryMesh.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 namespace Foam
45 // Forward declaration of friend functions and operators
47 class polyPatchID;
48 Ostream& operator<<(Ostream& os, const polyPatchID& p);
51 /*---------------------------------------------------------------------------*\
52                            Class polyPatchID Declaration
53 \*---------------------------------------------------------------------------*/
55 class polyPatchID
57     // Private data
59         //- Patch name
60         word name_;
62         //- Patch index
63         label index_;
66 public:
68     // Constructors
70         //- Construct from name
71         polyPatchID
72         (
73             const word& name,
74             const polyBoundaryMesh& bm,
75             bool checkValid = false
76         )
77         :
78             name_(name),
79             index_(bm.findPatchID(name))
80         {
81             if (checkValid && index_ < 0)
82             {
83                 FatalErrorIn
84                 (
85                     "polyPatchID\n"
86                     "(\n"
87                     "    const word& name,\n"
88                     "    const polyBoundaryMesh& bm,\n"
89                     "    bool checkValid = false\n"
90                     ")"
91                 )   << "Patch " << name_ << " not found.  Valid patch names: "
92                     << bm.names()
93                     << abort(FatalError);
94             }
95         }
97         //- Construct from Istream
98         polyPatchID
99         (
100             Istream& is,
101             const polyBoundaryMesh& bm,
102             bool checkValid = false
103         )
104         :
105             name_(is),
106             index_(bm.findPatchID(name_))
107         {
108             if (checkValid && index_ < 0)
109             {
110                 FatalErrorIn
111                 (
112                     "polyPatchID\n"
113                     "(\n"
114                     "    Istream& is\n"
115                     "    const polyBoundaryMesh& bm,\n"
116                     "    bool checkValid = false\n"
117                     ")"
118                 )   << "Patch " << name_ << " not found.  Valid patch names: "
119                     << bm.names()
120                     << abort(FatalError);
121             }
122         }
125     // Member Functions
127         // Access
129             //- Return name
130             const word& name() const
131             {
132                 return name_;
133             }
135             //- Return index
136             label index() const
137             {
138                 return index_;
139             }
141             //- Has the patch been found
142             bool active() const
143             {
144                 return index_ > -1;
145             }
148         // Edit
150             //- Update
151             void update(const polyBoundaryMesh& bm)
152             {
153                 index_ = bm.findPatchID(name_);
154             }
157     // Ostream Operator
159         friend Ostream& operator<<(Ostream& os, const polyPatchID& p)
160         {
161             os  << token::BEGIN_LIST
162                 << p.name_ << token::SPACE
163                 << p.index_
164                 << token::END_LIST;
166             // Check state of Ostream
167             os.check("Ostream& operator<<(Ostream&, const polyPatchID&)");
169             return os;
170         }
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 } // End namespace Foam
178 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 #endif
182 // ************************************************************************* //