subModelBaseTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
27 
28 template<class Type>
30 (
31  const word& entryName,
32  const Type& defaultValue
33 ) const
34 {
35  Type result = defaultValue;
36 
38  {
39  const dictionary& baseDict = properties_.subDict(baseName_);
40  baseDict.readIfPresent(entryName, result);
41  }
42 
43  return result;
44 }
45 
46 
47 template<class Type>
49 (
50  const word& entryName,
51  Type& value
52 ) const
53 {
54  if (properties_.found(baseName_))
55  {
56  const dictionary& baseDict = properties_.subDict(baseName_);
57  baseDict.readIfPresent(entryName, value);
58  }
59 }
60 
61 
62 template<class Type>
64 (
65  const word& entryName,
66  const Type& value
67 )
68 {
69  if (properties_.found(baseName_))
70  {
71  dictionary& baseDict = properties_.subDict(baseName_);
72  baseDict.add(entryName, value, true);
73  }
74  else
75  {
76  properties_.add(baseName_, dictionary());
77  properties_.subDict(baseName_).add(entryName, value);
78  }
79 }
80 
81 
82 template<class Type>
84 (
85  const word& entryName,
86  Type& value
87 ) const
88 {
89  if (properties_.found(baseName_))
90  {
91  const dictionary& baseDict = properties_.subDict(baseName_);
92 
93  if (inLine() && baseDict.found(modelName_))
94  {
95  baseDict.subDict(modelName_).readIfPresent(entryName, value);
96  }
97  else if (baseDict.found(modelType_))
98  {
99  baseDict.subDict(modelType_).readIfPresent(entryName, value);
100  }
101  }
102 }
103 
104 
105 template<class Type>
107 (
108  const word& entryName,
109  const Type& defaultValue
110 ) const
111 {
112  Type result = defaultValue;
113  getModelProperty(entryName, result);
114  return result;
115 }
116 
117 
118 template<class Type>
120 (
121  const word& entryName,
122  const Type& value
123 )
124 {
125  if (properties_.found(baseName_))
126  {
127  dictionary& baseDict = properties_.subDict(baseName_);
128 
129  if (inLine())
130  {
131  if (baseDict.found(modelName_))
132  {
133  baseDict.subDict(modelName_).add(entryName, value, true);
134  }
135  else
136  {
137  baseDict.add(modelName_, dictionary());
138  baseDict.subDict(modelName_).add(entryName, value, true);
139  }
140  }
141  else
142  {
143  if (baseDict.found(modelType_))
144  {
145  baseDict.subDict(modelType_).add(entryName, value, true);
146  }
147  else
148  {
149  baseDict.add(modelType_, dictionary());
150  baseDict.subDict(modelType_).add(entryName, value, true);
151  }
152  }
153  }
154  else
155  {
156  properties_.add(baseName_, dictionary());
157 
158  if (inLine())
159  {
160  properties_.subDict(baseName_).add(modelName_, dictionary());
161  properties_.subDict(baseName_).subDict(modelName_).add
162  (
163  entryName,
164  value
165  );
166  }
167  else
168  {
169  properties_.subDict(baseName_).add(modelType_, dictionary());
170  properties_.subDict(baseName_).subDict(modelType_).add
171  (
172  entryName,
173  value
174  );
175  }
176  }
177 }
178 
179 
180 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:843
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1014
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:509
Type getBaseProperty(const word &entryName, const Type &defaultValue=pTraits< Type >::zero) const
Retrieve generic property from the base model.
void getModelProperty(const word &entryName, Type &value) const
Retrieve generic property from the sub-model.
const word baseName_
Name of the sub-model base class.
Definition: subModelBase.H:68
void setBaseProperty(const word &entryName, const Type &value)
Add generic property to the base model.
dictionary & properties_
Reference to properties dictionary e.g. for restart.
Definition: subModelBase.H:62
void setModelProperty(const word &entryName, const Type &value)
Add generic property to the sub-model.
A class for handling words, derived from string.
Definition: word.H:62