loadOrCreateMesh.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) 2012-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2022 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 "loadOrCreateMesh.H"
30 #include "faMesh.H"
31 #include "Pstream.H"
32 #include "OSspecific.H"
33 
34 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
35 
37 (
38  const Time& runTime,
39  const fileName& meshPath,
40  const word& meshFile,
41  const bool verbose
42 )
43 {
44  boolList haveFileOnProc
45  (
46  UPstream::listGatherValues<bool>
47  (
49  (
50  fileHandler().filePath
51  (
52  runTime.path()/meshPath/meshFile
53  )
54  )
55  )
56  );
57 
58  if (verbose)
59  {
60  Info<< "Per processor availability of \""
61  << meshFile << "\" file in " << meshPath << nl
62  << " " << flatOutput(haveFileOnProc) << nl << endl;
63  }
64 
65  Pstream::broadcast(haveFileOnProc);
66  return haveFileOnProc;
67 }
68 
69 
70 void Foam::removeProcAddressing(const faMesh& mesh)
71 {
72  IOobject io
73  (
74  "procAddressing",
75  mesh.facesInstance(),
76  faMesh::meshSubDir,
77  mesh.thisDb()
78  );
79 
80  for (const auto prefix : {"boundary", "edge", "face", "point"})
81  {
82  io.rename(prefix + word("ProcAddressing"));
83 
84  const fileName procFile(io.objectPath());
85  Foam::rm(procFile);
86  }
87 }
88 
89 
90 void Foam::removeProcAddressing(const polyMesh& mesh)
91 {
92  IOobject io
93  (
94  "procAddressing",
95  mesh.facesInstance(),
96  polyMesh::meshSubDir,
97  mesh.thisDb()
98  );
99 
100  for (const auto prefix : {"boundary", "cell", "face", "point"})
101  {
102  io.rename(prefix + word("ProcAddressing"));
103 
104  const fileName procFile(io.objectPath());
105  Foam::rm(procFile);
106  }
107 }
108 
109 
110 void Foam::removeEmptyDir(const fileName& path)
111 {
112  // Remove directory: silent, emptyOnly
113  Foam::rmDir(path, true, true);
114 }
115 
116 
117 void Foam::removeEmptyDirs(const fileName& meshPath)
118 {
119  // Delete resulting directory if empty
120  fileName path(meshPath);
121  path.clean();
122 
123  // Do subdirectories
124  {
125  const fileNameList dirs
126  (
128  (
129  path,
130  fileName::DIRECTORY,
131  false, // filterGz
132  false // followLink
133  )
134  );
135  for (const auto& dir : dirs)
136  {
137  removeEmptyDirs(path/dir);
138  }
139  }
140 
142 }
143 
144 
145 // ************************************************************************* //
boolList haveMeshFile(const Time &runTime, const fileName &meshPath, const word &meshFile="faces", const bool verbose=true)
Check for availability of specified mesh file (default: "faces")
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
void removeEmptyDirs(const fileName &path)
Remove empty directories from bottom up.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
dynamicFvMesh & mesh
Miscellaneous file handling for meshes.
void removeEmptyDir(const fileName &path)
Remove empty directory.
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
Definition: POSIX.C:1433
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:877
messageStream Info
Information stream (stdout output on master, null elsewhere)
void removeProcAddressing(const faMesh &mesh)
Remove procAddressing.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
List< fileName > fileNameList
List of fileName.
Definition: fileNameList.H:32
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Definition: POSIX.C:963
List< bool > boolList
A List of bools.
Definition: List.H:60
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition: POSIX.C:1404