processorRunTimes.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-2025 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 "processorRunTimes.H"
27 #include "decompositionMethod.H"
28 #include "timeSelector.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
33 Foam::processorRunTimes::processorRunTimes::procRunTimes
34 (
35  const Time& completeRunTime,
36  const nProcsFrom npf
37 )
38 {
39  label nProcs;
40  switch (npf)
41  {
42  case nProcsFrom::decomposeParDict:
43  nProcs =
44  decompositionMethod::decomposeParDict(completeRunTime)
45  .lookup<int>("numberOfSubdomains");
46  break;
47 
49  nProcs =
50  fileHandler().nProcs(completeRunTime.path());
51  break;
52  }
53 
54  PtrList<Time> result(nProcs);
55 
56  forAll(result, proci)
57  {
58  result.set
59  (
60  proci,
61  new Time
62  (
63  Time::controlDictName,
64  completeRunTime.rootPath(),
65  completeRunTime.caseName()
66  /fileName(word("processor") + Foam::name(proci))
67  )
68  );
69 
70  result[proci].setTime(completeRunTime);
71  }
72 
73  return result;
74 }
75 
76 
77 Foam::autoPtr<Foam::Time> Foam::processorRunTimes::proc0RunTime
78 (
79  const Time& completeRunTime,
80  const PtrList<Time>& processorRunTimes
81 )
82 {
83  return
84  autoPtr<Time>
85  (
86  processorRunTimes.empty()
87  ? new Time
88  (
90  completeRunTime.rootPath(),
91  completeRunTime.caseName()
92  /fileName(word("processor") + Foam::name(label(0)))
93  )
94  : nullptr
95  );
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 
102 (
103  const word& name,
104  const argList& args,
105  const bool enableFunctionObjects,
106  const nProcsFrom npf
107 )
108 :
109  completeRunTime_(name, args, enableFunctionObjects),
110  procRunTimes_(procRunTimes(completeRunTime_, npf)),
111  proc0RunTime_(proc0RunTime(completeRunTime_, procRunTimes_))
112 {}
113 
114 
116 (
117  const word& name,
118  const fileName& rootPath,
119  const fileName& caseName,
120  const bool enableFunctionObjects,
121  const nProcsFrom npf
122 )
123 :
124  completeRunTime_(name, rootPath, caseName, enableFunctionObjects),
125  procRunTimes_(procRunTimes(completeRunTime_, npf)),
126  proc0RunTime_(proc0RunTime(completeRunTime_, procRunTimes_))
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
131 
133 {}
134 
135 
136 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
137 
139 (
140  const instant& inst,
141  const label newIndex
142 )
143 {
144  completeRunTime_.setTime(inst, newIndex);
145 
146  proc0TimeRef().setTime(inst, newIndex);
147 
148  for (label proci = 1; proci < nProcs(); proci ++)
149  {
150  procRunTimes_[proci].setTime(inst, newIndex);
151  }
152 }
153 
154 
156 {
157  const instantList timeDirs =
158  timeSelector::selectIfPresent(completeRunTime_, args);
159 
160  proc0TimeRef().setTime(completeRunTime_);
161 
162  for (label proci = 1; proci < nProcs(); proci ++)
163  {
164  procRunTimes_[proci].setTime(completeRunTime_);
165  }
166 
167  return timeDirs;
168 }
169 
170 
172 {
173  const instantList timeDirs =
174  timeSelector::select0(proc0TimeRef(), args);
175 
176  completeRunTime_.setTime(proc0TimeRef());
177 
178  for (label proci = 1; proci < nProcs(); proci ++)
179  {
180  procRunTimes_[proci].setTime(proc0TimeRef());
181  }
182 
183  return timeDirs;
184 }
185 
186 
187 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
static word controlDictName
The default control dictionary name (normally "controlDict")
Definition: Time.H:208
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
A class for handling file names.
Definition: fileName.H:82
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
An instant of time. Contains the time value and name.
Definition: instant.H:67
instantList selectComplete(const argList &args)
Select the time.
nProcsFrom
Enumeration for how the number of processors is determined.
instantList selectProc(const argList &args)
Select the time.
processorRunTimes(const word &name, const argList &args, const bool enableFunctionObjects=true, const nProcsFrom=nProcsFrom::decomposeParDict)
Construct from name and arguments.
void setTime(const instant &inst, const label newIndex)
Set the time.
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:252
static instantList selectIfPresent(Time &runTime, const argList &args)
If any time option provided return the set of times (as select0)
Definition: timeSelector.C:283
A class for handling words, derived from string.
Definition: word.H:62
static instantList timeDirs
Definition: globalFoam.H:44
const fileOperation & fileHandler()
Get current file handler.
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 LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Foam::argList args(argc, argv)