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-2026 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 = -1;
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  false
68  )
69  );
70 
71  result[proci].setTime(completeRunTime);
72  }
73 
74  return result;
75 }
76 
77 
78 Foam::autoPtr<Foam::Time> Foam::processorRunTimes::proc0RunTime
79 (
80  const Time& completeRunTime,
81  const PtrList<Time>& processorRunTimes
82 )
83 {
84  return
85  autoPtr<Time>
86  (
87  processorRunTimes.empty()
88  ? new Time
89  (
91  completeRunTime.rootPath(),
92  completeRunTime.caseName()
93  /fileName(word("processor") + Foam::name(label(0))),
94  false
95  )
96  : nullptr
97  );
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 
104 (
105  const word& name,
106  const argList& args,
107  const bool enableFunctionObjects,
108  const nProcsFrom npf
109 )
110 :
111  completeRunTime_(name, args, enableFunctionObjects),
112  procRunTimes_(procRunTimes(completeRunTime_, npf)),
113  proc0RunTime_(proc0RunTime(completeRunTime_, procRunTimes_))
114 {}
115 
116 
118 (
119  const word& name,
120  const fileName& rootPath,
121  const fileName& caseName,
122  const bool enableFunctionObjects,
123  const nProcsFrom npf
124 )
125 :
126  completeRunTime_(name, rootPath, caseName, enableFunctionObjects),
127  procRunTimes_(procRunTimes(completeRunTime_, npf)),
128  proc0RunTime_(proc0RunTime(completeRunTime_, procRunTimes_))
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
133 
135 {}
136 
137 
138 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
139 
141 (
142  const instant& inst,
143  const label newIndex
144 )
145 {
146  completeRunTime_.setTime(inst, newIndex);
147 
148  proc0TimeRef().setTime(inst, newIndex);
149 
150  for (label proci = 1; proci < nProcs(); proci ++)
151  {
152  procRunTimes_[proci].setTime(inst, newIndex);
153  }
154 }
155 
156 
158 {
159  const instantList timeDirs =
160  timeSelector::selectIfPresent(completeRunTime_, args);
161 
162  proc0TimeRef().setTime(completeRunTime_);
163 
164  for (label proci = 1; proci < nProcs(); proci ++)
165  {
166  procRunTimes_[proci].setTime(completeRunTime_);
167  }
168 
169  return timeDirs;
170 }
171 
172 
174 {
175  const instantList timeDirs =
176  timeSelector::select0(proc0TimeRef(), args);
177 
178  completeRunTime_.setTime(proc0TimeRef());
179 
180  for (label proci = 1; proci < nProcs(); proci ++)
181  {
182  procRunTimes_[proci].setTime(proc0TimeRef());
183  }
184 
185  return timeDirs;
186 }
187 
188 
189 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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:63
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)