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-2021 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  if (error::master())
60  {
61  std::cerr
62  << "--> FOAM IOWarning :" << nl
63  << " Ignoring 'coordinateSystem' as a keyword."
64  " Perhaps you meant this instead?" << nl
65  << '{' << nl
66  << " type " << coordSystem::indirect::typeName_()
67  << ';' << nl
68  << " name " << csName << ';' << nl
69  << '}' << nl
70  << std::endl;
71 
72  error::warnAboutAge("syntax change", 1806);
73  }
74  }
75  }
76 
77  return dictPtr;
78 }
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 (
85  word modelType,
86  const objectRegistry& obr,
87  const dictionary& dict
88 )
89 {
90  if (modelType.empty())
91  {
92  modelType = coordSystem::cartesian::typeName_();
93  }
94 
95  {
96  auto* ctorPtr = registryConstructorTable(modelType);
97  if (ctorPtr)
98  {
99  return autoPtr<coordinateSystem>(ctorPtr(obr, dict));
100  }
101  }
102 
103  auto* ctorPtr = dictionaryConstructorTable(modelType);
104 
105  // Everything with a registry constructor also has a dictionary
106  // constructor, so just need to print those.
107  if (!ctorPtr)
108  {
110  (
111  dict,
112  "coordinate system",
113  modelType,
114  *dictionaryConstructorTablePtr_
115  ) << exit(FatalIOError);
116  }
117 
118  return autoPtr<coordinateSystem>(ctorPtr(dict));
119 }
120 
121 
123 (
124  word modelType,
125  const dictionary& dict
126 )
127 {
128  if (modelType.empty())
129  {
130  modelType = coordSystem::cartesian::typeName_();
131  }
132 
133  auto* ctorPtr = dictionaryConstructorTable(modelType);
134 
135  if (!ctorPtr)
136  {
138  (
139  dict,
140  "coordinate system",
141  modelType,
142  *dictionaryConstructorTablePtr_
143  ) << exit(FatalIOError);
144  }
145 
146  return autoPtr<coordinateSystem>(ctorPtr(dict));
147 }
148 
149 
151 (
152  const objectRegistry& obr,
153  const dictionary& dict,
154  const word& dictName
155 )
156 {
157  const dictionary* dictPtr = &dict;
158 
159  if (dictName.size())
160  {
161  dictPtr = &(dictPtr->subDict(dictName));
162  }
163  else
164  {
165  // Use 'coordinateSystem' subDict if present
166  dictPtr = coordinateSystem::subDictCompat(dictPtr);
167  }
168 
169  word modelType = dictPtr->getOrDefault<word>
170  (
171  "type",
172  coordSystem::cartesian::typeName_()
173  );
174 
175  return coordinateSystem::New(modelType, obr, *dictPtr);
176 }
177 
178 
180 (
181  const dictionary& dict,
182  const word& dictName
183 )
184 {
185  const dictionary* dictPtr = &dict;
186 
187  if (dictName.size())
188  {
189  dictPtr = &(dictPtr->subDict(dictName));
190  }
191  else
192  {
193  // Use 'coordinateSystem' subDict if present
194  dictPtr = coordinateSystem::subDictCompat(dictPtr);
195  }
196 
197  const word modelType = dictPtr->getOrDefault<word>
198  (
199  "type",
200  coordSystem::cartesian::typeName_()
201  );
202 
203  return coordinateSystem::New(modelType, *dictPtr);
204 }
205 
206 
208 {
209  const word csName(is);
210  const dictionary dict(is);
211 
213  cs->rename(csName);
214 
215  return cs;
216 }
217 
218 
219 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
dictName
const word dictName("faMeshDefinition")
objectRegistry.H
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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:478
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:84
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:460
Foam::dictionary::Searcher::dictPtr
dict_pointer dictPtr() const noexcept
Pointer to the found entry as a dictionary, nullptr otherwise.
Definition: dictionary.H:237
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:123
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::autoPtr< Foam::coordinateSystem >
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::error::master
static bool master(const label communicator=-1)
Definition: error.C:41
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::error::warnAboutAge
static bool warnAboutAge(const int version) noexcept
Test if an age warning should be emitted.
Definition: error.C:55
Foam::keyType::LITERAL
String literal.
Definition: keyType.H:81
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148