coordinateSystemNew.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) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2018-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 "objectRegistry.H"
30#include "cartesianCS.H"
31#include "indirectCS.H"
32
33// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
34
35namespace Foam
36{
37
38// Handle a 'coordinateSystem' sub-dictionary
39// In 1806 and earlier, this was handled (rather poorly) in the
40// coordinateSystem constructor itself.
42(
43 const word& entryName,
44 const dictionary* dictPtr
45)
46{
47 if (entryName.empty() || !dictPtr)
48 {
49 return nullptr;
50 }
51
52 const auto finder = dictPtr->csearch(entryName, keyType::LITERAL);
53
54 if (finder.good())
55 {
56 if (finder.isDict())
57 {
58 return finder.dictPtr();
59 }
60 else
61 {
62 const word csName(finder.ref().stream());
63
64 // Deprecated, unsupported syntax
65 if (error::master())
66 {
67 std::cerr
68 << "--> FOAM IOWarning :" << nl
69 << " Ignoring '" << entryName << "' as a keyword."
70 " Perhaps you meant this instead?" << nl
71 << '{' << nl
72 << " type " << coordSystem::indirect::typeName_()
73 << ';' << nl
74 << " name " << csName << ';' << nl
75 << '}' << nl
76 << std::endl;
77
78 error::warnAboutAge("syntax change", 1806);
79 }
80 }
81 }
82
83 return dictPtr;
84}
85
86} // End namespace Foam
87
88
89// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90
92(
93 word modelType,
94 const objectRegistry& obr,
95 const dictionary& dict
96)
97{
98 if (modelType.empty())
99 {
100 modelType = coordSystem::cartesian::typeName_();
101 }
102
103 {
104 auto* ctorPtr = registryConstructorTable(modelType);
105 if (ctorPtr)
106 {
107 return autoPtr<coordinateSystem>(ctorPtr(obr, dict));
108 }
109 }
110
111 auto* ctorPtr = dictionaryConstructorTable(modelType);
112
113 // Everything with a registry constructor also has a dictionary
114 // constructor, so just need to print those.
115 if (!ctorPtr)
116 {
118 (
119 dict,
120 "coordinate system",
121 modelType,
122 *dictionaryConstructorTablePtr_
123 ) << exit(FatalIOError);
124 }
125
126 return autoPtr<coordinateSystem>(ctorPtr(dict));
127}
128
129
131(
132 word modelType,
133 const dictionary& dict
134)
135{
136 if (modelType.empty())
137 {
138 modelType = coordSystem::cartesian::typeName_();
139 }
140
141 auto* ctorPtr = dictionaryConstructorTable(modelType);
142
143 if (!ctorPtr)
144 {
146 (
147 dict,
148 "coordinate system",
149 modelType,
150 *dictionaryConstructorTablePtr_
151 ) << exit(FatalIOError);
152 }
153
154 return autoPtr<coordinateSystem>(ctorPtr(dict));
155}
156
157
159(
160 const objectRegistry& obr,
161 const dictionary& dict,
162 const word& dictName
163)
164{
165 const dictionary* dictPtr = &dict;
166
167 if (dictName.size())
168 {
169 dictPtr = &(dictPtr->subDict(dictName));
170 }
171 else
172 {
173 // Fallback: 'coordinateSystem' subDict if present
174 dictPtr = subDictCompat(coordinateSystem::typeName_(), dictPtr);
175 }
176
177 word modelType = dictPtr->getOrDefault<word>
178 (
179 "type",
180 coordSystem::cartesian::typeName_()
181 );
182
183 return coordinateSystem::New(modelType, obr, *dictPtr);
184}
185
186
188(
189 const dictionary& dict,
190 const word& dictName
191)
192{
193 const dictionary* dictPtr = &dict;
194
195 if (dictName.size())
196 {
197 dictPtr = &(dictPtr->subDict(dictName));
198 }
199 else
200 {
201 // Fallback: 'coordinateSystem' subDict if present
202 dictPtr = subDictCompat(coordinateSystem::typeName_(), dictPtr);
203 }
204
205 const word modelType = dictPtr->getOrDefault<word>
206 (
207 "type",
208 coordSystem::cartesian::typeName_()
209 );
210
211 return coordinateSystem::New(modelType, *dictPtr);
212}
213
214
216{
217 const word csName(is);
218 const dictionary dict(is);
219
221 cs->rename(csName);
222
223 return cs;
224}
225
226
227// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
dict_pointer dictPtr() const noexcept
Pointer to the found entry as a dictionary, nullptr otherwise.
Definition: dictionary.H:237
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
const_searcher csearch(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
static bool warnAboutAge(const int version) noexcept
Test if an age warning should be emitted.
Definition: error.C:55
@ LITERAL
String literal.
Definition: keyType.H:81
Registry of regIOobjects.
splitCell * master() const
Definition: splitCell.H:113
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
static const dictionary * subDictCompat(const word &entryName, const dictionary *dictPtr)
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict