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-2020 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 "objectRegistry.H"
30 #include "cartesianCS.H"
31 #include "indirectCS.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 
36 //- Handle a 'coordinateSystem' sub-dictionary
37 // In 1806 and earlier, this was handled (rather poorly) in the
38 // coordinateSystem constructor itself.
39 const Foam::dictionary* Foam::coordinateSystem::subDictCompat
40 (
41  const dictionary* dictPtr
42 )
43 {
44  if (dictPtr)
45  {
46  // Non-recursive, no pattern matching in the search
47  const auto finder =
48  dictPtr->csearch(coordinateSystem::typeName_(), keyType::LITERAL);
49 
50  if (finder.isDict())
51  {
52  return finder.dictPtr();
53  }
54  else if (finder.found())
55  {
56  const word csName(finder.ref().stream());
57 
58  // Deprecated, unsupported syntax
59 
60  std::cerr
61  << "--> FOAM IOWarning :" << nl
62  << " Ignoring 'coordinateSystem' as a keyword."
63  " Perhaps you meant this instead?" << nl
64  << '{' << nl
65  << " type " << coordSystem::indirect::typeName_()
66  << ';' << nl
67  << " name " << csName << ';' << nl
68  << '}' << nl
69  << std::endl;
70 
71  error::warnAboutAge("syntax change", 1806);
72  }
73  }
74 
75  return dictPtr;
76 }
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 (
83  word modelType,
84  const objectRegistry& obr,
85  const dictionary& dict
86 )
87 {
88  if (modelType.empty())
89  {
90  modelType = coordSystem::cartesian::typeName_();
91  }
92 
93  auto cstrIter1 = registryConstructorTablePtr_->cfind(modelType);
94 
95  if (cstrIter1.found())
96  {
97  return autoPtr<coordinateSystem>(cstrIter1()(obr, dict));
98  }
99 
100  auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
101 
102  // Everything with a registry constructor also has a dictionary
103  // constructor, so just need to print those.
104  if (!cstrIter.found())
105  {
107  (
108  dict,
109  "coordinate system",
110  modelType,
111  *dictionaryConstructorTablePtr_
112  ) << exit(FatalIOError);
113  }
114 
115  return autoPtr<coordinateSystem>(cstrIter()(dict));
116 }
117 
118 
120 (
121  word modelType,
122  const dictionary& dict
123 )
124 {
125  if (modelType.empty())
126  {
127  modelType = coordSystem::cartesian::typeName_();
128  }
129 
130  auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
131 
132  if (!cstrIter.found())
133  {
135  (
136  dict,
137  "coordinate system",
138  modelType,
139  *dictionaryConstructorTablePtr_
140  ) << exit(FatalIOError);
141  }
142 
143  return autoPtr<coordinateSystem>(cstrIter()(dict));
144 }
145 
146 
148 (
149  const objectRegistry& obr,
150  const dictionary& dict,
151  const word& dictName
152 )
153 {
154  const dictionary* dictPtr = &dict;
155 
156  if (dictName.size())
157  {
158  dictPtr = &(dictPtr->subDict(dictName));
159  }
160  else
161  {
162  // Use 'coordinateSystem' subDict if present
163  dictPtr = coordinateSystem::subDictCompat(dictPtr);
164  }
165 
166  word modelType = dictPtr->getOrDefault<word>
167  (
168  "type",
169  coordSystem::cartesian::typeName_()
170  );
171 
172  return coordinateSystem::New(modelType, obr, *dictPtr);
173 }
174 
175 
177 (
178  const dictionary& dict,
179  const word& dictName
180 )
181 {
182  const dictionary* dictPtr = &dict;
183 
184  if (dictName.size())
185  {
186  dictPtr = &(dictPtr->subDict(dictName));
187  }
188  else
189  {
190  // Use 'coordinateSystem' subDict if present
191  dictPtr = coordinateSystem::subDictCompat(dictPtr);
192  }
193 
194  const word modelType = dictPtr->getOrDefault<word>
195  (
196  "type",
197  coordSystem::cartesian::typeName_()
198  );
199 
200  return coordinateSystem::New(modelType, *dictPtr);
201 }
202 
203 
205 {
206  const word csName(is);
207  const dictionary dict(is);
208 
210  cs->rename(csName);
211 
212  return cs;
213 }
214 
215 
216 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::dictionary::Searcher::dictPtr
dict_pointer dictPtr() const
Pointer to the found entry as a dictionary or nullptr otherwise.
Definition: dictionary.H:234
objectRegistry.H
dictName
const word dictName("blockMeshDict")
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
cartesianCS.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:406
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
indirectCS.H
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
Definition: coordinateSystemNew.C:82
Foam::dictionary::csearch
const_searcher csearch(const word &keyword, enum keyType::option=keyType::REGEX) const
Search dictionary for given keyword.
Definition: dictionarySearch.C:265
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:528
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::autoPtr< Foam::coordinateSystem >
Foam::error::warnAboutAge
static void warnAboutAge(const char *what, const int version)
Emit warning on stderr about something being old.
Definition: error.C:41
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::keyType::LITERAL
String literal.
Definition: keyType.H:73
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:122