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 -------------------------------------------------------------------------------
10 License
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 
34 bool 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
60  IOobject
61  (
62  expect,
63  pMesh.time().system(),
64  pMesh,
68  ),
69  expect // typeName (ununsed?)
70  )
71  );
72 
73  if (found.empty())
74  {
75  looksValid = false;
76  }
77  }
78 
79  // Only needed on master
80  Pstream::broadcast(looksValid);
81 
82  return looksValid;
83 }
84 
85 
86 bool Foam::faMesh::hasFiles(const polyMesh& pMesh)
87 {
88  // As well as system/{faSchemes,faSolution}
89  //
90  // expect these:
91  // - instance/faMesh/faceLabels
92  // - instance/faMesh/faBoundary
93 
94  bool looksValid = hasSystemFiles(pMesh);
95 
96  if (looksValid)
97  {
98  const fileOperation& fp = Foam::fileHandler();
99 
100  // The geometry instance for faMesh/faceLabels
101  // Must use READ_IF_PRESENT to avoid aborting if not available
102 
103  const word instance = pMesh.time().findInstance
104  (
105  pMesh.dbDir()/faMesh::meshSubDir,
106  "faceLabels",
108  );
109 
110  for
111  (
112  const wordPair& expect
113  : List<wordPair>
114  ({
115  {"faceLabels", "labelList"},
116  {"faBoundary", "faBoundaryMesh"}
117  })
118  )
119  {
120  const word& dataFile = expect.first();
121  const word& dataClass = expect.second();
122 
123  fileName found
124  (
125  fp.filePath
126  (
127  false, // non-global
128  IOobject
129  (
130  dataFile,
131  instance,
133  pMesh,
137  ),
138  dataClass // typeName (ununsed?)
139  )
140  );
141 
142  if (found.empty())
143  {
144  looksValid = false;
145  }
146  }
147 
148  // Everybody needs it, or they all fail
149  Pstream::reduceAnd(looksValid);
150  }
151 
152  return looksValid;
153 }
154 
155 
157 {
158  if (faMesh::hasFiles(pMesh))
159  {
160  return autoPtr<faMesh>::New(pMesh);
161  }
162 
163  return nullptr;
164 }
165 
166 
167 // ************************************************************************* //
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
Ignore writing from objectRegistry::writeObject()
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
static void reduceAnd(bool &value, const label communicator=worldComm)
Logical (and) reduction (MPI_AllReduce)
Reading is optional [identical to LAZY_READ].
Pair< word > wordPair
A pair of words.
Definition: Pair.H:55
static word meshSubDir
The mesh sub-directory name (usually "faMesh")
Definition: faMesh.H:701
IOobject(const IOobject &)=default
Copy construct.
static autoPtr< faMesh > TryNew(const polyMesh &pMesh)
Read construction from polyMesh if all files are available.
Definition: faMeshNew.C:149
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
bool found
Do not request registration (bool: false)