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-2024 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 {
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
42 
44 (
45  const word& fieldName
46 )
47 {
48  Warning
49  << " functionObjects::" << type() << " " << name()
50  << " cannot find required object " << fieldName << endl;
51 }
52 
53 
55 (
56  const wordList& fieldNames
57 )
58 {
59  Warning
60  << " functionObjects::" << type() << " " << name()
61  << " cannot find required objects " << fieldNames << endl;
62 }
63 
64 
66 (
67  const word& fieldName
68 )
69 {
70  if (obr_.foundObject<regIOobject>(fieldName))
71  {
72  const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
73 
74  Log << " functionObjects::" << type() << " " << name()
75  << " writing field: " << field.name() << endl;
76 
77  field.write();
78 
79  return true;
80  }
81  else
82  {
83  return false;
84  }
85 }
86 
87 
89 (
90  const word& fieldName
91 )
92 {
93  if (foundObject<regIOobject>(fieldName))
94  {
95  regIOobject& resultObject = lookupObjectRef<regIOobject>(fieldName);
96 
97  if (resultObject.ownedByRegistry())
98  {
99  return resultObject.checkOut();
100  }
101  else
102  {
103  return false;
104  }
105  }
106  else
107  {
108  return true;
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 
116 (
117  const word& name,
118  const Time& runTime,
119  const dictionary& dict
120 )
121 :
122  functionObject(name, runTime),
123  obr_
124  (
125  runTime.lookupObject<objectRegistry>
126  (
127  dict.lookupOrDefault("region", polyMesh::defaultRegion)
128  )
129  )
130 {}
131 
132 
134 (
135  const word& name,
136  const objectRegistry& obr,
137  const dictionary& dict
138 )
139 :
140  functionObject(name, obr.time()),
141  obr_(obr)
142 {}
143 
144 
145 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
146 
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
154 {
155  return functionObject::read(dict);
156 }
157 
158 
159 // ************************************************************************* //
const word & name() const
Return name.
Definition: IOobject.H:310
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
virtual const word & type() const =0
Runtime type information.
const word & name() const
Return the name of this functionObject.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
Specialisation of Foam::functionObject for a region and providing a reference to the region Foam::obj...
void cannotFindObjects(const wordList &fieldNames)
Prints a warning message that fieldNames cannot be found.
bool writeObject(const word &fieldName)
Write field if present in objectRegistry.
bool clearObject(const word &fieldName)
Clear field from the objectRegistry if present.
regionFunctionObject(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
void cannotFindObject(const word &fieldName)
Prints a warning message that fieldName cannot be found.
virtual bool read(const dictionary &)
Read optional controls.
Writes run time, CPU time and clock time and optionally the CPU and clock times per time step.
Registry of regIOobjects.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:34
virtual bool write(const bool write=true) const
Write using setting from DB.
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:241
A class for handling words, derived from string.
Definition: word.H:62
static List< word > fieldNames
Definition: globalFoam.H:46
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
messageStream Warning
dictionary dict