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-2023 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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
37 }
38 }
39 
40 template<>
41 const char* Foam::NamedEnum
42 <
44  3
45 >::names[] =
46 {
47  "noWriteNow",
48  "writeNow",
49  "nextWrite"
50 };
51 
52 const Foam::NamedEnum
53 <
55  3
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 (
63  const word& name,
64  const Time& runTime,
65  const dictionary& dict
66 )
67 :
68  functionObject(name, runTime),
69  action_(actionType::nextWrite),
70  stopped_(false)
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
75 
77 {}
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
83 {
84  if (dict.found("action"))
85  {
86  action_ = actionTypeNames_.read(dict.lookup("action"));
87  }
88 
89  return true;
90 }
91 
92 
94 {
95  if (!stopped_)
96  {
97  bool stopCondition = condition();
98  reduce(stopCondition, orOp<bool>());
99 
100  if (stopCondition)
101  {
102  switch (action_)
103  {
104  case actionType::noWriteNow :
105  {
106  if (time_.stopAt(Time::stopAtControl::noWriteNow))
107  {
108  Info<< type() << "(timeIndex="
109  << time_.timeIndex()
110  << "): stopping now without writing"
111  << endl;
112  }
113  break;
114  }
115 
116  case actionType::writeNow :
117  {
118  if (time_.stopAt(Time::stopAtControl::writeNow))
119  {
120  Info<< type() << "(timeIndex="
121  << time_.timeIndex()
122  << "): stopping now after writing"
123  << endl;
124  }
125  break;
126  }
127 
128  case actionType::nextWrite :
129  {
130  if (time_.stopAt(Time::stopAtControl::nextWrite))
131  {
132  Info<< type() << "(timeIndex="
133  << time_.timeIndex()
134  << "): stopping after next write"
135  << endl;
136  }
137  break;
138  }
139  }
140 
141  stopped_ = true;
142  }
143  }
144 
145  return true;
146 }
147 
148 
150 {
151  return true;
152 }
153 
154 
156 {
157  return true;
158 }
159 
160 
161 // ************************************************************************* //
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:160
Abstract base-class for Time/database functionObjects.
Abstract base class for stop conditions.
Definition: stopAt.H:59
virtual ~stopAt()
Destructor.
Definition: stopAt.C:76
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:62
virtual bool execute()
Execute, check existence of stopAt file and take action.
Definition: stopAt.C:93
virtual bool write()
Execute, check existence of stopAt file and take action.
Definition: stopAt.C:149
virtual bool end()
Execute at the final time-loop, used for cleanup.
Definition: stopAt.C:155
virtual bool read(const dictionary &)
Read the dictionary settings.
Definition: stopAt.C:82
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:251
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