cpuLoad.H
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-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 Class
25  Foam::cpuLoad
26 
27 Description
28  Class to maintain a field of the CPU load per cell.
29 
30  The optionalCpuLoad is a base-class for cpuLoad to simplify the
31  implementation of optional CPU time caching. This is achieved via the
32  optionalCpuLoad::New function which returns a optionalCpuLoad with dummy
33  functions if loadBalancing is false otherwise it creates or looks-up and
34  returns a cpuLoad with the given name.
35 
36  Used for loadBalancing.
37 
38 SourceFiles
39  cpuLoad.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef cpuLoad_H
44 #define cpuLoad_H
45 
46 #include "cpuTime.H"
47 #include "scalarField.H"
48 #include "polyMesh.H"
49 #include "DemandDrivenMeshObject.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class optionalCpuLoad Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 class optionalCpuLoad
61 {
62  // Private Member Data
63 
64  //- Dummy optionalCpuLoad
65  // returned by optionalCpuLoad::New if loadBalancing = false
66  static optionalCpuLoad optionalCpuLoad_;
67 
68 
69 public:
70 
71  // Constructors
72 
73  //- Construct from mesh, name and switch
75  {}
76 
77  //- Disallow default bitwise copy construction
78  optionalCpuLoad(const optionalCpuLoad&) = delete;
79 
80 
81  // Selectors
82 
83 
84  //- Construct from polyMesh if loadBalancing is true
85  // otherwise return the dummy optionalCpuLoad
86  static optionalCpuLoad& New
87  (
88  const word& name,
89  const polyMesh& mesh,
90  const bool loadBalancing
91  );
92 
93 
94  //- Destructor
95  virtual ~optionalCpuLoad()
96  {}
97 
98 
99  // Member Functions
100 
101  //- Reset the CPU time (dummy)
102  virtual void resetCpuTime()
103  {}
104 
105  //- Cache the CPU time increment for celli (dummy)
106  virtual void cpuTimeIncrement(const label celli)
107  {}
108 
109  //- Reset the CPU load field (dummy)
110  virtual void reset()
111  {}
112 
113 
114  // Member Operators
115 
116  //- Disallow default bitwise assignment
117  void operator=(const optionalCpuLoad&) = delete;
118 };
119 
120 
121 /*---------------------------------------------------------------------------*\
122  Class cpuLoad Declaration
123 \*---------------------------------------------------------------------------*/
124 
125 class cpuLoad
126 :
127  public optionalCpuLoad,
128  public DemandDrivenMeshObject<polyMesh, TopoChangeableMeshObject, cpuLoad>,
129  public scalarField
130 {
131  // Private Data
132 
133  cpuTime cpuTime_;
134 
135 
136 public:
137 
138  // Declare name of the class and its debug switch
139  TypeName("cpuLoad");
140 
141 
142  // Constructors
143 
144  //- Construct from mesh, name and switch
145  cpuLoad
146  (
147  const word& name,
148  const polyMesh& mesh
149  );
150 
151  //- Disallow default bitwise copy construction
152  cpuLoad(const cpuLoad&) = delete;
153 
154 
155  //- Destructor
156  virtual ~cpuLoad();
157 
158 
159  // Member Functions
160 
161  //- Reset the CPU time
162  virtual void resetCpuTime();
163 
164  //- Cache the CPU time increment for celli
165  virtual void cpuTimeIncrement(const label celli);
166 
167  //- Reset the CPU load field
168  virtual void reset();
169 
170 
171  //- Update for mesh motion
172  virtual bool movePoints();
173 
174  //- Redistribute or update using the given distribution map
175  virtual void distribute(const polyDistributionMap& map);
176 
177  //- Update topology using the given map
178  virtual void topoChange(const polyTopoChangeMap& map);
179 
180  //- Update from another mesh using the given map
181  virtual void mapMesh(const polyMeshMap& map);
182 
183 
184  // Member Operators
185 
186  //- Disallow default bitwise assignment
187  void operator=(const cpuLoad&) = delete;
188 };
189 
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 } // End namespace Foam
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 #endif
198 
199 // ************************************************************************* //
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
void map(const UList< scalar > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
Definition: Field.C:289
const word & name() const
Return name.
Definition: IOobject.H:310
Class to maintain a field of the CPU load per cell.
Definition: cpuLoad.H:129
virtual bool movePoints()
Update for mesh motion.
Definition: cpuLoad.C:105
virtual void resetCpuTime()
Reset the CPU time.
Definition: cpuLoad.C:87
cpuLoad(const word &name, const polyMesh &mesh)
Construct from mesh, name and switch.
Definition: cpuLoad.C:43
virtual void cpuTimeIncrement(const label celli)
Cache the CPU time increment for celli.
Definition: cpuLoad.C:93
virtual ~cpuLoad()
Destructor.
Definition: cpuLoad.C:56
TypeName("cpuLoad")
virtual void mapMesh(const polyMeshMap &map)
Update from another mesh using the given map.
Definition: cpuLoad.C:118
void operator=(const cpuLoad &)=delete
Disallow default bitwise assignment.
virtual void distribute(const polyDistributionMap &map)
Redistribute or update using the given distribution map.
Definition: cpuLoad.C:125
virtual void reset()
Reset the CPU load field.
Definition: cpuLoad.C:99
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
Definition: cpuLoad.C:111
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTime.H:55
virtual void resetCpuTime()
Reset the CPU time (dummy)
Definition: cpuLoad.H:101
virtual ~optionalCpuLoad()
Destructor.
Definition: cpuLoad.H:94
virtual void reset()
Reset the CPU load field (dummy)
Definition: cpuLoad.H:109
optionalCpuLoad()
Construct from mesh, name and switch.
Definition: cpuLoad.H:73
void operator=(const optionalCpuLoad &)=delete
Disallow default bitwise assignment.
virtual void cpuTimeIncrement(const label celli)
Cache the CPU time increment for celli (dummy)
Definition: cpuLoad.H:105
static optionalCpuLoad & New(const word &name, const polyMesh &mesh, const bool loadBalancing)
Construct from polyMesh if loadBalancing is true.
Definition: cpuLoad.C:63
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:62
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39