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-2023 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 word& fieldName
57 )
58 {
59  if (obr_.foundObject<regIOobject>(fieldName))
60  {
61  const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
62 
63  Log << " functionObjects::" << type() << " " << name()
64  << " writing field: " << field.name() << endl;
65 
66  field.write();
67 
68  return true;
69  }
70  else
71  {
72  return false;
73  }
74 }
75 
76 
78 (
79  const word& fieldName
80 )
81 {
82  if (foundObject<regIOobject>(fieldName))
83  {
84  regIOobject& resultObject = lookupObjectRef<regIOobject>(fieldName);
85 
86  if (resultObject.ownedByRegistry())
87  {
88  return resultObject.checkOut();
89  }
90  else
91  {
92  return false;
93  }
94  }
95  else
96  {
97  return true;
98  }
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
103 
105 (
106  const word& name,
107  const Time& runTime,
108  const dictionary& dict
109 )
110 :
111  functionObject(name, runTime),
112  obr_
113  (
114  runTime.lookupObject<objectRegistry>
115  (
116  dict.lookupOrDefault("region", polyMesh::defaultRegion)
117  )
118  )
119 {}
120 
121 
123 (
124  const word& name,
125  const objectRegistry& obr,
126  const dictionary& dict
127 )
128 :
129  functionObject(name, obr.time()),
130  obr_(obr)
131 {}
132 
133 
134 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
135 
137 {}
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
143 {
144  return functionObject::read(dict);
145 }
146 
147 
148 // ************************************************************************* //
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:160
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...
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
#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:251
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
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