Loading...
Searching...
No Matches
faMeshNew.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) 2022-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "faMesh.H"
29#include "polyMesh.H"
30#include "fileOperation.H"
31
32// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
33
34bool Foam::faMesh::hasSystemFiles
35(
36 const word& areaName,
37 const polyMesh& pMesh
38)
39{
40 // Expect
41 // - system/finite-area/<region>/faSchemes
42 // - system/finite-area/<region>/faSolution
43
44 // The directory relative to polyMesh (not Time)
45 const fileName relativeDir
46 (
48 );
49
50 DebugInfo<< "check system files: " << relativeDir << nl;
51
52 IOobject systemIOobject
53 (
54 "any-name",
55 pMesh.time().system(),
56 relativeDir,
57 pMesh,
61 );
62
63 const fileOperation& fp = Foam::fileHandler();
64
65 bool looksValid = true;
66
67 // Global files: system/{faSchemes,faSolution}
68 for
69 (
70 const word& expect
71 : List<word>
72 ({
73 {"faSchemes"},
74 {"faSolution"}
75 })
76 )
77 {
78 systemIOobject.resetHeader(expect);
79
80 fileName found
81 (
82 fp.filePath
83 (
84 true, // global
85 systemIOobject,
86 expect // typeName (ununsed?)
87 )
88 );
89
90 if (found.empty())
91 {
92 looksValid = false;
93 }
94 }
95
96 // Only needed on master
97 Pstream::broadcast(looksValid);
98
99 return looksValid;
100}
101
102
103bool Foam::faMesh::hasMeshFiles
104(
105 const word& areaName,
106 const polyMesh& pMesh
107)
108{
109 // As well as system/finite-area/{faSchemes,faSolution}
110 //
111 // expect these:
112 // - instance/finite-area/<region>/faMesh/faceLabels
113 // - instance/finite-area/<region>/faMesh/faBoundary
114
115
116 // Not required...
117 // bool looksValid = hasSystemFiles(areaName, pMesh);
118
119 bool looksValid = true;
120
121 // The mesh directory relative to polyMesh (not Time)
122 const fileName relativeDir
123 (
124 faMesh::meshDir(word::null, areaName)
125 );
126
127 if (looksValid)
128 {
129 DebugInfo<< "check mesh files: " << relativeDir << nl;
130
131 const fileOperation& fp = Foam::fileHandler();
132
133 // The geometry instance for faMesh/faceLabels
134 // Must use READ_IF_PRESENT to avoid aborting if not available
135
136 const word instance = pMesh.time().findInstance
137 (
138 // Searching from Time, so need polyMesh region too
139 pMesh.regionName()/relativeDir,
140 "faceLabels",
142 );
143
144 IOobject meshIOobject
145 (
146 "any-name",
147 instance,
148 relativeDir,
149 pMesh,
153 );
154
155 for
156 (
157 const wordPair& expect
159 ({
160 {"faceLabels", "labelList"},
161 {"faBoundary", "faBoundaryMesh"}
162 })
163 )
164 {
165 const word& dataFile = expect.first();
166 const word& dataClass = expect.second();
167
168 meshIOobject.resetHeader(dataFile);
169
171 (
172 fp.filePath
173 (
174 false, // non-global
175 meshIOobject,
176 dataClass // typeName (ununsed?)
177 )
178 );
179
180 if (found.empty())
181 {
182 looksValid = false;
183 }
184 }
185
186 // Everybody needs it, or they all fail
188 }
189
190 return looksValid;
191}
192
193
195(
196 const word& areaName,
197 const polyMesh& pMesh
198)
199{
200 if (faMesh::hasMeshFiles(areaName, pMesh))
201 {
202 return autoPtr<faMesh>::New(areaName, pMesh);
203 }
204
205 return nullptr;
206}
207
208
210(
211 const polyMesh& pMesh
212)
213{
214 return TryNew(polyMesh::defaultRegion, pMesh);
215}
216
217
218// ************************************************************************* //
bool found
@ NO_REGISTER
Do not request registration (bool: false).
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
static void reduceAnd(bool &value, const int communicator=worldComm)
Logical (and) reduction (MPI_AllReduce).
@ broadcast
broadcast [MPI]
Definition UPstream.H:189
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition autoPtr.H:178
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir).
Definition faMesh.C:1022
static autoPtr< faMesh > TryNew(const word &areaName, const polyMesh &pMesh)
Read construction from polyMesh if all files are available.
Definition faMeshNew.C:188
static const word & prefix() noexcept
The prefix to the parent registry name: finite-area.
Definition faMesh.C:66
A class for handling file names.
Definition fileName.H:75
An encapsulation of filesystem-related operations.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static word defaultRegion
Return the default region name.
Definition polyMesh.H:406
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
Definition polyMesh.C:832
A class for handling words, derived from Foam::string.
Definition word.H:66
static const word null
An empty word.
Definition word.H:84
#define DebugInfo
Report an information message using Foam::Info.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
Pair< word > wordPair
A pair of words.
Definition Pair.H:55
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50