regionFunctionObject.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) 2016-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 #include "regionFunctionObject.H"
27 #include "Time.H"
28 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
36  defineTypeNameAndDebug(regionFunctionObject, 0);
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
42 
44 (
45  const word& fieldName
46 )
47 {
48  if (obr_.foundObject<regIOobject>(fieldName))
49  {
50  const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
51 
52  Log << " functionObjects::" << type() << " " << name()
53  << " writing field: " << field.name() << endl;
54 
55  field.write();
56 
57  return true;
58  }
59  else
60  {
61  return false;
62  }
63 }
64 
65 
67 (
68  const word& fieldName
69 )
70 {
71  if (foundObject<regIOobject>(fieldName))
72  {
73  regIOobject& resultObject = lookupObjectRef<regIOobject>(fieldName);
74 
75  if (resultObject.ownedByRegistry())
76  {
77  return resultObject.checkOut();
78  }
79  else
80  {
81  return false;
82  }
83  }
84  else
85  {
86  return true;
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
93 Foam::functionObjects::regionFunctionObject::regionFunctionObject
94 (
95  const word& name,
96  const Time& runTime,
97  const dictionary& dict
98 )
99 :
100  functionObject(name),
101  time_(runTime),
102  obr_
103  (
105  (
107  )
108  )
109 {}
110 
111 
112 Foam::functionObjects::regionFunctionObject::regionFunctionObject
113 (
114  const word& name,
115  const objectRegistry& obr,
116  const dictionary& dict
117 )
118 :
119  functionObject(name),
120  time_(obr.time()),
121  obr_(obr)
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
126 
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 {
135  return functionObject::read(dict);
136 }
137 
138 
139 // ************************************************************************* //
const word & name() const
Return name.
Definition: IOobject.H:297
bool writeObject(const word &fieldName)
Write field if present in objectRegistry.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:309
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Abstract base-class for Time/database function objects.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:28
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual bool read(const dictionary &)
Read optional controls.
A class for handling words, derived from string.
Definition: word.H:59
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:210
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
const Time & time() const
Return time.
bool clearObject(const word &fieldName)
Clear field from the objectRegistry if present.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:65
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Registry of regIOobjects.
virtual bool write(const bool valid=true) const
Write using setting from DB.
Namespace for OpenFOAM.