subModelBaseTemplates.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) 2013-2015 OpenFOAM Foundation
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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const word& entryName,
34  const Type& defaultValue
35 ) const
36 {
37  Type result = defaultValue;
38 
40  {
41  const dictionary& baseDict = properties_.subDict(baseName_);
42  baseDict.readIfPresent(entryName, result);
43  }
44 
45  return result;
46 }
47 
48 
49 template<class Type>
51 (
52  const word& entryName,
53  Type& value
54 ) const
55 {
56  if (properties_.found(baseName_))
57  {
58  const dictionary& baseDict = properties_.subDict(baseName_);
59  baseDict.readIfPresent(entryName, value);
60  }
61 }
62 
63 
64 template<class Type>
66 (
67  const word& entryName,
68  const Type& value
69 )
70 {
71  if (properties_.found(baseName_))
72  {
73  dictionary& baseDict = properties_.subDict(baseName_);
74  baseDict.add(entryName, value, true);
75  }
76  else
77  {
78  properties_.add(baseName_, dictionary());
79  properties_.subDict(baseName_).add(entryName, value);
80  }
81 }
82 
83 
84 template<class Type>
86 (
87  const word& entryName,
88  Type& value
89 ) const
90 {
91  if (properties_.found(baseName_))
92  {
93  const dictionary& baseDict = properties_.subDict(baseName_);
94 
95  if (inLine() && baseDict.found(modelName_))
96  {
97  return baseDict.subDict(modelName_).readIfPresent(entryName, value);
98  }
99  else if (baseDict.found(modelType_))
100  {
101  return baseDict.subDict(modelType_).readIfPresent(entryName, value);
102  }
103  }
105  return false;
106 }
107 
108 
109 template<class Type>
111 (
112  const word& entryName,
113  const Type& defaultValue
114 ) const
115 {
116  Type result = defaultValue;
117  getModelProperty(entryName, result);
118  return result;
119 }
120 
121 
122 template<class Type>
124 (
125  const word& entryName,
126  const Type& value
127 )
128 {
129  if (properties_.found(baseName_))
130  {
131  dictionary& baseDict = properties_.subDict(baseName_);
132 
133  if (inLine())
134  {
135  if (baseDict.found(modelName_))
136  {
137  baseDict.subDict(modelName_).add(entryName, value, true);
138  }
139  else
140  {
141  baseDict.add(modelName_, dictionary());
142  baseDict.subDict(modelName_).add(entryName, value, true);
143  }
144  }
145  else
146  {
147  if (baseDict.found(modelType_))
148  {
149  baseDict.subDict(modelType_).add(entryName, value, true);
150  }
151  else
152  {
153  baseDict.add(modelType_, dictionary());
154  baseDict.subDict(modelType_).add(entryName, value, true);
155  }
156  }
157  }
158  else
159  {
160  properties_.add(baseName_, dictionary());
161 
162  if (inLine())
163  {
164  properties_.subDict(baseName_).add(modelName_, dictionary());
165  properties_.subDict(baseName_).subDict(modelName_).add
166  (
167  entryName,
168  value
169  );
170  }
171  else
172  {
173  properties_.subDict(baseName_).add(modelType_, dictionary());
174  properties_.subDict(baseName_).subDict(modelType_).add
175  (
176  entryName,
177  value
178  );
179  }
180  }
181 }
182 
183 
184 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Type getBaseProperty(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from the base model.
dictionary & properties_
Reference to properties dictionary e.g. for restart.
Definition: subModelBase.H:72
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:625
const word baseName_
Name of the sub-model base class.
Definition: subModelBase.H:82
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
void setModelProperty(const word &entryName, const Type &value)
Add generic property to the sub-model.
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool getModelProperty(const word &entryName, Type &value) const
Retrieve generic property from the sub-model.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
void setBaseProperty(const word &entryName, const Type &value)
Add generic property to the base model.