Commit 77a08ec1 authored by Andrew Heather's avatar Andrew Heather
Browse files

added field face/cell values function objects

parent 91fca60f
fieldValue/fieldValue.C
face/faceSource.C
face/faceSourceFunctionObject.C
cell/cellSource.C
cell/cellSourceFunctionObject.C
LIB = $(FOAM_LIBBIN)/libfieldValueFunctionObjects
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude
LIB_LIBS = \
-lfiniteVolume \
-lmeshTools \
-lsampling
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
Typedef
Foam::IOcellSource
Description
Instance of the generic IOOutputFilter for cellSource.
\*---------------------------------------------------------------------------*/
#ifndef IOcellSource_H
#define IOcellSource_H
#include "cellSource.H"
#include "IOOutputFilter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOOutputFilter<cellSource> IOcellSource;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "cellSource.H"
#include "fvMesh.H"
#include "volFields.H"
#include "IOList.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fieldValues
{
defineTypeNameAndDebug(cellSource, 0);
}
template<>
const char* NamedEnum<fieldValues::cellSource::sourceType, 1>::
names[] = {"cellZone"};
const NamedEnum<fieldValues::cellSource::sourceType, 1>
fieldValues::cellSource::sourceTypeNames_;
template<>
const char* NamedEnum<fieldValues::cellSource::operationType, 4>::
names[] = {"none", "sum", "volAverage", "volIntegrate"};
const NamedEnum<fieldValues::cellSource::operationType, 4>
fieldValues::cellSource::operationTypeNames_;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fieldValues::cellSource::setCellZoneCells()
{
label zoneId = mesh().cellZones().findZoneID(sourceName_);
if (zoneId < 0)
{
FatalErrorIn("cellSource::cellSource::setCellZoneCells()")
<< "Unknown cell zone name: " << sourceName_
<< ". Valid cell zones are: " << mesh().cellZones().names()
<< nl << exit(FatalError);
}
const cellZone& cZone = mesh().cellZones()[zoneId];
cellId_.setSize(cZone.size());
label count = 0;
forAll(cZone, i)
{
label cellI = cZone[i];
cellId_[count] = cellI;
count++;
}
cellId_.setSize(count);
if (debug)
{
Info<< "Original cell zone size = " << cZone.size()
<< ", new size = " << count << endl;
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fieldValues::cellSource::initialise()
{
switch (source_)
{
case stCellZone:
{
setCellZoneCells();
break;
}
default:
{
FatalErrorIn("cellSource::constructCellAddressing()")
<< "Unknown source type. Valid source types are:"
<< sourceTypeNames_ << nl << exit(FatalError);
}
}
Info<< type() << " " << name_ << ":" << nl
<< " total cells = " << cellId_.size() << nl
<< " total volume = " << sum(filterField(mesh().V()))
<< nl << endl;
}
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()
{
if (outputFilePtr_.valid())
{
outputFilePtr_()
<< "# Source : " << sourceTypeNames_[source_] << " "
<< sourceName_ << nl << "# Cells : " << cellId_.size() << nl
<< "# Time" << tab << "sum(V)";
forAll(fields_, i)
{
outputFilePtr_()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
outputFilePtr_() << endl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fieldValues::cellSource::cellSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
fieldValue(name, obr, dict, loadFromFiles),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
cellId_(),
outputFilePtr_(NULL)
{
initialise();
if (active_)
{
// Create the output file if not already created
makeFile();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fieldValues::cellSource::~cellSource()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fieldValues::cellSource::read(const dictionary& dict)
{
if (active_)
{
fieldValue::read(dict);
initialise();
}
}
void Foam::fieldValues::cellSource::write()
{
if (active_)
{
if (log_)
{
Info<< type() << " " << name_ << " output:" << nl;
}
outputFilePtr_()
<< obr_.time().value() << tab
<< sum(filterField(mesh().V()));
forAll(fields_, i)
{
writeValues<scalar>(fields_[i]);
writeValues<vector>(fields_[i]);
writeValues<sphericalTensor>(fields_[i]);
writeValues<symmTensor>(fields_[i]);
writeValues<tensor>(fields_[i]);
}
outputFilePtr_()<< endl;
if (log_)
{
Info<< endl;
}
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
Class
Foam::fieldValues::cellSource
Description
Cell source variant of field value function object. Values of user-
specified fields reported for collections of cells.
cellObj1 // Name also used to identify output folder
{
type cellSource;
functionObjectLibs ("libfieldValueFunctionObjects.so");
enabled true;
outputControl outputTime;
log true; // log to screen?
valueOutput true; // Write values at run-time output times?
source cellZone; // Type of cell source
sourceName c0;
operation volAverage; // none, sum, volAverage, volIntegrate
fields
(
p
U
);
}
SourceFiles
cellSource.C
\*---------------------------------------------------------------------------*/
#ifndef cellSource_H
#define cellSource_H
#include "NamedEnum.H"
#include "fieldValue.H"
#include "labelList.H"
#include "OFstream.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class cellSource Declaration
\*---------------------------------------------------------------------------*/
class cellSource
:
public fieldValue
{
public:
// Public data types
//- Source type enumeration
enum sourceType
{
stCellZone
};
//- Source type names
static const NamedEnum<sourceType, 1> sourceTypeNames_;
//- Operation type enumeration
enum operationType
{
opNone,
opSum,
opVolAverage,
opVolIntegrate
};
//- Operation type names
static const NamedEnum<operationType, 4> operationTypeNames_;
private:
// Private member functions
//- Set cells to evaluate based on a cell zone
void setCellZoneCells();
//- Set cells to evaluate based on a patch
void setPatchCells();
//- Create the output file if not already created
void makeFile();
protected:
// Protected data
//- Source type
sourceType source_;
//- Operation to apply to values
operationType operation_;
//- Local list of cell IDs
labelList cellId_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Protected member functions
//- Initialise, e.g. cell addressing
void initialise();
//- Insert field values into values list
template<class Type>
bool setFieldValues
(
const word& fieldName,
List<Type>& values
) const;
//- Apply the 'operation' to the values
template<class Type>
Type processValues(const List<Type>& values) const;
//- Output file header information
virtual void writeFileHeader();
public:
//- Run-time type information
TypeName("cellSource");
//- Construct from components
cellSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles = false
);
//- Destructor
virtual ~cellSource();
// Public member functions
// Access
//- Return the source type
inline const sourceType& source() const;
//- Return the local list of cell IDs
inline const labelList& cellId() const;
// Function object functions
//- Read from dictionary
virtual void read(const dictionary&);
//- Calculate and write
virtual void write();
//- Templated helper function to output field values
template<class Type>
bool writeValues(const word& fieldName);
//- Filter a field according to cellIds
template<class Type>
tmp<Field<Type> > filterField(const Field<Type>& field) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "cellSourceI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "cellSourceTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "cellSourceFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug
(
cellSourceFunctionObject,
0
);
addToRunTimeSelectionTable
(