stopAtFile.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) 2011-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 "stopAtFile.H"
27 #include "dictionary.H"
28 #include "OSspecific.H"
29 #include "PstreamReduceOps.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(stopAtFile, 0);
39 
41  (
42  functionObject,
43  stopAtFile,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::functionObjects::stopAtFile::removeFile() const
53 {
54  bool fileExists = isFile(stopAtFileFile_);
55  reduce(fileExists, orOp<bool>());
56 
57  if (fileExists && Pstream::master())
58  {
59  // Cleanup ABORT file (on master only)
60  rm(stopAtFileFile_);
61  }
62 }
63 
64 
65 bool Foam::functionObjects::stopAtFile::condition() const
66 {
67  return isFile(stopAtFileFile_);
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 
74 (
75  const word& name,
76  const Time& runTime,
77  const dictionary& dict
78 )
79 :
80  stopAt(name, runTime, dict),
81  stopAtFileFile_("$FOAM_CASE/" + name)
82 {
83  stopAtFileFile_.expand();
84  read(dict);
85 
86  // Remove any old files from previous runs
87  removeFile();
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 {
101  stopAt::read(dict);
102 
103  if (dict.readIfPresent("file", stopAtFileFile_))
104  {
105  stopAtFileFile_.expand();
106  }
107 
108  return true;
109 }
110 
111 
113 {
114  removeFile();
115  return true;
116 }
117 
118 
119 // ************************************************************************* //
virtual bool end()
Execute at the final time-loop, used for cleanup.
Definition: stopAtFile.C:112
stopAtFile(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: stopAtFile.C:74
Inter-processor communication reduction functions.
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
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
Definition: POSIX.C:555
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
virtual ~stopAtFile()
Destructor.
Definition: stopAtFile.C:93
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.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read(const dictionary &)
Read the dictionary settings.
Definition: stopAtFile.C:99
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
defineTypeNameAndDebug(Qdot, 0)
Abstract base class for stop conditions.
Definition: stopAt.H:56
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:1017
Namespace for OpenFOAM.