Merge branch 'master' of /home/noisy3/OpenFOAM/OpenFOAM-dev

This commit is contained in:
mattijs
2009-08-24 21:55:17 +01:00
21 changed files with 2928 additions and 0 deletions

View File

@ -6,4 +6,10 @@ fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.C
fieldMinMax/fieldMinMax.C
fieldMinMax/fieldMinMaxFunctionObject.C
fieldValues/fieldValue/fieldValue.C
fieldValues/face/faceSource.C
fieldValues/face/faceSourceFunctionObject.C
fieldValues/cell/cellSource.C
fieldValues/cell/cellSourceFunctionObject.C
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects

View File

@ -0,0 +1,51 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
// ************************************************************************* //

View File

@ -0,0 +1,257 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,227 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
// ************************************************************************* //

View File

@ -0,0 +1,47 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
(
functionObject,
cellSourceFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::cellSourceFunctionObject
Description
FunctionObject wrapper around cellSource to allow it to be
created via the functions list within controlDict.
SourceFiles
cellSourceFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef cellSourceFunctionObject_H
#define cellSourceFunctionObject_H
#include "cellSource.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<fieldValues::cellSource>
cellSourceFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::fieldValues::cellSource::sourceType&
Foam::fieldValues::cellSource::source() const
{
return source_;
}
inline const Foam::labelList&
Foam::fieldValues::cellSource::cellId() const
{
return cellId_;
}
// ************************************************************************* //

View File

@ -0,0 +1,175 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "volFields.H"
#include "IOList.H"
#include "ListListOps.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::fieldValues::cellSource::setFieldValues
(
const word& fieldName,
List<Type>& values
) const
{
values.setSize(cellId_.size(), pTraits<Type>::zero);
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (obr_.foundObject<vf>(fieldName))
{
const vf& field = obr_.lookupObject<vf>(fieldName);
forAll(values, i)
{
label cellI = cellId_[i];
values[i] = field[cellI];
}
return true;
}
return false;
}
template<class Type>
Type Foam::fieldValues::cellSource::processValues
(
const List<Type>& values
) const
{
Type result = pTraits<Type>::zero;
switch (operation_)
{
case opSum:
{
result = sum(values);
break;
}
case opVolAverage:
{
tmp<scalarField> V = filterField(mesh().V());
result = sum(values*V())/sum(V());
break;
}
case opVolIntegrate:
{
result = sum(values*filterField(mesh().V()));
break;
}
default:
{
// Do nothing
}
}
return result;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
{
List<List<Type> > allValues(Pstream::nProcs());
bool validField =
setFieldValues<Type>(fieldName, allValues[Pstream::myProcNo()]);
if (validField)
{
Pstream::gatherList(allValues);
if (Pstream::master())
{
List<Type> values =
ListListOps::combine<List<Type> >
(
allValues,
accessOp<List<Type> >()
);
Type result = processValues(values);
if (valueOutput_)
{
IOList<Type>
(
IOobject
(
fieldName + "_" + sourceTypeNames_[source_] + "-"
+ sourceName_,
obr_.time().timeName(),
obr_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
values
).write();
}
outputFilePtr_()<< tab << result;
if (log_)
{
Info<< " " << operationTypeNames_[operation_]
<< "(" << sourceName_ << ") for " << fieldName
<< " = " << result << endl;
}
}
}
return validField;
}
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::filterField
(
const Field<Type>& field
) const
{
tmp<Field<Type> > tvalues(new Field<Type>(cellId_.size()));
Field<Type>& values = tvalues();
forAll(values, i)
{
label cellI = cellId_[i];
values[i] = field[cellI];
}
return tvalues;
}
// ************************************************************************* //

View File

@ -0,0 +1,108 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.6 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression uncompressed;
timeFormat general;
timePrecision 6;
runTimeModifiable yes;
functions
(
faceObj1
{
type faceSource;
functionObjectLibs ("libfieldFunctionObjects.so");
enabled true;
outputControl outputTime;
log true;
valueOutput true;
source patch;
sourceName movingWall;
// source faceZone;
// sourceName f0;
operation areaAverage;
fields
(
p
phi
U
);
}
faceObj2
{
type faceSource;
functionObjectLibs ("libfieldFunctionObjects.so");
enabled true;
outputControl outputTime;
log true;
valueOutput true;
source faceZone;
sourceName f0;
operation sum;
fields
(
phi
);
}
cellObj1
{
type cellSource;
functionObjectLibs ("libfieldFunctionObjects.so");
enabled true;
outputControl outputTime;
log true;
valueOutput true;
source cellZone;
sourceName c0;
operation volAverage;
fields
(
p
U
);
}
);
// ************************************************************************* //

View File

@ -0,0 +1,51 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::IOfaceSource
Description
Instance of the generic IOOutputFilter for faceSource.
\*---------------------------------------------------------------------------*/
#ifndef IOfaceSource_H
#define IOfaceSource_H
#include "faceSource.H"
#include "IOOutputFilter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOOutputFilter<faceSource> IOfaceSource;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,368 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "faceSource.H"
#include "fvMesh.H"
#include "cyclicPolyPatch.H"
#include "emptyPolyPatch.H"
#include "processorPolyPatch.H"
#include "surfaceFields.H"
#include "volFields.H"
#include "IOList.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fieldValues
{
defineTypeNameAndDebug(faceSource, 0);
}
template<>
const char* NamedEnum<fieldValues::faceSource::sourceType, 2>::
names[] = {"faceZone", "patch"};
const NamedEnum<fieldValues::faceSource::sourceType, 2>
fieldValues::faceSource::sourceTypeNames_;
template<>
const char* NamedEnum<fieldValues::faceSource::operationType, 4>::
names[] = {"none", "sum", "areaAverage", "areaIntegrate"};
const NamedEnum<fieldValues::faceSource::operationType, 4>
fieldValues::faceSource::operationTypeNames_;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fieldValues::faceSource::setFaceZoneFaces()
{
label zoneId = mesh().faceZones().findZoneID(sourceName_);
if (zoneId < 0)
{
FatalErrorIn("faceSource::faceSource::setFaceZoneFaces()")
<< "Unknown face zone name: " << sourceName_
<< ". Valid face zones are: " << mesh().faceZones().names()
<< nl << exit(FatalError);
}
const faceZone& fZone = mesh().faceZones()[zoneId];
faceId_.setSize(fZone.size());
facePatchId_.setSize(fZone.size());
flipMap_.setSize(fZone.size());
label count = 0;
forAll(fZone, i)
{
label faceI = fZone[i];
label faceId = -1;
label facePatchId = -1;
if (mesh().isInternalFace(faceI))
{
faceId = faceI;
facePatchId = -1;
}
else
{
facePatchId = mesh().boundaryMesh().whichPatch(faceI);
const polyPatch& pp = mesh().boundaryMesh()[facePatchId];
if (isA<processorPolyPatch>(pp))
{
if (refCast<const processorPolyPatch>(pp).owner())
{
faceId = pp.whichFace(faceI);
}
else
{
faceId = -1;
}
}
else if (isA<cyclicPolyPatch>(pp))
{
label patchFaceI = faceI - pp.start();
if (patchFaceI < pp.size()/2)
{
faceId = patchFaceI;
}
else
{
faceId = -1;
}
}
else if (!isA<emptyPolyPatch>(pp))
{
faceId = faceI - pp.start();
}
else
{
faceId = -1;
facePatchId = -1;
}
}
if (faceId >= 0)
{
if (fZone.flipMap()[i])
{
flipMap_[count] = -1;
}
else
{
flipMap_[count] = 1;
}
faceId_[count] = faceId;
facePatchId_[count] = facePatchId;
count++;
}
}
faceId_.setSize(count);
facePatchId_.setSize(count);
flipMap_.setSize(count);
if (debug)
{
Info<< "Original face zone size = " << fZone.size()
<< ", new size = " << count << endl;
}
}
void Foam::fieldValues::faceSource::setPatchFaces()
{
label patchId = mesh().boundaryMesh().findPatchID(sourceName_);
if (patchId < 0)
{
FatalErrorIn("faceSource::constructFaceAddressing()")
<< "Unknown patch name: " << sourceName_
<< ". Valid patch names are: "
<< mesh().boundaryMesh().names() << nl
<< exit(FatalError);
}
const polyPatch& pp = mesh().boundaryMesh()[patchId];
label nFaces = pp.size();
if (isA<cyclicPolyPatch>(pp))
{
nFaces /= 2;
}
else if (isA<emptyPolyPatch>(pp))
{
nFaces = 0;
}
faceId_.setSize(nFaces);
facePatchId_.setSize(nFaces);
flipMap_.setSize(nFaces);
forAll(faceId_, faceI)
{
faceId_[faceI] = faceI;
facePatchId_[faceI] = patchId;
flipMap_[faceI] = 1;
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fieldValues::faceSource::initialise()
{
switch (source_)
{
case stFaceZone:
{
setFaceZoneFaces();
break;
}
case stPatch:
{
setPatchFaces();
break;
}
default:
{
FatalErrorIn("faceSource::constructFaceAddressing()")
<< "Unknown source type. Valid source types are:"
<< sourceTypeNames_ << nl << exit(FatalError);
}
}
Info<< type() << " " << name_ << ":" << nl
<< " total faces = " << faceId_.size() << nl
<< " total area = " << sum(filterField(mesh().magSf()))
<< nl << endl;
}
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()
{
if (outputFilePtr_.valid())
{
outputFilePtr_()
<< "# Source : " << sourceTypeNames_[source_] << " "
<< sourceName_ << nl << "# Faces : " << faceId_.size() << nl
<< "# Time" << tab << "sum(magSf)";
forAll(fields_, i)
{
outputFilePtr_()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
outputFilePtr_() << endl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fieldValues::faceSource::faceSource
(
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"))),
faceId_(),
facePatchId_(),
flipMap_(),
outputFilePtr_(NULL)
{
initialise();
if (active_)
{
// Create the output file if not already created
makeFile();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fieldValues::faceSource::~faceSource()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fieldValues::faceSource::read(const dictionary& dict)
{
if (active_)
{
fieldValue::read(dict);
initialise();
}
}
void Foam::fieldValues::faceSource::write()
{
if (active_)
{
if (log_)
{
Info<< type() << " " << name_ << " output:" << nl;
}
outputFilePtr_()
<< obr_.time().value() << tab
<< sum(filterField(mesh().magSf()));
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;
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,252 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::faceSource
Description
Face source variant of field value function object. Values of user-
specified fields reported for collections of faces.
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 faceZone; // Type of face source: faceZone, patch
sourceName f0;
operation sum; // none, sum, areaAverage, areaIntegrate
fields
(
p
phi
U
);
}
SourceFiles
faceSource.C
\*---------------------------------------------------------------------------*/
#ifndef faceSource_H
#define faceSource_H
#include "NamedEnum.H"
#include "fieldValue.H"
#include "labelList.H"
#include "OFstream.H"
#include "surfaceFieldsFwd.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class faceSource Declaration
\*---------------------------------------------------------------------------*/
class faceSource
:
public fieldValue
{
public:
// Public data types
//- Source type enumeration
enum sourceType
{
stFaceZone,
stPatch
};
//- Source type names
static const NamedEnum<sourceType, 2> sourceTypeNames_;
//- Operation type enumeration
enum operationType
{
opNone,
opSum,
opAreaAverage,
opAreaIntegrate
};
//- Operation type names
static const NamedEnum<operationType, 4> operationTypeNames_;
private:
// Private member functions
//- Set faces to evaluate based on a face zone
void setFaceZoneFaces();
//- Set faces to evaluate based on a patch
void setPatchFaces();
//- 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 face IDs
labelList faceId_;
//- Local list of patch ID per face
labelList facePatchId_;
//- List of +1/-1 representing face flip map
labelList flipMap_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Protected member functions
//- Initialise, e.g. face 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("faceSource");
//- Construct from components
faceSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles = false
);
//- Destructor
virtual ~faceSource();
// Public member functions
// Access
//- Return the source type
inline const sourceType& source() const;
//- Return the local list of face IDs
inline const labelList& faceId() const;
//- Return the local list of patch ID per face
inline const labelList& facePatch() const;
//- Return the list of +1/-1 representing face flip map
inline const labelList& flipMap() 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 surface field according to faceIds
template<class Type>
tmp<Field<Type> > filterField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& field
) const;
//- Filter a volume field according to faceIds
template<class Type>
tmp<Field<Type> > filterField
(
const GeometricField<Type, fvPatchField, volMesh>& field
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "faceSourceI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "faceSourceTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,47 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "faceSourceFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug
(
faceSourceFunctionObject,
0
);
addToRunTimeSelectionTable
(
functionObject,
faceSourceFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::faceSourceFunctionObject
Description
FunctionObject wrapper around faceSource to allow it to be
created via the functions list within controlDict.
SourceFiles
faceSourceFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef faceSourceFunctionObject_H
#define faceSourceFunctionObject_H
#include "faceSource.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<fieldValues::faceSource>
faceSourceFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "faceSource.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::fieldValues::faceSource::sourceType&
Foam::fieldValues::faceSource::source() const
{
return source_;
}
inline const Foam::labelList&
Foam::fieldValues::faceSource::faceId() const
{
return faceId_;
}
inline const Foam::labelList&
Foam::fieldValues::faceSource::facePatch() const
{
return facePatchId_;
}
inline const Foam::labelList&
Foam::fieldValues::faceSource::flipMap() const
{
return flipMap_;
}
// ************************************************************************* //

View File

@ -0,0 +1,269 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "faceSource.H"
#include "surfaceFields.H"
#include "volFields.H"
#include "IOList.H"
#include "ListListOps.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::fieldValues::faceSource::setFieldValues
(
const word& fieldName,
List<Type>& values
) const
{
values.setSize(faceId_.size(), pTraits<Type>::zero);
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (obr_.foundObject<sf>(fieldName))
{
const sf& field = obr_.lookupObject<sf>(fieldName);
forAll(values, i)
{
label faceI = faceId_[i];
label patchI = facePatchId_[i];
if (patchI >= 0)
{
values[i] = field.boundaryField()[patchI][faceI];
}
else
{
values[i] = field[faceI];
}
values[i] *= flipMap_[i];
}
return true;
}
else if (obr_.foundObject<vf>(fieldName))
{
const vf& field = obr_.lookupObject<vf>(fieldName);
forAll(values, i)
{
label faceI = faceId_[i];
label patchI = facePatchId_[i];
if (patchI >= 0)
{
values[i] = field.boundaryField()[patchI][faceI];
}
else
{
FatalErrorIn
(
"fieldValues::faceSource::setFieldValues"
"("
"const word&, "
"List<Type>&"
") const"
) << type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl
<< " Unable to process internal faces for volume field "
<< fieldName << nl << abort(FatalError);
}
values[i] *= flipMap_[i];
}
return true;
}
return false;
}
template<class Type>
Type Foam::fieldValues::faceSource::processValues
(
const List<Type>& values
) const
{
Type result = pTraits<Type>::zero;
switch (operation_)
{
case opSum:
{
result = sum(values);
break;
}
case opAreaAverage:
{
tmp<scalarField> magSf = filterField(mesh().magSf());
result = sum(values*magSf())/sum(magSf());
break;
}
case opAreaIntegrate:
{
result = sum(values*filterField(mesh().magSf()));
break;
}
default:
{
// Do nothing
}
}
return result;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
{
List<List<Type> > allValues(Pstream::nProcs());
bool validField =
setFieldValues<Type>(fieldName, allValues[Pstream::myProcNo()]);
if (validField)
{
Pstream::gatherList(allValues);
if (Pstream::master())
{
List<Type> values =
ListListOps::combine<List<Type> >
(
allValues,
accessOp<List<Type> >()
);
Type result = processValues(values);
if (valueOutput_)
{
IOList<Type>
(
IOobject
(
fieldName + "_" + sourceTypeNames_[source_] + "-"
+ sourceName_,
obr_.time().timeName(),
obr_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
values
).write();
}
outputFilePtr_()<< tab << result;
if (log_)
{
Info<< " " << operationTypeNames_[operation_]
<< "(" << sourceName_ << ") for " << fieldName
<< " = " << result << endl;
}
}
}
return validField;
}
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::filterField
(
const GeometricField<Type, fvPatchField, volMesh>& field
) const
{
tmp<Field<Type> > tvalues(new Field<Type>(faceId_.size()));
Field<Type>& values = tvalues();
forAll(values, i)
{
label faceI = faceId_[i];
label patchI = facePatchId_[i];
if (patchI >= 0)
{
values[i] = field.boundaryField()[patchI][faceI];
}
else
{
FatalErrorIn
(
"fieldValues::faceSource::filterField"
"("
"const GeometricField<Type, fvPatchField, volMesh>&"
") const"
) << type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl
<< " Unable to process internal faces for volume field "
<< field.name() << nl << abort(FatalError);
}
values[i] *= flipMap_[i];
}
return tvalues;
}
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::filterField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& field
) const
{
tmp<Field<Type> > tvalues(new Field<Type>(faceId_.size()));
Field<Type>& values = tvalues();
forAll(values, i)
{
label faceI = faceId_[i];
label patchI = facePatchId_[i];
if (patchI >= 0)
{
values[i] = field.boundaryField()[patchI][faceI];
}
else
{
values[i] = field[faceI];
}
values[i] *= flipMap_[i];
}
return tvalues;
}
// ************************************************************************* //

View File

@ -0,0 +1,177 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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"
#include "fvMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(fieldValue, 0);
defineTemplateTypeNameAndDebug(IOList<vector>, 0);
defineTemplateTypeNameAndDebug(IOList<sphericalTensor>, 0);
defineTemplateTypeNameAndDebug(IOList<symmTensor>, 0);
defineTemplateTypeNameAndDebug(IOList<tensor>, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fieldValue::updateMesh(const mapPolyMesh&)
{
// Do nothing
}
void Foam::fieldValue::movePoints(const Field<point>&)
{
// Do nothing
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fieldValue::fieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
name_(name),
obr_(obr),
active_(true),
log_(false),
sourceName_(dict.lookup("sourceName")),
fields_(dict.lookup("fields")),
valueOutput_(dict.lookup("valueOutput"))
{
// Only active if obr is an fvMesh
if (isA<fvMesh>(obr_))
{
read(dict);
}
else
{
WarningIn
(
"fieldValue::fieldValue"
"("
"const word&, "
"const objectRegistry&, "
"const dictionary&, "
"const bool"
")"
) << "No fvMesh available, deactivating."
<< nl << endl;
active_ = false;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fieldValue::~fieldValue()
{}
// * * * * * * * * * * * * * * * 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()
{
// Do nothing
}
void Foam::fieldValue::end()
{
// Do nothing
}
// ************************************************************************* //

View File

@ -0,0 +1,165 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fieldValue
Description
Base class for field value -based function objects.
SourceFiles
fieldValue.C
\*---------------------------------------------------------------------------*/
#ifndef fieldValue_H
#define fieldValue_H
#include "Switch.H"
#include "pointFieldFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class dictionary;
class objectRegistry;
class fvMesh;
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class fieldValue Declaration
\*---------------------------------------------------------------------------*/
class fieldValue
{
protected:
// Protected data
//- Name of this fieldValue object
word name_;
//- Database this class is registered to
const objectRegistry& obr_;
//- Active flag
bool active_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Name of source object
word sourceName_;
//- List of field names to operate on
wordList fields_;
//- Output field values flag
Switch valueOutput_;
// Functions to be over-ridden from IOoutputFilter class
//- Update mesh
virtual void updateMesh(const mapPolyMesh&);
//- Move points
virtual void movePoints(const Field<point>&);
public:
//- Run-time type information
TypeName("fieldValue");
//- Construct from components
fieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles = false
);
//- Destructor
virtual ~fieldValue();
// Public member functions
// Access
//- Return the name of the geometric source
const word& name() const;
//- Return the reference to the object registry
const objectRegistry& obr() const;
//- Return the active flag
bool active() const;
//- Return the switch to send output to Info as well as to file
const Switch& log() const;
//- Return the source name
const word& sourceName() const;
//- Return the list of field names
const wordList& fields() const;
//- Return the output field values flag
const Switch& valueOutput() const;
//- Helper funvction to return the reference to the mesh
const fvMesh& mesh() const;
// Function object functions
//- Read from dictionary
virtual void read(const dictionary& dict);
//- Execute
virtual void execute();
//- Execute the at the final time-loop, currently does nothing
virtual void end();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -15,6 +15,7 @@ wallFunctions = derivedFvPatchFields/wallFunctions
alphatWallFunctions = $(wallFunctions)/alphatWallFunctions
$(alphatWallFunctions)/alphatWallFunction/alphatWallFunctionFvPatchScalarField.C
$(alphatWallFunctions)/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.C
mutWallFunctions = $(wallFunctions)/mutWallFunctions
$(mutWallFunctions)/mutkRoughWallFunction/mutkRoughWallFunctionFvPatchScalarField.C

View File

@ -0,0 +1,316 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-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 "alphatJayatillekeWallFunctionFvPatchScalarField.H"
#include "RASModel.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
#include "wallFvPatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace compressible
{
namespace RASModels
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
scalar alphatJayatillekeWallFunctionFvPatchScalarField::maxExp_ = 50.0;
scalar alphatJayatillekeWallFunctionFvPatchScalarField::tolerance_ = 0.01;
label alphatJayatillekeWallFunctionFvPatchScalarField::maxIters_ = 10;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void alphatJayatillekeWallFunctionFvPatchScalarField::checkType()
{
if (!isA<wallFvPatch>(patch()))
{
FatalErrorIn
(
"alphatJayatillekeWallFunctionFvPatchScalarField::checkType()"
)
<< "Patch type for patch " << patch().name() << " must be wall\n"
<< "Current patch type is " << patch().type() << nl
<< exit(FatalError);
}
}
scalar alphatJayatillekeWallFunctionFvPatchScalarField::Psmooth
(
const scalar Prat
) const
{
return 9.24*(pow(Prat, 0.75) - 1.0)*(1.0 + 0.28*exp(-0.007*Prat));
}
scalar alphatJayatillekeWallFunctionFvPatchScalarField::yPlusTherm
(
const scalar P,
const scalar Prat
) const
{
scalar ypt = 11.0;
for (int i=0; i<maxIters_; i++)
{
scalar f = ypt - (log(E_*ypt)/kappa_ + P)/Prat;
scalar df = 1.0 - 1.0/(ypt*kappa_*Prat);
scalar yptNew = ypt - f/df;
if (yptNew < VSMALL)
{
return 0;
}
else if (mag(yptNew - ypt) < tolerance_)
{
return yptNew;
}
else
{
ypt = yptNew;
}
}
return ypt;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
alphatJayatillekeWallFunctionFvPatchScalarField::
alphatJayatillekeWallFunctionFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchScalarField(p, iF),
Prt_(0.85),
Cmu_(0.09),
kappa_(0.41),
E_(9.8)
{
checkType();
}
alphatJayatillekeWallFunctionFvPatchScalarField::
alphatJayatillekeWallFunctionFvPatchScalarField
(
const alphatJayatillekeWallFunctionFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchScalarField(ptf, p, iF, mapper),
Prt_(ptf.Prt_),
Cmu_(ptf.Cmu_),
kappa_(ptf.kappa_),
E_(ptf.E_)
{}
alphatJayatillekeWallFunctionFvPatchScalarField::
alphatJayatillekeWallFunctionFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchScalarField(p, iF, dict),
Prt_(dict.lookupOrDefault<scalar>("Prt", 0.85)),
Cmu_(dict.lookupOrDefault<scalar>("Cmu", 0.09)),
kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
E_(dict.lookupOrDefault<scalar>("E", 9.8))
{
checkType();
}
alphatJayatillekeWallFunctionFvPatchScalarField::
alphatJayatillekeWallFunctionFvPatchScalarField
(
const alphatJayatillekeWallFunctionFvPatchScalarField& awfpsf
)
:
fixedValueFvPatchScalarField(awfpsf),
Prt_(awfpsf.Prt_),
Cmu_(awfpsf.Cmu_),
kappa_(awfpsf.kappa_),
E_(awfpsf.E_)
{
checkType();
}
alphatJayatillekeWallFunctionFvPatchScalarField::
alphatJayatillekeWallFunctionFvPatchScalarField
(
const alphatJayatillekeWallFunctionFvPatchScalarField& awfpsf,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchScalarField(awfpsf, iF),
Prt_(awfpsf.Prt_),
Cmu_(awfpsf.Cmu_),
kappa_(awfpsf.kappa_),
E_(awfpsf.E_)
{
checkType();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void alphatJayatillekeWallFunctionFvPatchScalarField::updateCoeffs()
{
if (updated())
{
return;
}
const label patchI = patch().index();
const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
const scalar Cmu25 = pow(Cmu_, 0.25);
const scalarField& y = rasModel.y()[patchI];
const scalarField& muw = rasModel.mu().boundaryField()[patchI];
const scalarField& alphaw = rasModel.alpha().boundaryField()[patchI];
scalarField& alphatw = *this;
const tmp<volScalarField> tk = rasModel.k();
const volScalarField& k = tk();
const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI];
const scalarField magUp = mag(Uw.patchInternalField() - Uw);
const scalarField magGradUw = mag(Uw.snGrad());
const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
const fvPatchScalarField& hw =
patch().lookupPatchField<volScalarField, scalar>("h");
// Heat flux [W/m2] - lagging alphatw
const scalarField qDot = (alphaw + alphatw)*hw.snGrad();
// Populate boundary values
forAll(alphatw, faceI)
{
label faceCellI = patch().faceCells()[faceI];
scalar uTau = Cmu25*sqrt(k[faceCellI]);
scalar yPlus = uTau*y[faceI]/(muw[faceI]/rhow[faceI]);
// Molecular Prandtl number
scalar Pr = muw[faceI]/alphaw[faceI];
// Molecular-to-turbulenbt Prandtl number ratio
scalar Prat = Pr/Prt_;
// Thermal sublayer thickness
scalar P = Psmooth(Prat);
scalar yPlusTherm = this->yPlusTherm(P, Prat);
// Evaluate new effective thermal diffusivity
scalar alphaEff = 0.0;
if (yPlus < yPlusTherm)
{
scalar A = qDot[faceI]*rhow[faceI]*uTau*y[faceI];
scalar B = qDot[faceI]*Pr*yPlus;
scalar C = Pr*0.5*rhow[faceI]*uTau*sqr(magUp[faceI]);
alphaEff = A/(B + C + VSMALL);
}
else
{
scalar A = qDot[faceI]*rhow[faceI]*uTau*y[faceI];
scalar B = qDot[faceI]*Prt_*(1.0/kappa_*log(E_*yPlus) + P);
scalar magUc = uTau/kappa_*log(E_*yPlusTherm) - mag(Uw[faceI]);
scalar C =
0.5*rhow[faceI]*uTau
*(Prt_*sqr(magUp[faceI]) + (Pr - Prt_)*sqr(magUc));
alphaEff = A/(B + C + VSMALL);
}
// Update turbulent thermal diffusivity
alphatw[faceI] = max(0.0, alphaEff - alphaw[faceI]);
if (debug)
{
Info<< " uTau = " << uTau << nl
<< " Pr = " << Pr << nl
<< " Prt = " << Prt_ << nl
<< " qDot = " << qDot[faceI] << nl
<< " yPlus = " << yPlus << nl
<< " yPlusTherm = " << yPlusTherm << nl
<< " alphaEff = " << alphaEff << nl
<< " alphaw = " << alphaw[faceI] << nl
<< " alphatw = " << alphatw[faceI] << nl
<< endl;
}
}
fixedValueFvPatchField<scalar>::updateCoeffs();
}
void alphatJayatillekeWallFunctionFvPatchScalarField::write(Ostream& os) const
{
fvPatchField<scalar>::write(os);
os.writeKeyword("Prt") << Prt_ << token::END_STATEMENT << nl;
os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl;
os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeField
(
fvPatchScalarField,
alphatJayatillekeWallFunctionFvPatchScalarField
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace RASModels
} // End namespace compressible
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,195 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-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
alphatJayatillekeWallFunctionFvPatchScalarField
Description
Thermal wall function for turbulent thermal diffusivity based on the
Jayatilleke thermal wall function
SourceFiles
alphatJayatillekeWallFunctionFvPatchScalarField.C
\*---------------------------------------------------------------------------*/
#ifndef alphatJayatillekeWallFunctionFvPatchScalarField_H
#define alphatJayatillekeWallFunctionFvPatchScalarField_H
#include "fixedValueFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace compressible
{
namespace RASModels
{
/*---------------------------------------------------------------------------*\
Class alphatJayatillekeWallFunctionFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class alphatJayatillekeWallFunctionFvPatchScalarField
:
public fixedValueFvPatchScalarField
{
// Private data
//- Turbulent Prandtl number
scalar Prt_;
//- Cmu coefficient
scalar Cmu_;
//- Von Karman constant
scalar kappa_;
//- E coefficient
scalar E_;
// Solution parameters
static scalar maxExp_;
static scalar tolerance_;
static label maxIters_;
// Private member functions
//- Check the type of the patch
void checkType();
//- `P' function
scalar Psmooth(const scalar Prat) const;
//- Calculate y+ at the edge of the thermal laminar sublayer
scalar yPlusTherm
(
const scalar P,
const scalar Prat
) const;
public:
//- Runtime type information
TypeName("alphatJayatillekeWallFunction");
// Constructors
//- Construct from patch and internal field
alphatJayatillekeWallFunctionFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&
);
//- Construct from patch, internal field and dictionary
alphatJayatillekeWallFunctionFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const dictionary&
);
//- Construct by mapping given an
// alphatJayatillekeWallFunctionFvPatchScalarField
// onto a new patch
alphatJayatillekeWallFunctionFvPatchScalarField
(
const alphatJayatillekeWallFunctionFvPatchScalarField&,
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
alphatJayatillekeWallFunctionFvPatchScalarField
(
const alphatJayatillekeWallFunctionFvPatchScalarField&
);
//- Construct and return a clone
virtual tmp<fvPatchScalarField> clone() const
{
return tmp<fvPatchScalarField>
(
new alphatJayatillekeWallFunctionFvPatchScalarField(*this)
);
}
//- Construct as copy setting internal field reference
alphatJayatillekeWallFunctionFvPatchScalarField
(
const alphatJayatillekeWallFunctionFvPatchScalarField&,
const DimensionedField<scalar, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchScalarField> clone
(
const DimensionedField<scalar, volMesh>& iF
) const
{
return tmp<fvPatchScalarField>
(
new alphatJayatillekeWallFunctionFvPatchScalarField
(
*this,
iF
)
);
}
// Member functions
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
// I-O
//- Write
void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace RASModels
} // End namespace compressible
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //