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 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 {
36  defineTypeNameAndDebug(stopAt, 0);
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),
69  time_(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  else
90  {
91  action_ = actionType::nextWrite;
92  }
93 
94  return true;
95 }
96 
97 
99 {
100  if (!stopped_)
101  {
102  bool stopCondition = condition();
103  reduce(stopCondition, orOp<bool>());
104 
105  if (stopCondition)
106  {
107  switch (action_)
108  {
109  case actionType::noWriteNow :
110  {
111  if (time_.stopAt(Time::stopAtControl::noWriteNow))
112  {
113  Info<< type() << "(timeIndex="
114  << time_.timeIndex()
115  << "): stopping now without writing"
116  << endl;
117  }
118  break;
119  }
120 
121  case actionType::writeNow :
122  {
123  if (time_.stopAt(Time::stopAtControl::writeNow))
124  {
125  Info<< type() << "(timeIndex="
126  << time_.timeIndex()
127  << "): stopping now after writing"
128  << endl;
129  }
130  break;
131  }
132 
133  case actionType::nextWrite :
134  {
135  if (time_.stopAt(Time::stopAtControl::nextWrite))
136  {
137  Info<< type() << "(timeIndex="
138  << time_.timeIndex()
139  << "): stopping after next write"
140  << endl;
141  }
142  break;
143  }
144  }
145 
146  stopped_ = true;
147  }
148  }
149 
150  return true;
151 }
152 
153 
155 {
156  return true;
157 }
158 
159 
161 {
162  return true;
163 }
164 
165 
166 // ************************************************************************* //
actionType
Enumeration defining the type of action.
Definition: stopAt.H:63
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:663
virtual bool end()
Execute at the final time-loop, used for cleanup.
Definition: stopAt.C:160
virtual bool read(const dictionary &)
Read the dictionary settings.
Definition: stopAt.C:83
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
set endTime to stop immediately w/ writing
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual ~stopAt()
Destructor.
Definition: stopAt.C:77
Abstract base-class for Time/database functionObjects.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
static const NamedEnum< actionType, 3 > actionTypeNames_
Action type names.
Definition: stopAt.H:79
A class for handling words, derived from string.
Definition: word.H:59
set endTime to stop immediately w/o writing
virtual bool write()
Execute, check existence of stopAt file and take action.
Definition: stopAt.C:154
virtual bool execute()
Execute, check existence of stopAt file and take action.
Definition: stopAt.C:98
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
defineTypeNameAndDebug(Qdot, 0)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
stopAt(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: stopAt.C:62
messageStream Info
stop the next time data are written
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864