FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

fieldValue.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2009-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "fieldValue.H"
00027 #include <finiteVolume/fvMesh.H>
00028 #include <OpenFOAM/Time.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(fieldValue, 0);
00035 
00036     defineTemplateTypeNameAndDebug(IOList<vector>, 0);
00037     defineTemplateTypeNameAndDebug(IOList<sphericalTensor>, 0);
00038     defineTemplateTypeNameAndDebug(IOList<symmTensor>, 0);
00039     defineTemplateTypeNameAndDebug(IOList<tensor>, 0);
00040 }
00041 
00042 
00043 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
00044 
00045 void Foam::fieldValue::updateMesh(const mapPolyMesh&)
00046 {
00047     // Do nothing
00048 }
00049 
00050 
00051 void Foam::fieldValue::movePoints(const Field<point>&)
00052 {
00053     // Do nothing
00054 }
00055 
00056 
00057 void Foam::fieldValue::makeFile()
00058 {
00059     // Create the forces file if not already created
00060     if (outputFilePtr_.empty())
00061     {
00062         if (debug)
00063         {
00064             Info<< "Creating output file." << endl;
00065         }
00066 
00067         // File update
00068         if (Pstream::master())
00069         {
00070             fileName outputDir;
00071             word startTimeName =
00072                 obr_.time().timeName(obr_.time().startTime().value());
00073 
00074             if (Pstream::parRun())
00075             {
00076                 // Put in undecomposed case (Note: gives problems for
00077                 // distributed data running)
00078                 outputDir =
00079                     obr_.time().path()/".."/name_/startTimeName;
00080             }
00081             else
00082             {
00083                 outputDir = obr_.time().path()/name_/startTimeName;
00084             }
00085 
00086             // Create directory if does not exist
00087             mkDir(outputDir);
00088 
00089             // Open new file at start up
00090             outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat")));
00091 
00092             // Add headers to output data
00093             writeFileHeader();
00094         }
00095     }
00096 }
00097 
00098 
00099 void Foam::fieldValue::read(const dictionary& dict)
00100 {
00101     if (active_)
00102     {
00103         log_ = dict.lookupOrDefault<Switch>("log", false);
00104         dict.lookup("fields") >> fields_;
00105         dict.lookup("valueOutput") >> valueOutput_;
00106     }
00107 }
00108 
00109 
00110 void Foam::fieldValue::write()
00111 {
00112     if (active_)
00113     {
00114         if (log_)
00115         {
00116             Info<< type() << " " << name_ << " output:" << nl;
00117         }
00118 
00119         makeFile();
00120     }
00121 }
00122 
00123 
00124 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00125 
00126 Foam::fieldValue::fieldValue
00127 (
00128     const word& name,
00129     const objectRegistry& obr,
00130     const dictionary& dict,
00131     const bool loadFromFiles
00132 )
00133 :
00134     name_(name),
00135     obr_(obr),
00136     active_(true),
00137     log_(false),
00138     sourceName_(dict.lookup("sourceName")),
00139     fields_(dict.lookup("fields")),
00140     valueOutput_(dict.lookup("valueOutput")),
00141     outputFilePtr_(NULL)
00142 {
00143     // Only active if obr is an fvMesh
00144     if (isA<fvMesh>(obr_))
00145     {
00146         read(dict);
00147     }
00148     else
00149     {
00150         WarningIn
00151         (
00152             "fieldValue::fieldValue"
00153             "("
00154                 "const word&, "
00155                 "const objectRegistry&, "
00156                 "const dictionary&, "
00157                 "const bool"
00158             ")"
00159         )   << "No fvMesh available, deactivating."
00160             << nl << endl;
00161         active_ = false;
00162     }
00163 }
00164 
00165 
00166 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00167 
00168 Foam::fieldValue::~fieldValue()
00169 {}
00170 
00171 
00172 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00173 
00174 void Foam::fieldValue::execute()
00175 {
00176     // Do nothing
00177 }
00178 
00179 
00180 void Foam::fieldValue::end()
00181 {
00182     // Do nothing
00183 }
00184 
00185 
00186 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines