timeActivatedFileUpdate.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 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 
27 #include "Time.H"
28 #include "polyMesh.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
37  defineTypeNameAndDebug(timeActivatedFileUpdate, 0);
38 
40  (
41  functionObject,
42  timeActivatedFileUpdate,
43  dictionary
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 void Foam::functionObjects::timeActivatedFileUpdate::updateFile()
52 {
53  label i = lastIndex_;
54  while
55  (
56  i < timeVsFile_.size()-1
57  && timeVsFile_[i+1].first() < time_.value()
58  )
59  {
60  i++;
61  }
62 
63  if (i > lastIndex_)
64  {
65  Info<< nl << type() << ": copying file" << nl << timeVsFile_[i].second()
66  << nl << "to:" << nl << fileToUpdate_ << nl << endl;
67 
68  cp(timeVsFile_[i].second(), fileToUpdate_);
69  lastIndex_ = i;
70  }
71 }
72 
73 
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 
76 Foam::functionObjects::timeActivatedFileUpdate::timeActivatedFileUpdate
77 (
78  const word& name,
79  const Time& runTime,
80  const dictionary& dict
81 )
82 :
83  functionObject(name),
84  time_(runTime),
85  fileToUpdate_(dict.lookup("fileToUpdate")),
86  timeVsFile_(),
87  lastIndex_(-1)
88 {
89  read(dict);
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 
96 {}
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 (
103  const dictionary& dict
104 )
105 {
106  dict.lookup("fileToUpdate") >> fileToUpdate_;
107  dict.lookup("timeVsFile") >> timeVsFile_;
108 
109  lastIndex_ = -1;
110  fileToUpdate_.expand();
111 
112  Info<< type() << ": time vs file list:" << nl;
113  forAll(timeVsFile_, i)
114  {
115  timeVsFile_[i].second() = timeVsFile_[i].second().expand();
116  if (!isFile(timeVsFile_[i].second()))
117  {
119  << "File: " << timeVsFile_[i].second() << " not found"
120  << nl << exit(FatalError);
121  }
122 
123  Info<< " " << timeVsFile_[i].first() << tab
124  << timeVsFile_[i].second() << endl;
125  }
126  Info<< endl;
127 
128  updateFile();
129 
130  return true;
131 }
132 
133 
135 {
136  updateFile();
137 
138  return true;
139 }
140 
141 
143 {
144  return true;
145 }
146 
147 
148 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
virtual bool execute()
Execute file updates.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const char tab
Definition: Ostream.H:261
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:492
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool cp(const fileName &src, const fileName &dst)
Copy, recursively if necessary, the source to the destination.
Definition: POSIX.C:620
Abstract base-class for Time/database function objects.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
static const char nl
Definition: Ostream.H:262
virtual bool read(const dictionary &)
Read the timeActivatedFileUpdate data.
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
addToRunTimeSelectionTable(functionObject, blendingFactor, dictionary)
messageStream Info
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451