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-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
14  Search for the appropriate faMeshDefinition dictionary...
15 
16 Required Classes
17  - Foam::polyMesh
18  - Foam::IOdictionary
19 
20 Required Variables
21  - regionName [word]
22  - args [argList]
23  - runTime [Time]
24 
25 Provided Variables
26  - meshDefDict [IOdictionary]
27  - meshDictPtr [autoPtr<IOdictionary>]
28 
29 \*---------------------------------------------------------------------------*/
30 
31 const word dictName("faMeshDefinition");
32 
33 autoPtr<IOdictionary> meshDictPtr;
34 
35 {
36  fileName dictPath;
38 
39  if (args.readIfPresent("dict", dictPath))
40  {
41  // Dictionary specified on the command-line ...
42 
43  if (isDir(dictPath))
44  {
45  dictPath /= dictName;
46  }
47  }
48  else if
49  (
50  // Check global location
51  exists
52  (
53  runTime.path()/runTime.caseConstant()
54  / regionDir/faMesh::meshSubDir/dictName
55  )
56  )
57  {
58  // Dictionary present in constant faMesh directory (old-style)
59 
60  dictPath =
61  (
62  runTime.constant()
63  / regionDir/faMesh::meshSubDir/dictName
64  );
65 
66  // Warn that constant/faMesh/faMeshDefinition was used
67  // instead of system/faMeshDefinition
68  #if 0
70  << "Using the old faMeshDefinition location: "
71  << dictPath << nl
72  << " instead of default location: "
73  << runTime.system()/regionDir/dictName << nl
74  << endl;
75  #endif
76  }
77  else
78  {
79  // Assume dictionary is in the system directory
80 
81  dictPath = runTime.system()/regionDir/dictName;
82  }
83 
84  IOobject meshDictIO
85  (
86  dictPath,
87  runTime,
88  IOobject::MUST_READ,
89  IOobject::NO_WRITE,
90  IOobject::NO_REGISTER,
91  true // is globalObject
92  );
93 
94  if (!meshDictIO.typeHeaderOk<IOdictionary>(true))
95  {
97  << meshDictIO.objectPath() << nl
98  << exit(FatalError);
99  }
100 
101  Info<< "Creating faMesh from definition: "
102  << meshDictIO.objectRelPath() << endl;
105 }
106 
107 IOdictionary& meshDefDict = *meshDictPtr;
108 
109 
110 // ************************************************************************* //
#define WarningIn(functionName)
Report a warning using Foam::Warning.
IOdictionary & meshDefDict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
Definition: polyMesh.C:847
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const word dictName("faMeshDefinition")
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:860
const word & executable() const noexcept
Name of executable without the path.
Definition: argListI.H:44
autoPtr< IOdictionary > meshDictPtr
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:835
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
const word & regionDir
IOobject meshDictIO(dictPath, runTime, IOobject::MUST_READ, IOobject::NO_WRITE, IOobject::NO_REGISTER, true)
messageStream Info
Information stream (stdout output on master, null elsewhere)
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:316
Foam::argList args(argc, argv)