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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 
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  if (log_) Info
56  << nl << type() << ": copying file" << nl << timeVsFile_[i].second()
57  << nl << "to:" << nl << fileToUpdate_ << nl << endl;
58 
59  cp(timeVsFile_[i].second(), fileToUpdate_);
60  lastIndex_ = i;
61  }
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 
68 (
69  const word& name,
70  const objectRegistry& obr,
71  const dictionary& dict,
72  const bool loadFromFiles
73 )
74 :
75  name_(name),
76  obr_(obr),
77  active_(true),
78  fileToUpdate_("unknown-fileToUpdate"),
79  timeVsFile_(),
80  lastIndex_(-1),
81  log_(true)
82 {
83  read(dict);
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 {
97  if (active_)
98  {
99  log_.readIfPresent("log", dict);
100 
101  dict.lookup("fileToUpdate") >> fileToUpdate_;
102  dict.lookup("timeVsFile") >> timeVsFile_;
103 
104  lastIndex_ = -1;
105  fileToUpdate_.expand();
106 
107  if (log_) Info
108  << type() << " " << name_ << " output:" << nl
109  << " time vs file list:" << endl;
110 
111  forAll(timeVsFile_, i)
112  {
113  timeVsFile_[i].second() = timeVsFile_[i].second().expand();
114  if (!isFile(timeVsFile_[i].second()))
115  {
117  << "File: " << timeVsFile_[i].second() << " not found"
118  << nl << exit(FatalError);
119  }
120 
121  if (log_) Info
122  << " " << timeVsFile_[i].first() << tab
123  << timeVsFile_[i].second() << endl;
124  }
125  if (log_) Info<< endl;
126 
127  updateFile();
128  }
129 }
130 
131 
133 {
134  if (active_)
135  {
136  updateFile();
137  }
138 }
139 
140 
142 {
143  // Do nothing
144 }
145 
146 
148 {
149  // Do nothing
150 }
151 
152 
154 {
155  // Do nothing
156 }
157 
158 
159 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::timeActivatedFileUpdate::~timeActivatedFileUpdate
virtual ~timeActivatedFileUpdate()
Destructor.
Definition: timeActivatedFileUpdate.C:89
Foam::timeActivatedFileUpdate::timeActivatedFileUpdate
timeActivatedFileUpdate(const timeActivatedFileUpdate &)
Disallow default bitwise copy construct.
Foam::timeActivatedFileUpdate::execute
virtual void execute()
Execute, currently does nothing.
Definition: timeActivatedFileUpdate.C:132
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::timeActivatedFileUpdate::timeVsFile_
List< Tuple2< scalar, fileName > > timeVsFile_
List of times vs filenames.
Definition: timeActivatedFileUpdate.H:131
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::timeActivatedFileUpdate::fileToUpdate_
fileName fileToUpdate_
Name of file to update.
Definition: timeActivatedFileUpdate.H:128
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
objectRegistry.H
Foam::timeActivatedFileUpdate::write
virtual void write()
Calculate the timeActivatedFileUpdate and write.
Definition: timeActivatedFileUpdate.C:153
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:261
Foam::cp
bool cp(const fileName &src, const fileName &dst)
Copy, recursively if necessary, the source to the destination.
Definition: POSIX.C:755
Foam::timeActivatedFileUpdate::obr_
const objectRegistry & obr_
Owner database.
Definition: timeActivatedFileUpdate.H:122
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::timeActivatedFileUpdate::updateFile
void updateFile()
Update file.
Definition: timeActivatedFileUpdate.C:41
Foam::label
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
Foam::timeActivatedFileUpdate::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: timeActivatedFileUpdate.C:141
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::timeActivatedFileUpdate::log_
Switch log_
Switch to send output to Info as well as to file.
Definition: timeActivatedFileUpdate.H:137
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::isFile
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
Definition: POSIX.C:622
timeActivatedFileUpdate.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::tab
static const char tab
Definition: Ostream.H:259
dictionary.H
Foam::timeActivatedFileUpdate::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: timeActivatedFileUpdate.C:147
Foam::timeActivatedFileUpdate::lastIndex_
label lastIndex_
Index of last file copied.
Definition: timeActivatedFileUpdate.H:134
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::timeActivatedFileUpdate::read
virtual void read(const dictionary &)
Read the timeActivatedFileUpdate data.
Definition: timeActivatedFileUpdate.C:95
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47