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 
39  if (properties_.found(baseName_))
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  baseDict.subDict(modelName_).readIfPresent(entryName, value);
98  }
99  else if (baseDict.found(modelType_))
100  {
101  baseDict.subDict(modelType_).readIfPresent(entryName, value);
102  }
103  }
104 }
105 
106 
107 template<class Type>
109 (
110  const word& entryName,
111  const Type& defaultValue
112 ) const
113 {
114  Type result = defaultValue;
115  getModelProperty(entryName, result);
116  return result;
117 }
118 
119 
120 template<class Type>
122 (
123  const word& entryName,
124  const Type& value
125 )
126 {
127  if (properties_.found(baseName_))
128  {
129  dictionary& baseDict = properties_.subDict(baseName_);
130 
131  if (inLine())
132  {
133  if (baseDict.found(modelName_))
134  {
135  baseDict.subDict(modelName_).add(entryName, value, true);
136  }
137  else
138  {
139  baseDict.add(modelName_, dictionary());
140  baseDict.subDict(modelName_).add(entryName, value, true);
141  }
142  }
143  else
144  {
145  if (baseDict.found(modelType_))
146  {
147  baseDict.subDict(modelType_).add(entryName, value, true);
148  }
149  else
150  {
151  baseDict.add(modelType_, dictionary());
152  baseDict.subDict(modelType_).add(entryName, value, true);
153  }
154  }
155  }
156  else
157  {
158  properties_.add(baseName_, dictionary());
159 
160  if (inLine())
161  {
162  properties_.subDict(baseName_).add(modelName_, dictionary());
163  properties_.subDict(baseName_).subDict(modelName_).add
164  (
165  entryName,
166  value
167  );
168  }
169  else
170  {
171  properties_.subDict(baseName_).add(modelType_, dictionary());
172  properties_.subDict(baseName_).subDict(modelType_).add
173  (
174  entryName,
175  value
176  );
177  }
178  }
179 }
180 
181 
182 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::subModelBase::getModelProperty
void getModelProperty(const word &entryName, Type &value) const
Retrieve generic property from the sub-model.
Definition: subModelBaseTemplates.C:86
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Foam::subModelBase::getBaseProperty
Type getBaseProperty(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property from the base model.
Definition: subModelBaseTemplates.C:32
Foam::subModelBase::setModelProperty
void setModelProperty(const word &entryName, const Type &value)
Add generic property to the sub-model.
Definition: subModelBaseTemplates.C:122
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
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::subModelBase::setBaseProperty
void setBaseProperty(const word &entryName, const Type &value)
Add generic property to the base model.
Definition: subModelBaseTemplates.C:66
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405