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-2014 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 "objectRegistry.H"
28 #include "Time.H"
29 #include "dictionary.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 defineTypeNameAndDebug(timeActivatedFileUpdate, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::timeActivatedFileUpdate::updateFile()
42 {
43  label i = lastIndex_;
44  while
45  (
46  i < timeVsFile_.size()-1
47  && timeVsFile_[i+1].first() < obr_.time().value()
48  )
49  {
50  i++;
51  }
52 
53  if (i > lastIndex_)
54  {
55  Info<< nl << type() << ": copying file" << nl << timeVsFile_[i].second()
56  << nl << "to:" << nl << fileToUpdate_ << nl << endl;
57 
58  cp(timeVsFile_[i].second(), fileToUpdate_);
59  lastIndex_ = i;
60  }
61 }
62 
63 
64 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65 
66 Foam::timeActivatedFileUpdate::timeActivatedFileUpdate
67 (
68  const word& name,
69  const objectRegistry& obr,
70  const dictionary& dict,
71  const bool loadFromFiles
72 )
73 :
74  name_(name),
75  obr_(obr),
76  active_(true),
77  fileToUpdate_(dict.lookup("fileToUpdate")),
78  timeVsFile_(),
79  lastIndex_(-1)
80 {
81  read(dict);
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
86 
88 {}
89 
90 
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 
94 {
95  if (active_)
96  {
97  dict.lookup("fileToUpdate") >> fileToUpdate_;
98  dict.lookup("timeVsFile") >> timeVsFile_;
99 
100  lastIndex_ = -1;
101  fileToUpdate_.expand();
102 
103  Info<< type() << ": time vs file list:" << nl;
104  forAll(timeVsFile_, i)
105  {
106  timeVsFile_[i].second() = timeVsFile_[i].second().expand();
107  if (!isFile(timeVsFile_[i].second()))
108  {
109  FatalErrorIn("timeActivatedFileUpdate::read(const dictionary&)")
110  << "File: " << timeVsFile_[i].second() << " not found"
111  << nl << exit(FatalError);
112  }
113 
114  Info<< " " << timeVsFile_[i].first() << tab
115  << timeVsFile_[i].second() << endl;
116  }
117  Info<< endl;
118 
119  updateFile();
120  }
121 }
122 
123 
125 {
126  if (active_)
127  {
128  updateFile();
129  }
130 }
131 
132 
134 {
135  if (active_)
136  {
137  execute();
138  }
139 }
140 
141 
143 {
144  // Do nothing
145 }
146 
147 
149 {
150  // Do nothing
151 }
152 
153 
154 // ************************************************************************* //
virtual void end()
Execute at the final time-loop, currently does nothing.
virtual void read(const dictionary &)
Read the timeActivatedFileUpdate data.
A class for handling words, derived from string.
Definition: word.H:59
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
virtual void execute()
Execute, currently does nothing.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Namespace for OpenFOAM.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
static const char tab
Definition: Ostream.H:259
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
Registry of regIOobjects.
virtual void write()
Calculate the timeActivatedFileUpdate and write.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:623
bool cp(const fileName &src, const fileName &dst)
Copy, recursively if necessary, the source to the destination.
Definition: POSIX.C:756
defineTypeNameAndDebug(combustionModel, 0)
virtual ~timeActivatedFileUpdate()
Destructor.