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 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(const polyMesh& pMesh)
35{
36 // Expect
37 // - system/faSchemes
38 // - system/faSolution
39
40 const fileOperation& fp = Foam::fileHandler();
41
42 bool looksValid = true;
43
44 // Global files: system/{faSchemes,faSolution}
45 for
46 (
47 const word& expect
48 : List<word>
49 ({
50 {"faSchemes"},
51 {"faSolution"}
52 })
53 )
54 {
55 fileName found
56 (
57 fp.filePath
58 (
59 true, // global
61 (
62 expect,
63 pMesh.time().system(),
64 pMesh,
67 false
68 ),
69 expect // typeName (ununsed?)
70 )
71 );
72
73 if (found.empty())
74 {
75 looksValid = false;
76 }
77 }
78
79 Pstream::broadcast(looksValid);
80
81 return looksValid;
82}
83
84
85bool Foam::faMesh::hasFiles(const polyMesh& pMesh)
86{
87 // As well as system/{faSchemes,faSolution}
88 //
89 // expect these:
90 // - timeValue/faMesh/faBoundary
91 // - timeValue/instance/faMesh/faceLabels
92
93 bool looksValid = hasSystemFiles(pMesh);
94
95 if (looksValid)
96 {
97 const fileOperation& fp = Foam::fileHandler();
98
99 fileName subDir(pMesh.dbDir()/faMesh::meshSubDir);
100
101 for
102 (
103 const wordPair& expect
104 : List<wordPair>
105 ({
106 {"faBoundary", "faBoundaryMesh"},
107 {"faceLabels", "labelList"}
108 })
109 )
110 {
111 const word& dataFile = expect.first();
112 const word& dataClass = expect.second();
113
114 fileName found
115 (
116 fp.filePath
117 (
118 false, // non-global
119 IOobject
120 (
121 dataFile,
122 pMesh.time().findInstance(subDir, dataFile),
124 pMesh,
127 false
128 ),
129 dataClass // typeName (ununsed?)
130 )
131 );
132
133 if (found.empty())
134 {
135 looksValid = false;
136 }
137 }
138
139 Pstream::broadcast(looksValid);
140 }
141
142 return looksValid;
143}
144
145
147{
148 if (faMesh::hasFiles(pMesh))
149 {
150 return autoPtr<faMesh>::New(pMesh);
151 }
152
153 return nullptr;
154}
155
156
157// ************************************************************************* //
bool found
IOobject(const IOobject &)=default
Copy construct.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
static autoPtr< faMesh > TryNew(const polyMesh &pMesh)
Read construction from polyMesh if all files are available.
Definition: faMeshNew.C:146
static word meshSubDir
The mesh sub-directory name (usually "faMesh")
Definition: faMesh.H:504
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const fileOperation & fileHandler()
Get current file handler.
Pair< word > wordPair
A pair of words.
Definition: Pair.H:58