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 {
39 
41  (
43  stopAtFile,
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 {
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 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Inter-processor communication reduction functions.
Macros for easy insertion into run-time selection tables.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
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.
Stops the run when the specified file is created in the case directory and optionally write results b...
Definition: stopAtFile.H:114
virtual ~stopAtFile()
Destructor.
Definition: stopAtFile.C:93
virtual bool end()
Execute at the final time-loop, used for cleanup.
Definition: stopAtFile.C:112
virtual bool read(const dictionary &)
Read the dictionary settings.
Definition: stopAtFile.C:99
stopAtFile(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: stopAtFile.C:74
Abstract base class for stop conditions.
Definition: stopAt.H:59
virtual bool read(const dictionary &)
Read the dictionary settings.
Definition: stopAt.C:82
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurrences of environment variables.
Definition: string.C:125
A class for handling words, derived from string.
Definition: word.H:62
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
Namespace for OpenFOAM.
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
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:1017
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict