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-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 \*---------------------------------------------------------------------------*/
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 template<>
42 const char* Foam::NamedEnum
43 <
45  3
46 >::names[] =
47 {
48  "noWriteNow",
49  "writeNow",
50  "nextWrite"
51 };
52 
53 const Foam::NamedEnum
54 <
56  3
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 (
64  const word& name,
65  const Time& runTime,
66  const dictionary& dict
67 )
68 :
69  functionObject(name, runTime),
70  action_(actionType::nextWrite),
71  stopped_(false)
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
76 
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 {
85  if (dict.found("action"))
86  {
87  action_ = actionTypeNames_.read(dict.lookup("action"));
88  }
89 
90  return true;
91 }
92 
93 
95 {
96  if (!stopped_)
97  {
98  bool stopCondition = condition();
99  reduce(stopCondition, orOp<bool>());
100 
101  if (stopCondition)
102  {
103  switch (action_)
104  {
105  case actionType::noWriteNow :
106  {
107  if (time_.stopAt(Time::stopAtControl::noWriteNow))
108  {
109  Info<< type() << "(timeIndex="
110  << time_.timeIndex()
111  << "): stopping now without writing"
112  << endl;
113  }
114  break;
115  }
116 
117  case actionType::writeNow :
118  {
119  if (time_.stopAt(Time::stopAtControl::writeNow))
120  {
121  Info<< type() << "(timeIndex="
122  << time_.timeIndex()
123  << "): stopping now after writing"
124  << endl;
125  }
126  break;
127  }
128 
129  case actionType::nextWrite :
130  {
131  if (time_.stopAt(Time::stopAtControl::nextWrite))
132  {
133  Info<< type() << "(timeIndex="
134  << time_.timeIndex()
135  << "): stopping after next write"
136  << endl;
137  }
138  break;
139  }
140  }
141 
142  stopped_ = true;
143  }
144  }
145 
146  return true;
147 }
148 
149 
151 {
152  return true;
153 }
154 
155 
157 {
158  return true;
159 }
160 
161 
162 // ************************************************************************* //
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:54
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 keyword definitions, which are a keyword followed by any number of values (e....
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:77
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:63
virtual bool execute()
Execute, check existence of stopAt file and take action.
Definition: stopAt.C:94
virtual bool write()
Execute, check existence of stopAt file and take action.
Definition: stopAt.C:150
virtual bool end()
Execute at the final time-loop, used for cleanup.
Definition: stopAt.C:156
virtual bool read(const dictionary &)
Read the dictionary settings.
Definition: stopAt.C:83
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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
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