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 {
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().name(),
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 // ************************************************************************* //
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Class to maintain a field of the CPU load per cell.
Definition: cpuLoad.H:118
virtual void cpuTimeIncrement(const label celli)
Cache the CPU time increment for celli.
Definition: cpuLoad.C:118
virtual ~cpuLoad()
Destructor.
Definition: cpuLoad.C:57
cpuLoad(const fvMesh &mesh, const word &name)
Construct from mesh, name and switch.
Definition: cpuLoad.C:39
virtual void reset()
Reset the CPU time.
Definition: cpuLoad.C:112
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:412
const word & name() const
Return reference to name.
Definition: fvMesh.H:420
static optionalCpuLoad & New(const fvMesh &mesh, const word &name, const bool loadBalancing)
Definition: cpuLoad.C:64
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:40
A class for handling words, derived from string.
Definition: word.H:62
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const dimensionSet dimTime
defineTypeNameAndDebug(combustionModel, 0)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47