PatchFunction1New.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) 2018-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "ConstantField.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const polyPatch& pp,
36  const word& entryName,
37  const dictionary& dict,
38  const bool faceValues
39 )
40 {
41  const entry* eptr = dict.findEntry(entryName, keyType::LITERAL);
42 
43  if (!eptr)
44  {
46  << "No PatchFunction1 dictionary entry: "
47  << entryName << nl << nl
48  << exit(FatalIOError);
49 
50  return nullptr;
51  }
52  else if (eptr->isDict())
53  {
54  const dictionary& coeffsDict = eptr->dict();
55 
56  const word modelType(coeffsDict.getWord("type", keyType::LITERAL));
57 
58  auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
59 
60  if (!cstrIter.found())
61  {
62  FatalIOErrorInFunction(coeffsDict)
63  << "Unknown PatchFunction1 type "
64  << modelType << " for " << entryName
65  << "\n\nValid PatchFunction1 types :\n"
66  << dictionaryConstructorTablePtr_->sortedToc() << nl
67  << exit(FatalIOError);
68  }
69 
70  return cstrIter()(pp, modelType, entryName, coeffsDict, faceValues);
71  }
72  else
73  {
74  ITstream& is = eptr->stream();
75 
76  token firstToken(is);
77 
78  if (!firstToken.isWord())
79  {
80  // Backwards-compatibility for reading straight fields
81  is.putBack(firstToken);
82 
83  const Type uniformValue = pTraits<Type>(is);
84  const Field<Type> value
85  (
86  (faceValues ? pp.size() : pp.nPoints()),
88  );
89 
91  (
93  (
94  pp,
95  entryName,
96  true, // uniform
97  uniformValue, // uniform value
98  value, // Supply value
99  dict,
100  faceValues
101  )
102  );
103  }
104 
105  const word modelType = firstToken.wordToken();
106 
107  // Check to see if this looks like a normal field entry
108  if (modelType == "uniform" || modelType == "nonuniform")
109  {
111  (
113  (
114  pp,
116  entryName,
117  dict,
118  faceValues
119  )
120  );
121  }
122 
123 
124  auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
125 
126  if (!cstrIter.found())
127  {
129  << "Unknown PatchFunction1 type "
130  << modelType << " for " << entryName
131  << "\n\nValid PatchFunction1 types :\n"
132  << dictionaryConstructorTablePtr_->sortedToc() << nl
133  << exit(FatalIOError);
134  }
135 
136  return cstrIter()
137  (
138  pp,
139  modelType,
140  entryName,
141  dict.optionalSubDict(entryName + "Coeffs"),
142  faceValues
143  );
144  }
145 }
146 
147 
148 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
ConstantField.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::entry::stream
virtual ITstream & stream() const =0
Return token stream, if entry is a primitive entry.
Foam::PatchFunction1::New
static autoPtr< PatchFunction1< Type > > New(const polyPatch &pp, const word &entryName, const dictionary &dict, const bool faceValues=true)
Selector.
Definition: PatchFunction1New.C:34
Foam::PatchFunction1Types::ConstantField
Templated function that returns a constant value.
Definition: ConstantField.H:58
Foam::FatalIOError
IOerror FatalIOError
Foam::token
A token holds an item read from Istream.
Definition: token.H:69
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::entry::isDict
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:222
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:55
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatch.H:311
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::token::isWord
bool isWord() const
Token is WORD.
Definition: tokenI.H:552
Foam::dictionary::getWord
word getWord(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< word >(const word&, keyType::option)
Definition: dictionary.H:1490
Foam::entry::dict
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
Foam::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.H:558
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::pTraits< Type >
Foam::Istream::putBack
void putBack(const token &tok)
Put back token.
Definition: Istream.C:53
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
Foam::uniformValue
Definition: uniformValue.H:50