stopAt.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) 2020-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 "stopAt.H"
27 #include "Time.H"
28 #include "PstreamReduceOps.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
38 }
39 }
40 
41 const Foam::NamedEnum
42 <
44  3
46 {
47  "noWriteNow",
48  "writeNow",
49  "nextWrite"
50 };
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
56 (
57  const word& name,
58  const Time& runTime,
59  const dictionary& dict
60 )
61 :
62  functionObject(name, runTime),
63  action_(actionType::nextWrite),
64  stopped_(false)
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
77 {
78  if (dict.found("action"))
79  {
80  action_ = actionTypeNames_.read(dict.lookup("action"));
81  }
82 
83  return true;
84 }
85 
86 
88 {
89  if (!stopped_)
90  {
91  bool stopCondition = condition();
92  reduce(stopCondition, orOp<bool>());
93 
94  if (stopCondition)
95  {
96  switch (action_)
97  {
98  case actionType::noWriteNow :
99  {
100  if (time_.stopAt(Time::stopAtControl::noWriteNow))
101  {
102  Info<< type() << "(timeIndex="
103  << time_.timeIndex()
104  << "): stopping now without writing"
105  << endl;
106  }
107  break;
108  }
109 
110  case actionType::writeNow :
111  {
112  if (time_.stopAt(Time::stopAtControl::writeNow))
113  {
114  Info<< type() << "(timeIndex="
115  << time_.timeIndex()
116  << "): stopping now after writing"
117  << endl;
118  }
119  break;
120  }
121 
122  case actionType::nextWrite :
123  {
124  if (time_.stopAt(Time::stopAtControl::nextWrite))
125  {
126  Info<< type() << "(timeIndex="
127  << time_.timeIndex()
128  << "): stopping after next write"
129  << endl;
130  }
131  break;
132  }
133  }
134 
135  stopped_ = true;
136  }
137  }
138 
139  return true;
140 }
141 
142 
144 {
145  return true;
146 }
147 
148 
150 {
151  return true;
152 }
153 
154 
155 // ************************************************************************* //
Inter-processor communication reduction functions.
Macros for easy insertion into run-time selection tables.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
@ nextWrite
stop the next time data are written
@ writeNow
set endTime to stop immediately w/ writing
@ noWriteNow
set endTime to stop immediately w/o writing
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
Abstract base class for stop conditions.
Definition: stopAt.H:59
virtual ~stopAt()
Destructor.
Definition: stopAt.C:70
actionType
Enumeration defining the type of action.
Definition: stopAt.H:64
static const NamedEnum< actionType, 3 > actionTypeNames_
Action type names.
Definition: stopAt.H:76
stopAt(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: stopAt.C:56
virtual bool execute()
Execute, check existence of stopAt file and take action.
Definition: stopAt.C:87
virtual bool write()
Execute, check existence of stopAt file and take action.
Definition: stopAt.C:143
virtual bool end()
Execute at the final time-loop, used for cleanup.
Definition: stopAt.C:149
virtual bool read(const dictionary &)
Read the dictionary settings.
Definition: stopAt.C:76
A class for handling words, derived from string.
Definition: word.H:62
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict