functionObjectState.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 | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 #include "functionObjectState.H"
27 #include "Time.H"
28 
30 
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 (
36  const objectRegistry& obr,
37  const word& name
38 )
39 :
40  obr_(obr),
41  name_(name),
42  active_(true),
43  stateDict_
44  (
45  const_cast<IOdictionary&>(obr.time().functionObjects().stateDict())
46  )
47 {}
48 
49 
50 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
51 
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
59 {
60  return name_;
61 }
62 
63 
65 {
66  return active_;
67 }
68 
69 
71 {
72  return stateDict_;
73 }
74 
75 
77 {
78  if (!stateDict_.found(name_))
79  {
80  stateDict_.add(name_, dictionary());
81  }
82 
83  return stateDict_.subDict(name_);
84 }
85 
86 
87 bool Foam::functionObjectState::foundProperty(const word& entryName) const
88 {
89  if (stateDict_.found(name_))
90  {
91  const dictionary& baseDict = stateDict_.subDict(name_);
92  return baseDict.found(entryName);
93  }
94 
95  return false;
96 }
97 
98 
100 {
101  return objectResultType(name_, entryName);
102 }
103 
104 
106 (
107  const word& objectName,
108  const word& entryName
109 ) const
110 {
111  word result = word::null;
112 
113  if (stateDict_.found(resultsName_))
114  {
115  const dictionary& resultsDict = stateDict_.subDict(resultsName_);
116 
117  if (resultsDict.found(objectName))
118  {
119  const dictionary& objectDict = resultsDict.subDict(objectName);
120 
121  forAllConstIter(dictionary, objectDict, iter)
122  {
123  const dictionary& dict = iter().dict();
124 
125  if (dict.found(entryName))
126  {
127  return dict.dictName();
128  }
129  }
130  }
131  }
132 
133  return result;
134 }
135 
136 
138 {
139  return objectResultEntries(name_);
140 }
141 
142 
144 (
145  const word& objectName
146 ) const
147 {
148  DynamicList<word> result(2);
149 
150  if (stateDict_.found(resultsName_))
151  {
152  const dictionary& resultsDict = stateDict_.subDict(resultsName_);
153 
154  if (resultsDict.found(objectName))
155  {
156  const dictionary& objectDict = resultsDict.subDict(objectName);
157 
158  forAllConstIter(dictionary, objectDict, iter)
159  {
160  const dictionary& dict = iter().dict();
161  result.append(dict.toc());
162  }
163  }
164  }
165 
166  wordList entries;
167  entries.transfer(result);
168 
169  return entries;
170 }
171 
172 
173 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::dictionaryName::dictName
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::DynamicList< word >
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::functionObjectState::~functionObjectState
virtual ~functionObjectState()
Destructor.
Definition: functionObjectState.C:52
functionObjectState.H
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::Time::functionObjects
const functionObjectList & functionObjects() const
Return the list of function objects.
Definition: Time.H:435
Foam::functionObjectState::objectResultType
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
Definition: functionObjectState.C:106
Foam::functionObjectState::resultType
word resultType(const word &entryName) const
Retrieve the result type.
Definition: functionObjectState.C:99
Foam::functionObjectList::stateDict
IOdictionary & stateDict()
Return the state dictionary.
Definition: functionObjectList.C:127
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::functionObjectState::functionObjectState
functionObjectState(const functionObjectState &)
Disallow default bitwise copy construct.
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::functionObjectState::active
bool active() const
Return the active flag.
Definition: functionObjectState.C:64
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::functionObjectState::resultsName_
static const word resultsName_
Name of the results dictionary.
Definition: functionObjectState.H:61
Foam::List< Foam::word >
Foam::functionObjectState::propertyDict
dictionary & propertyDict()
Return access to the property dictionary.
Definition: functionObjectState.C:76
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::functionObjectState::foundProperty
bool foundProperty(const word &entryName) const
Return true if the property exists.
Definition: functionObjectState.C:87
Foam::functionObjectState::objectResultEntries
List< word > objectResultEntries() const
Retrieve the result entries.
Definition: functionObjectState.C:137
Foam::functionObjectState::stateDict
const IOdictionary & stateDict() const
Return access to the state dictionary.
Definition: functionObjectState.C:70
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::functionObjectState::name
const word & name() const
Return the name.
Definition: functionObjectState.C:58
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729