Loading...
Searching...
No Matches
findMeshDefinitionDict.H
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) 2021-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13Description
14 Search for the appropriate faMeshDefinition dictionary...
15
16 Expects to find a faMeshDefinition file in a location specified
17 by the command-line option, or one of the standard locations.
18
19 For default area region (region0):
20 (1) system/finite-area/faMeshDefinition
21 (2) system/faMeshDefinition [legacy location - v2312 and earlier]
22
23 For a named area region:
24 (1) system/finite-area/<area-name>/faMeshDefinition
25 (2) system/finite-area/faMeshDefinition.<area-name>
26 [symmetric with faOptions]
27
28Required Classes
29 - Foam::polyMesh
30 - Foam::IOdictionary
31
32Required Variables
33 - regionName [word] (the polyMesh region)
34 - areaRegionName [word] (the areaMesh region)
35 - args [argList]
36 - runTime [Time]
37
38Provided Variables
39 - faMeshDefinitionPtr [autoPtr<IOdictionary>]
40
41If the dictionary cannot be found, exits with an error message or
42reports a warning (dry-run mode)
43
44\*---------------------------------------------------------------------------*/
46const word dictName("faMeshDefinition");
47
48autoPtr<IOdictionary> faMeshDefinitionPtr;
49
50{
51 // Exit unless dry-run?
52 const bool exitOnFailure = (!args.dryRun());
54 const word& regionDir = polyMesh::regionName(regionName);
55 const word& areaRegionDir = polyMesh::regionName(areaRegionName);
56
57 // Canonical location
58 fileName dictPath
59 (
60 runTime.system()/regionDir
61 / faMesh::prefix()/areaRegionDir/dictName
62 );
63
65 // Dictionary specified on the command-line ...
66 const bool specified = args.readIfPresent("dict", dictPath);
67
68 if (specified)
69 {
70 if (isDir(dictPath))
71 {
73 }
74 }
75
77 IOobject meshDictIO
78 (
80 runTime,
81 IOobjectOption::MUST_READ,
82 IOobjectOption::NO_WRITE,
83 IOobjectOption::NO_REGISTER,
84 true // is globalObject
85 );
86
87 refPtr<IOobject> meshDictIOPtr;
88
89 bool foundIOobject = meshDictIO.typeHeaderOk<IOdictionary>(true);
90
91 // For reporting any alternative locations
92 dictPath.clear();
93
94 if (!foundIOobject && !specified)
95 {
96 if (!areaRegionDir.empty())
97 {
98 // Alternative location
99 // - system/finite-area/faMeshDefinition.<area-name>
100
101 dictPath =
102 (
103 runTime.system()/regionDir
104 / faMesh::prefix()/IOobject::groupName(dictName, areaRegionDir)
105 );
106 }
107 else
108 {
109 // legacy location (v2312 and earlier)
110 // - system/faMeshDefinition
111
113 }
114
115 if (!dictPath.empty())
116 {
117 auto ioptr = autoPtr<IOobject>::New
118 (
119 dictPath,
120 runTime,
121 IOobjectOption::MUST_READ,
122 IOobjectOption::NO_WRITE,
123 IOobjectOption::NO_REGISTER,
124 true // is globalObject
125 );
126
128 (
129 ioptr && ioptr->typeHeaderOk<IOdictionary>(true)
130 );
131
132 if (foundIOobject)
133 {
134 // Use if found
135 meshDictIOPtr = std::move(ioptr);
136 }
137
138 // Generally retain dictPath for error messages,
139 // but don't mention the really old legacy location
140 if (areaRegionDir.empty())
141 {
142 dictPath.clear();
144 }
145 }
146
147 // Alternative location or regular location?
148 if (!meshDictIOPtr)
149 {
151 }
152 const auto& io = meshDictIOPtr();
153
154
155 // Handle final success or failure
156 if (foundIOobject)
157 {
158 Info<< "----------------" << nl
159 << "Using area-mesh definition";
160 if (!areaRegionDir.empty())
161 {
162 Info<< " [" << areaRegionName << "]";
163 }
164
165 Info<< nl
166 << " " << io.objectRelPath() << nl << endl;
167
168 faMeshDefinitionPtr = autoPtr<IOdictionary>::New(io);
169 }
170 else
171 {
172 // Failure
173
174 if (exitOnFailure)
175 {
176 auto& err =
178 << "Did not find area-mesh definition";
179
180 if (!areaRegionDir.empty())
181 {
182 err<< " [" << areaRegionName << "]";
183 }
184
185 err << nl
186 << " " << io.objectRelPath() << nl;
187
188 if (!dictPath.empty())
189 {
190 err << " " << dictPath << nl;
191 }
192
193 FatalError<< exit(FatalError);
194 }
195 else
196 {
197 // dry-run: warning
198 auto& err =
199 Warning << nl
200 << "----------------" << nl
201 << "Did not find area-mesh definition";
202
203 if (!areaRegionDir.empty())
204 {
205 err << " [" << areaRegionName << "]";
206 }
207
208 err << nl
209 << " " << io.objectRelPath() << nl;
210
211 if (!dictPath.empty())
212 {
213 err << " " << dictPath << nl;
214 }
215 }
216 }
217}
218
219
220// ************************************************************************* //
engineTime & runTime
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
Foam::word areaRegionName(args.getOrDefault< word >("area-region", Foam::polyMesh::defaultRegion))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const auto & io
const word dictName("faMeshDefinition")
const word & regionDir
const word & areaRegionDir
const bool specified
IOobject meshDictIO(dictPath, runTime, IOobjectOption::MUST_READ, IOobjectOption::NO_WRITE, IOobjectOption::NO_REGISTER, true)
refPtr< IOobject > meshDictIOPtr
fileName dictPath(runTime.system()/regionDir/faMesh::prefix()/areaRegionDir/dictName)
autoPtr< IOdictionary > faMeshDefinitionPtr
bool foundIOobject
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
messageStream Warning
Warning stream (stdout output on master, null elsewhere), with additional 'FOAM Warning' header text.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)