cpuLoad.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) 2022 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 "cpuLoad.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(cpuLoad, 0);
33  optionalCpuLoad optionalCpuLoad::optionalCpuLoad_;
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
39 Foam::cpuLoad::cpuLoad(const fvMesh& mesh, const word& name)
40 :
41  volScalarField::Internal
42  (
43  IOobject
44  (
45  name,
46  mesh.time().timeName(),
47  mesh
48  ),
49  mesh,
51  )
52 {}
53 
54 
55 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
56 
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
62 
64 (
65  const fvMesh& mesh,
66  const word& name,
67  const bool loadBalancing
68 )
69 {
70  if (loadBalancing)
71  {
72  if
73  (
74  mesh.thisDb().objectRegistry::template
75  foundObject<cpuLoad>
76  (
77  name
78  )
79  )
80  {
81  return mesh.thisDb().objectRegistry::template
82  lookupObjectRef<cpuLoad>
83  (
84  name
85  );
86  }
87  else
88  {
89  if (cpuLoad::debug)
90  {
92  << "constructing " << name
93  << " for region " << mesh.name() << endl;
94  }
95 
96  cpuLoad* cpuLoadPtr(new cpuLoad(mesh, name));
97 
98  regIOobject::store(cpuLoadPtr);
99 
100  return *cpuLoadPtr;
101  }
102  }
103  else
104  {
105  return optionalCpuLoad::optionalCpuLoad_;
106  }
107 }
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
113 {
114  cpuTime_.cpuTimeIncrement();
115 }
116 
117 
119 {
120  operator[](celli) += cpuTime_.cpuTimeIncrement();
121 }
122 
123 
124 // ************************************************************************* //
const word & name() const
Return name.
Definition: IOobject.H:315
Type & operator[](const label)
Return element of UList.
Definition: UListI.H:167
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual ~cpuLoad()
Destructor.
Definition: cpuLoad.C:57
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:378
const dimensionSet dimTime
A class for handling words, derived from string.
Definition: word.H:59
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Definition: cpuTime.C:60
Class to maintain a field of the CPU load per cell.
Definition: cpuLoad.H:114
cpuLoad(const fvMesh &mesh, const word &name)
Construct from mesh, name and switch.
Definition: cpuLoad.C:39
word timeName
Definition: getTimeIndex.H:3
virtual void reset()
Reset the CPU time.
Definition: cpuLoad.C:112
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:40
defineTypeNameAndDebug(combustionModel, 0)
const word & name() const
Return reference to name.
Definition: fvMesh.H:386
static optionalCpuLoad & New(const fvMesh &mesh, const word &name, const bool loadBalancing)
Definition: cpuLoad.C:64
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
virtual void cpuTimeIncrement(const label celli)
Cache the CPU time increment for celli.
Definition: cpuLoad.C:118
Namespace for OpenFOAM.
#define InfoInFunction
Report an information message using Foam::Info.