fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / global / JobInfo / JobInfo.C
blob3446c130c784cfbb564e1ee7210a3596bff980e5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "JobInfo.H"
28 #include "OSspecific.H"
29 #include "clock.H"
30 #include "OFstream.H"
31 #include "Pstream.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 bool Foam::JobInfo::writeJobInfo(Foam::debug::infoSwitch("writeJobInfo", 0));
36 Foam::JobInfo Foam::jobInfo;
39 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
41 // Null constructor
42 Foam::JobInfo::JobInfo()
44     runningJobPath_(),
45     finishedJobPath_(),
46     cpuTime_()
48     name() = "JobInfo";
50     if (writeJobInfo && Pstream::master())
51     {
52         string baseDir = getEnv("FOAM_JOB_DIR");
53         string jobFile = hostName() + '.' + Foam::name(pid());
55         fileName runningDir(baseDir/"runningJobs");
56         fileName finishedDir(baseDir/"finishedJobs");
58         runningJobPath_  = runningDir/jobFile;
59         finishedJobPath_ = finishedDir/jobFile;
61         if (baseDir.empty())
62         {
63             FatalErrorIn("JobInfo::JobInfo()")
64                 << "Cannot get JobInfo directory $FOAM_JOB_DIR"
65                 << Foam::exit(FatalError);
66         }
68         if (!isDir(runningDir) && !mkDir(runningDir))
69         {
70             FatalErrorIn("JobInfo::JobInfo()")
71                 << "Cannot make JobInfo directory " << runningDir
72                 << Foam::exit(FatalError);
73         }
75         if (!isDir(finishedDir) && !mkDir(finishedDir))
76         {
77             FatalErrorIn("JobInfo::JobInfo()")
78                 << "Cannot make JobInfo directory " << finishedDir
79                 << Foam::exit(FatalError);
80         }
81     }
83     constructed = true;
87 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
89 Foam::JobInfo::~JobInfo()
91     if (writeJobInfo && constructed && Pstream::master())
92     {
93         mv(runningJobPath_, finishedJobPath_);
94     }
96     constructed = false;
100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
102 bool Foam::JobInfo::write(Ostream& os) const
104     if (writeJobInfo && Pstream::master())
105     {
106         if (os.good())
107         {
108             dictionary::write(os, false);
109             return true;
110         }
111         else
112         {
113             return false;
114         }
115     }
116     else
117     {
118         return true;
119     }
123 void Foam::JobInfo::write() const
125     if (writeJobInfo && Pstream::master())
126     {
127         if (!write(OFstream(runningJobPath_)()))
128         {
129             FatalErrorIn("JobInfo::write() const")
130                 << "Failed to write to JobInfo file "
131                 << runningJobPath_
132                 << Foam::exit(FatalError);
133         }
134     }
138 void Foam::JobInfo::end(const word& terminationType)
140     if (writeJobInfo && constructed && Pstream::master())
141     {
142         add("cpuTime", cpuTime_.elapsedCpuTime());
143         add("endDate", clock::date());
144         add("endTime", clock::clockTime());
146         if (!found("termination"))
147         {
148             add("termination", terminationType);
149         }
151         rm(runningJobPath_);
152         write(OFstream(finishedJobPath_)());
153     }
155     constructed = false;
159 void Foam::JobInfo::end()
161     end("normal");
165 void Foam::JobInfo::exit()
167     end("exit");
171 void Foam::JobInfo::abort()
173     end("abort");
177 void Foam::JobInfo::signalEnd() const
179     if (writeJobInfo && constructed && Pstream::master())
180     {
181         mv(runningJobPath_, finishedJobPath_);
182     }
184     constructed = false;
188 // ************************************************************************* //