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-------------------------------------------------------------------------------
11License
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 (
48 fileHandler().isFile
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
70void Foam::removeProcAddressing(const faMesh& mesh)
71{
72 IOobject ioAddr
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 ioAddr.rename(prefix + word("ProcAddressing"));
83
84 const fileName procFile(ioAddr.objectPath());
85 Foam::rm(procFile);
86 }
87}
88
89
90void Foam::removeProcAddressing(const polyMesh& mesh)
91{
92 IOobject ioAddr
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 ioAddr.rename(prefix + word("ProcAddressing"));
103
104 const fileName procFile(ioAddr.objectPath());
105 Foam::rm(procFile);
106 }
107}
108
109
110bool Foam::removeEmptyDir(const fileName& path)
111{
112 // Return true if empty directory. Note bypass of fileHandler to be
113 // consistent with polyMesh.removeFiles for now.
114
115 {
116 fileNameList files
117 (
119 (
120 path,
121 fileName::FILE,
122 false, // filterGz
123 false // followLink
124 )
125 );
126 if (files.size())
127 {
128 return false;
129 }
130 }
131 {
132 fileNameList dirs
133 (
135 (
136 path,
137 fileName::DIRECTORY,
138 false, // filterGz
139 false // followLink
140 )
141 );
142 if (dirs.size())
143 {
144 return false;
145 }
146 }
147 {
148 fileNameList links
149 (
151 (
152 path,
153 fileName::SYMLINK,
154 false, // filterGz
155 false // followLink
156 )
157 );
158 if (links.size())
159 {
160 return false;
161 }
162 }
163 {
164 fileNameList other
165 (
167 (
168 path,
169 fileName::UNDEFINED,
170 false, // filterGz
171 false // followLink
172 )
173 );
174 if (other.size())
175 {
176 return false;
177 }
178 }
179
180 // Avoid checking success of deletion since initial path might not
181 // exist (e.g. contain 'region0'). Will stop when trying to delete
182 // parent directory anyway since now not empty.
183 Foam::rm(path);
184 return true;
185}
186
187
188void Foam::removeEmptyDirs(const fileName& meshPath)
189{
190 // Delete resulting directory if empty
191 fileName path(meshPath);
192 path.clean();
193
194 // Do subdirectories
195 {
196 const fileNameList dirs
197 (
199 (
200 path,
201 fileName::DIRECTORY,
202 false, // filterGz
203 false // followLink
204 )
205 );
206 for (const auto& dir : dirs)
207 {
209 }
210 }
211
213}
214
215
216// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
dynamicFvMesh & mesh
engineTime & runTime
Miscellaneous file handling for meshes.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition: MSwindows.C:1012
const fileOperation & fileHandler()
Get current file handler.
List< fileName > fileNameList
A List of fileNames.
Definition: fileNameList.H:58
bool removeEmptyDir(const fileName &path)
Remove empty directory. Return true if removed.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void removeEmptyDirs(const fileName &path)
Remove empty directories from bottom up.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
void removeProcAddressing(const faMesh &mesh)
Remove procAddressing.
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")
List< bool > boolList
A List of bools.
Definition: List.H:64
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Definition: MSwindows.C:715
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53