re-structuring

This commit is contained in:
andy
2009-11-23 18:31:41 +00:00
parent d6a5a3299e
commit e83a5c271e
7 changed files with 186 additions and 189 deletions

View File

@ -117,45 +117,6 @@ void Foam::fieldValues::cellSource::initialise()
} }
void Foam::fieldValues::cellSource::makeFile()
{
// Create the forces file if not already created
if (outputFilePtr_.empty())
{
if (debug)
{
Info<< "Creating output file." << endl;
}
// File update
if (Pstream::master())
{
fileName outputDir;
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
outputDir =
obr_.time().path()/".."/name_/obr_.time().timeName();
}
else
{
outputDir = obr_.time().path()/name_/obr_.time().timeName();
}
// Create directory if does not exist
mkDir(outputDir);
// Open new file at start up
outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat")));
// Add headers to output data
writeFileHeader();
}
}
}
void Foam::fieldValues::cellSource::writeFileHeader() void Foam::fieldValues::cellSource::writeFileHeader()
{ {
if (outputFilePtr_.valid()) if (outputFilePtr_.valid())
@ -190,16 +151,9 @@ Foam::fieldValues::cellSource::cellSource
fieldValue(name, obr, dict, loadFromFiles), fieldValue(name, obr, dict, loadFromFiles),
source_(sourceTypeNames_.read(dict.lookup("source"))), source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))), operation_(operationTypeNames_.read(dict.lookup("operation"))),
cellId_(), cellId_()
outputFilePtr_(NULL)
{ {
initialise(); read(dict);
if (active_)
{
// Create the output file if not already created
makeFile();
}
} }
@ -213,9 +167,11 @@ Foam::fieldValues::cellSource::~cellSource()
void Foam::fieldValues::cellSource::read(const dictionary& dict) void Foam::fieldValues::cellSource::read(const dictionary& dict)
{ {
fieldValue::read(dict);
if (active_) if (active_)
{ {
fieldValue::read(dict); // no additional info to read
initialise(); initialise();
} }
} }
@ -223,13 +179,10 @@ void Foam::fieldValues::cellSource::read(const dictionary& dict)
void Foam::fieldValues::cellSource::write() void Foam::fieldValues::cellSource::write()
{ {
fieldValue::write();
if (active_) if (active_)
{ {
if (log_)
{
Info<< type() << " " << name_ << " output:" << nl;
}
outputFilePtr_() outputFilePtr_()
<< obr_.time().value() << tab << obr_.time().value() << tab
<< sum(filterField(mesh().V())); << sum(filterField(mesh().V()));

View File

@ -58,7 +58,6 @@ SourceFiles
#include "NamedEnum.H" #include "NamedEnum.H"
#include "fieldValue.H" #include "fieldValue.H"
#include "labelList.H" #include "labelList.H"
#include "OFstream.H"
#include "volFieldsFwd.H" #include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -114,9 +113,6 @@ private:
//- Set cells to evaluate based on a patch //- Set cells to evaluate based on a patch
void setPatchCells(); void setPatchCells();
//- Create the output file if not already created
void makeFile();
protected: protected:
@ -131,9 +127,6 @@ protected:
//- Local list of cell IDs //- Local list of cell IDs
labelList cellId_; labelList cellId_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Protected member functions // Protected member functions

View File

@ -258,45 +258,6 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
} }
void Foam::fieldValues::faceSource::makeFile()
{
// Create the forces file if not already created
if (outputFilePtr_.empty())
{
if (debug)
{
Info<< "Creating output file." << endl;
}
// File update
if (Pstream::master())
{
fileName outputDir;
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
outputDir =
obr_.time().path()/".."/name_/obr_.time().timeName();
}
else
{
outputDir = obr_.time().path()/name_/obr_.time().timeName();
}
// Create directory if does not exist
mkDir(outputDir);
// Open new file at start up
outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat")));
// Add headers to output data
writeFileHeader();
}
}
}
void Foam::fieldValues::faceSource::writeFileHeader() void Foam::fieldValues::faceSource::writeFileHeader()
{ {
if (outputFilePtr_.valid()) if (outputFilePtr_.valid())
@ -334,16 +295,9 @@ Foam::fieldValues::faceSource::faceSource
faceId_(), faceId_(),
facePatchId_(), facePatchId_(),
flipMap_(), flipMap_(),
outputFilePtr_(NULL),
weightFieldName_("undefinedWeightedFieldName") weightFieldName_("undefinedWeightedFieldName")
{ {
if (active_) read(dict);
{
initialise(dict);
// Create the output file if not already created
makeFile();
}
} }
@ -357,9 +311,10 @@ Foam::fieldValues::faceSource::~faceSource()
void Foam::fieldValues::faceSource::read(const dictionary& dict) void Foam::fieldValues::faceSource::read(const dictionary& dict)
{ {
fieldValue::read(dict);
if (active_) if (active_)
{ {
fieldValue::read(dict);
initialise(dict); initialise(dict);
} }
} }
@ -367,13 +322,10 @@ void Foam::fieldValues::faceSource::read(const dictionary& dict)
void Foam::fieldValues::faceSource::write() void Foam::fieldValues::faceSource::write()
{ {
fieldValue::write();
if (active_) if (active_)
{ {
if (log_)
{
Info<< type() << " " << name_ << " output:" << nl;
}
outputFilePtr_() outputFilePtr_()
<< obr_.time().value() << tab << obr_.time().value() << tab
<< sum(filterField(mesh().magSf())); << sum(filterField(mesh().magSf()));

View File

@ -66,7 +66,6 @@ SourceFiles
#include "NamedEnum.H" #include "NamedEnum.H"
#include "fieldValue.H" #include "fieldValue.H"
#include "labelList.H" #include "labelList.H"
#include "OFstream.H"
#include "surfaceFieldsFwd.H" #include "surfaceFieldsFwd.H"
#include "volFieldsFwd.H" #include "volFieldsFwd.H"
@ -125,9 +124,6 @@ private:
//- Set faces to evaluate based on a patch //- Set faces to evaluate based on a patch
void setPatchFaces(); void setPatchFaces();
//- Create the output file if not already created
void makeFile();
protected: protected:
@ -148,9 +144,6 @@ protected:
//- List of +1/-1 representing face flip map //- List of +1/-1 representing face flip map
labelList flipMap_; labelList flipMap_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
//- Weight field name - only used for opWeightedAverage mode //- Weight field name - only used for opWeightedAverage mode
word weightFieldName_; word weightFieldName_;

View File

@ -26,6 +26,7 @@ License
#include "fieldValue.H" #include "fieldValue.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -54,6 +55,73 @@ void Foam::fieldValue::movePoints(const Field<point>&)
} }
void Foam::fieldValue::makeFile()
{
// Create the forces file if not already created
if (outputFilePtr_.empty())
{
if (debug)
{
Info<< "Creating output file." << endl;
}
// File update
if (Pstream::master())
{
fileName outputDir;
word startTimeName =
obr_.time().timeName(obr_.time().startTime().value());
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
outputDir =
obr_.time().path()/".."/name_/startTimeName;
}
else
{
outputDir = obr_.time().path()/name_/startTimeName;
}
// Create directory if does not exist
mkDir(outputDir);
// Open new file at start up
outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat")));
// Add headers to output data
writeFileHeader();
}
}
}
void Foam::fieldValue::read(const dictionary& dict)
{
if (active_)
{
log_ = dict.lookupOrDefault<Switch>("log", false);
dict.lookup("fields") >> fields_;
dict.lookup("valueOutput") >> valueOutput_;
}
}
void Foam::fieldValue::write()
{
if (active_)
{
if (log_)
{
Info<< type() << " " << name_ << " output:" << nl;
}
makeFile();
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fieldValue::fieldValue Foam::fieldValue::fieldValue
@ -70,7 +138,8 @@ Foam::fieldValue::fieldValue
log_(false), log_(false),
sourceName_(dict.lookup("sourceName")), sourceName_(dict.lookup("sourceName")),
fields_(dict.lookup("fields")), fields_(dict.lookup("fields")),
valueOutput_(dict.lookup("valueOutput")) valueOutput_(dict.lookup("valueOutput")),
outputFilePtr_(NULL)
{ {
// Only active if obr is an fvMesh // Only active if obr is an fvMesh
if (isA<fvMesh>(obr_)) if (isA<fvMesh>(obr_))
@ -103,65 +172,6 @@ Foam::fieldValue::~fieldValue()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::word& Foam::fieldValue::name() const
{
return name_;
}
const Foam::objectRegistry& Foam::fieldValue::obr() const
{
return obr_;
}
bool Foam::fieldValue::active() const
{
return active_;
}
const Foam::Switch& Foam::fieldValue::log() const
{
return log_;
}
const Foam::word& Foam::fieldValue::sourceName() const
{
return sourceName_;
}
const Foam::wordList& Foam::fieldValue::fields() const
{
return fields_;
}
const Foam::Switch& Foam::fieldValue::valueOutput() const
{
return valueOutput_;
}
const Foam::fvMesh& Foam::fieldValue::mesh() const
{
return refCast<const fvMesh>(obr_);
}
void Foam::fieldValue::read(const dictionary& dict)
{
if (active_)
{
log_ = dict.lookupOrDefault<Switch>("log", false);
dict.lookup("fields") >> fields_;
dict.lookup("valueOutput") >> valueOutput_;
}
}
void Foam::fieldValue::execute() void Foam::fieldValue::execute()
{ {
// Do nothing // Do nothing

View File

@ -38,6 +38,7 @@ SourceFiles
#include "Switch.H" #include "Switch.H"
#include "pointFieldFwd.H" #include "pointFieldFwd.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -82,9 +83,18 @@ protected:
//- Output field values flag //- Output field values flag
Switch valueOutput_; Switch valueOutput_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Functions to be over-ridden from IOoutputFilter class // Functions to be over-ridden from IOoutputFilter class
//- Make the output file
virtual void makeFile();
//- Write the output file header
virtual void writeFileHeader() = 0;
//- Update mesh //- Update mesh
virtual void updateMesh(const mapPolyMesh&); virtual void updateMesh(const mapPolyMesh&);
@ -117,28 +127,28 @@ public:
// Access // Access
//- Return the name of the geometric source //- Return the name of the geometric source
const word& name() const; inline const word& name() const;
//- Return the reference to the object registry //- Return the reference to the object registry
const objectRegistry& obr() const; inline const objectRegistry& obr() const;
//- Return the active flag //- Return the active flag
bool active() const; inline bool active() const;
//- Return the switch to send output to Info as well as to file //- Return the switch to send output to Info as well as to file
const Switch& log() const; inline const Switch& log() const;
//- Return the source name //- Return the source name
const word& sourceName() const; inline const word& sourceName() const;
//- Return the list of field names //- Return the list of field names
const wordList& fields() const; inline const wordList& fields() const;
//- Return the output field values flag //- Return the output field values flag
const Switch& valueOutput() const; inline const Switch& valueOutput() const;
//- Helper function to return the reference to the mesh //- Helper function to return the reference to the mesh
const fvMesh& mesh() const; inline const fvMesh& mesh() const;
// Function object functions // Function object functions
@ -146,6 +156,9 @@ public:
//- Read from dictionary //- Read from dictionary
virtual void read(const dictionary& dict); virtual void read(const dictionary& dict);
//- Write to screen/file
virtual void write();
//- Execute //- Execute
virtual void execute(); virtual void execute();
@ -160,6 +173,10 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "fieldValueI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,79 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "fieldValue.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::word& Foam::fieldValue::name() const
{
return name_;
}
inline const Foam::objectRegistry& Foam::fieldValue::obr() const
{
return obr_;
}
inline bool Foam::fieldValue::active() const
{
return active_;
}
inline const Foam::Switch& Foam::fieldValue::log() const
{
return log_;
}
inline const Foam::word& Foam::fieldValue::sourceName() const
{
return sourceName_;
}
inline const Foam::wordList& Foam::fieldValue::fields() const
{
return fields_;
}
inline const Foam::Switch& Foam::fieldValue::valueOutput() const
{
return valueOutput_;
}
inline const Foam::fvMesh& Foam::fieldValue::mesh() const
{
return refCast<const fvMesh>(obr_);
}
// ************************************************************************* //