From 77a08ec13187b4de3244149634a002d7c7864795 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 24 Aug 2009 16:20:31 +0100 Subject: [PATCH 1/3] added field face/cell values function objects --- .../field/fieldValues/Make/files | 9 + .../field/fieldValues/Make/options | 9 + .../field/fieldValues/cell/IOcellSource.H | 51 +++ .../field/fieldValues/cell/cellSource.C | 257 ++++++++++++ .../field/fieldValues/cell/cellSource.H | 227 +++++++++++ .../cell/cellSourceFunctionObject.C | 47 +++ .../cell/cellSourceFunctionObject.H | 55 +++ .../field/fieldValues/cell/cellSourceI.H | 46 +++ .../fieldValues/cell/cellSourceTemplates.C | 175 +++++++++ .../field/fieldValues/controlDict | 108 +++++ .../field/fieldValues/face/IOfaceSource.H | 51 +++ .../field/fieldValues/face/faceSource.C | 368 ++++++++++++++++++ .../field/fieldValues/face/faceSource.H | 252 ++++++++++++ .../face/faceSourceFunctionObject.C | 47 +++ .../face/faceSourceFunctionObject.H | 55 +++ .../field/fieldValues/face/faceSourceI.H | 60 +++ .../fieldValues/face/faceSourceTemplates.C | 269 +++++++++++++ .../field/fieldValues/fieldValue/fieldValue.C | 177 +++++++++ .../field/fieldValues/fieldValue/fieldValue.H | 165 ++++++++ 19 files changed, 2428 insertions(+) create mode 100644 src/postProcessing/functionObjects/field/fieldValues/Make/files create mode 100644 src/postProcessing/functionObjects/field/fieldValues/Make/options create mode 100644 src/postProcessing/functionObjects/field/fieldValues/cell/IOcellSource.H create mode 100644 src/postProcessing/functionObjects/field/fieldValues/cell/cellSource.C create mode 100644 src/postProcessing/functionObjects/field/fieldValues/cell/cellSource.H create mode 100644 src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceFunctionObject.C create mode 100644 src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceFunctionObject.H create mode 100644 src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceI.H create mode 100644 src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceTemplates.C create mode 100644 src/postProcessing/functionObjects/field/fieldValues/controlDict create mode 100644 src/postProcessing/functionObjects/field/fieldValues/face/IOfaceSource.H create mode 100644 src/postProcessing/functionObjects/field/fieldValues/face/faceSource.C create mode 100644 src/postProcessing/functionObjects/field/fieldValues/face/faceSource.H create mode 100644 src/postProcessing/functionObjects/field/fieldValues/face/faceSourceFunctionObject.C create mode 100644 src/postProcessing/functionObjects/field/fieldValues/face/faceSourceFunctionObject.H create mode 100644 src/postProcessing/functionObjects/field/fieldValues/face/faceSourceI.H create mode 100644 src/postProcessing/functionObjects/field/fieldValues/face/faceSourceTemplates.C create mode 100644 src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C create mode 100644 src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H diff --git a/src/postProcessing/functionObjects/field/fieldValues/Make/files b/src/postProcessing/functionObjects/field/fieldValues/Make/files new file mode 100644 index 0000000000..66028b4812 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/Make/files @@ -0,0 +1,9 @@ +fieldValue/fieldValue.C + +face/faceSource.C +face/faceSourceFunctionObject.C + +cell/cellSource.C +cell/cellSourceFunctionObject.C + +LIB = $(FOAM_LIBBIN)/libfieldValueFunctionObjects diff --git a/src/postProcessing/functionObjects/field/fieldValues/Make/options b/src/postProcessing/functionObjects/field/fieldValues/Make/options new file mode 100644 index 0000000000..5166bcc9e3 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/Make/options @@ -0,0 +1,9 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude + +LIB_LIBS = \ + -lfiniteVolume \ + -lmeshTools \ + -lsampling diff --git a/src/postProcessing/functionObjects/field/fieldValues/cell/IOcellSource.H b/src/postProcessing/functionObjects/field/fieldValues/cell/IOcellSource.H new file mode 100644 index 0000000000..b116bb96fd --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/cell/IOcellSource.H @@ -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 IOcellSource; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/cell/cellSource.C b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSource.C new file mode 100644 index 0000000000..5e63d1287a --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSource.C @@ -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:: + names[] = {"cellZone"}; + + const NamedEnum + fieldValues::cellSource::sourceTypeNames_; + + template<> + const char* NamedEnum:: + names[] = {"none", "sum", "volAverage", "volIntegrate"}; + + const NamedEnum + 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(fields_[i]); + writeValues(fields_[i]); + writeValues(fields_[i]); + writeValues(fields_[i]); + writeValues(fields_[i]); + } + + outputFilePtr_()<< endl; + + if (log_) + { + Info<< endl; + } + } +} + + +// ************************************************************************* // + diff --git a/src/postProcessing/functionObjects/field/fieldValues/cell/cellSource.H b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSource.H new file mode 100644 index 0000000000..d1d08cdbd9 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSource.H @@ -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 sourceTypeNames_; + + + //- Operation type enumeration + enum operationType + { + opNone, + opSum, + opVolAverage, + opVolIntegrate + }; + + //- Operation type names + static const NamedEnum 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 outputFilePtr_; + + + // Protected member functions + + //- Initialise, e.g. cell addressing + void initialise(); + + //- Insert field values into values list + template + bool setFieldValues + ( + const word& fieldName, + List& values + ) const; + + //- Apply the 'operation' to the values + template + Type processValues(const List& 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 + bool writeValues(const word& fieldName); + + //- Filter a field according to cellIds + template + tmp > filterField(const Field& field) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fieldValues +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "cellSourceI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "cellSourceTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceFunctionObject.C b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceFunctionObject.C new file mode 100644 index 0000000000..24f4b7bbb8 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceFunctionObject.C @@ -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 + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceFunctionObject.H b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceFunctionObject.H new file mode 100644 index 0000000000..eca172a58d --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceFunctionObject.H @@ -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 + cellSourceFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceI.H b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceI.H new file mode 100644 index 0000000000..b86462d2cc --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceI.H @@ -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_; +} + + +// ************************************************************************* // + diff --git a/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceTemplates.C new file mode 100644 index 0000000000..0b6fa1ff03 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/cell/cellSourceTemplates.C @@ -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 +bool Foam::fieldValues::cellSource::setFieldValues +( + const word& fieldName, + List& values +) const +{ + values.setSize(cellId_.size(), pTraits::zero); + + typedef GeometricField vf; + + if (obr_.foundObject(fieldName)) + { + const vf& field = obr_.lookupObject(fieldName); + + forAll(values, i) + { + label cellI = cellId_[i]; + values[i] = field[cellI]; + } + + return true; + } + + return false; +} + + +template +Type Foam::fieldValues::cellSource::processValues +( + const List& values +) const +{ + Type result = pTraits::zero; + switch (operation_) + { + case opSum: + { + result = sum(values); + break; + } + case opVolAverage: + { + tmp 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 +bool Foam::fieldValues::cellSource::writeValues(const word& fieldName) +{ + List > allValues(Pstream::nProcs()); + + bool validField = + setFieldValues(fieldName, allValues[Pstream::myProcNo()]); + + if (validField) + { + Pstream::gatherList(allValues); + + if (Pstream::master()) + { + List values = + ListListOps::combine > + ( + allValues, + accessOp >() + ); + + Type result = processValues(values); + + if (valueOutput_) + { + IOList + ( + 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 +Foam::tmp > Foam::fieldValues::cellSource::filterField +( + const Field& field +) const +{ + tmp > tvalues(new Field(cellId_.size())); + Field& values = tvalues(); + + forAll(values, i) + { + label cellI = cellId_[i]; + values[i] = field[cellI]; + } + + return tvalues; +} + + +// ************************************************************************* // + diff --git a/src/postProcessing/functionObjects/field/fieldValues/controlDict b/src/postProcessing/functionObjects/field/fieldValues/controlDict new file mode 100644 index 0000000000..88ea120317 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/controlDict @@ -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 ("libfieldValueFunctionObjects.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 ("libfieldValueFunctionObjects.so"); + enabled true; + outputControl outputTime; + log true; + valueOutput true; + source faceZone; + sourceName f0; + operation sum; + fields + ( + phi + ); + } + + cellObj1 + { + type cellSource; + functionObjectLibs ("libfieldValueFunctionObjects.so"); + enabled true; + outputControl outputTime; + log true; + valueOutput true; + source cellZone; + sourceName c0; + operation volAverage; + fields + ( + p + U + ); + } +); + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/IOfaceSource.H b/src/postProcessing/functionObjects/field/fieldValues/face/IOfaceSource.H new file mode 100644 index 0000000000..caca9968c6 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/face/IOfaceSource.H @@ -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 IOfaceSource; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.C new file mode 100644 index 0000000000..76c1ac9515 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.C @@ -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:: + names[] = {"faceZone", "patch"}; + + const NamedEnum + fieldValues::faceSource::sourceTypeNames_; + + template<> + const char* NamedEnum:: + names[] = {"none", "sum", "areaAverage", "areaIntegrate"}; + + const NamedEnum + 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(pp)) + { + if (refCast(pp).owner()) + { + faceId = pp.whichFace(faceI); + } + else + { + faceId = -1; + } + } + else if (isA(pp)) + { + label patchFaceI = faceI - pp.start(); + if (patchFaceI < pp.size()/2) + { + faceId = patchFaceI; + } + else + { + faceId = -1; + } + } + else if (!isA(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(pp)) + { + nFaces /= 2; + } + else if (isA(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(fields_[i]); + writeValues(fields_[i]); + writeValues(fields_[i]); + writeValues(fields_[i]); + writeValues(fields_[i]); + } + + outputFilePtr_()<< endl; + + if (log_) + { + Info<< endl; + } + } +} + + +// ************************************************************************* // + diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.H new file mode 100644 index 0000000000..fa89fcdd6c --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSource.H @@ -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 sourceTypeNames_; + + + //- Operation type enumeration + enum operationType + { + opNone, + opSum, + opAreaAverage, + opAreaIntegrate + }; + + //- Operation type names + static const NamedEnum 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 outputFilePtr_; + + + // Protected member functions + + //- Initialise, e.g. face addressing + void initialise(); + + //- Insert field values into values list + template + bool setFieldValues + ( + const word& fieldName, + List& values + ) const; + + //- Apply the 'operation' to the values + template + Type processValues(const List& 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 + bool writeValues(const word& fieldName); + + //- Filter a surface field according to faceIds + template + tmp > filterField + ( + const GeometricField& field + ) const; + + //- Filter a volume field according to faceIds + template + tmp > filterField + ( + const GeometricField& field + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fieldValues +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "faceSourceI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "faceSourceTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceFunctionObject.C b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceFunctionObject.C new file mode 100644 index 0000000000..12019c86c2 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceFunctionObject.C @@ -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 + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceFunctionObject.H b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceFunctionObject.H new file mode 100644 index 0000000000..54d717f870 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceFunctionObject.H @@ -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 + faceSourceFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceI.H b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceI.H new file mode 100644 index 0000000000..9d86255c36 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceI.H @@ -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_; +} + + +// ************************************************************************* // + diff --git a/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceTemplates.C new file mode 100644 index 0000000000..ced2ee82ee --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/face/faceSourceTemplates.C @@ -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 +bool Foam::fieldValues::faceSource::setFieldValues +( + const word& fieldName, + List& values +) const +{ + values.setSize(faceId_.size(), pTraits::zero); + + typedef GeometricField sf; + typedef GeometricField vf; + + if (obr_.foundObject(fieldName)) + { + const sf& field = obr_.lookupObject(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(fieldName)) + { + const vf& field = obr_.lookupObject(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&" + ") 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 +Type Foam::fieldValues::faceSource::processValues +( + const List& values +) const +{ + Type result = pTraits::zero; + switch (operation_) + { + case opSum: + { + result = sum(values); + break; + } + case opAreaAverage: + { + tmp 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 +bool Foam::fieldValues::faceSource::writeValues(const word& fieldName) +{ + List > allValues(Pstream::nProcs()); + + bool validField = + setFieldValues(fieldName, allValues[Pstream::myProcNo()]); + + if (validField) + { + Pstream::gatherList(allValues); + + if (Pstream::master()) + { + List values = + ListListOps::combine > + ( + allValues, + accessOp >() + ); + + Type result = processValues(values); + + if (valueOutput_) + { + IOList + ( + 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 +Foam::tmp > Foam::fieldValues::faceSource::filterField +( + const GeometricField& field +) const +{ + tmp > tvalues(new Field(faceId_.size())); + Field& 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&" + ") 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 +Foam::tmp > Foam::fieldValues::faceSource::filterField +( + const GeometricField& field +) const +{ + tmp > tvalues(new Field(faceId_.size())); + Field& 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; +} + + +// ************************************************************************* // + diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C new file mode 100644 index 0000000000..36b88d5e81 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C @@ -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, 0); + defineTemplateTypeNameAndDebug(IOList, 0); + defineTemplateTypeNameAndDebug(IOList, 0); + defineTemplateTypeNameAndDebug(IOList, 0); +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::fieldValue::updateMesh(const mapPolyMesh&) +{ + // Do nothing +} + + +void Foam::fieldValue::movePoints(const Field&) +{ + // 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(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(obr_); +} + + +void Foam::fieldValue::read(const dictionary& dict) +{ + if (active_) + { + log_ = dict.lookupOrDefault("log", false); + dict.lookup("fields") >> fields_; + dict.lookup("valueOutput") >> valueOutput_; + } +} + + +void Foam::fieldValue::execute() +{ + // Do nothing +} + + +void Foam::fieldValue::end() +{ + // Do nothing +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H new file mode 100644 index 0000000000..cdedaae131 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H @@ -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&); + + +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 + +// ************************************************************************* // From cf25c46400f38574ed2eab3c60b619a9bed98f75 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 24 Aug 2009 16:23:05 +0100 Subject: [PATCH 2/3] added RAS variant of the Jayatilleke thermal wall function --- .../compressible/RAS/Make/files | 1 + ...ayatillekeWallFunctionFvPatchScalarField.C | 316 ++++++++++++++++++ ...ayatillekeWallFunctionFvPatchScalarField.H | 195 +++++++++++ 3 files changed, 512 insertions(+) create mode 100644 src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/alphatWallFunctions/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.C create mode 100644 src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/alphatWallFunctions/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.H diff --git a/src/turbulenceModels/compressible/RAS/Make/files b/src/turbulenceModels/compressible/RAS/Make/files index 1329745581..ed01f0592e 100644 --- a/src/turbulenceModels/compressible/RAS/Make/files +++ b/src/turbulenceModels/compressible/RAS/Make/files @@ -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 diff --git a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/alphatWallFunctions/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.C b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/alphatWallFunctions/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.C new file mode 100644 index 0000000000..e8fdf3edd5 --- /dev/null +++ b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/alphatWallFunctions/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.C @@ -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(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& 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& 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& iF, + const dictionary& dict +) +: + fixedValueFvPatchScalarField(p, iF, dict), + Prt_(dict.lookupOrDefault("Prt", 0.85)), + Cmu_(dict.lookupOrDefault("Cmu", 0.09)), + kappa_(dict.lookupOrDefault("kappa", 0.41)), + E_(dict.lookupOrDefault("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& 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("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 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("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::updateCoeffs(); +} + + +void alphatJayatillekeWallFunctionFvPatchScalarField::write(Ostream& os) const +{ + fvPatchField::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 + +// ************************************************************************* // diff --git a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/alphatWallFunctions/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.H b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/alphatWallFunctions/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.H new file mode 100644 index 0000000000..6b5ce3bd72 --- /dev/null +++ b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/alphatWallFunctions/alphatJayatillekeWallFunction/alphatJayatillekeWallFunctionFvPatchScalarField.H @@ -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& + ); + + //- Construct from patch, internal field and dictionary + alphatJayatillekeWallFunctionFvPatchScalarField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given an + // alphatJayatillekeWallFunctionFvPatchScalarField + // onto a new patch + alphatJayatillekeWallFunctionFvPatchScalarField + ( + const alphatJayatillekeWallFunctionFvPatchScalarField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + alphatJayatillekeWallFunctionFvPatchScalarField + ( + const alphatJayatillekeWallFunctionFvPatchScalarField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new alphatJayatillekeWallFunctionFvPatchScalarField(*this) + ); + } + + //- Construct as copy setting internal field reference + alphatJayatillekeWallFunctionFvPatchScalarField + ( + const alphatJayatillekeWallFunctionFvPatchScalarField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + 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 + +// ************************************************************************* // From 5623ba449a8e25eaf12ed35bb4e92c9c11f75b8c Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 24 Aug 2009 17:10:53 +0100 Subject: [PATCH 3/3] added fieldValues to field function objects library --- src/postProcessing/functionObjects/field/Make/files | 6 ++++++ .../functionObjects/field/fieldValues/Make/files | 9 --------- .../functionObjects/field/fieldValues/Make/options | 9 --------- .../functionObjects/field/fieldValues/controlDict | 6 +++--- 4 files changed, 9 insertions(+), 21 deletions(-) delete mode 100644 src/postProcessing/functionObjects/field/fieldValues/Make/files delete mode 100644 src/postProcessing/functionObjects/field/fieldValues/Make/options diff --git a/src/postProcessing/functionObjects/field/Make/files b/src/postProcessing/functionObjects/field/Make/files index e300214731..3766cb0ba8 100644 --- a/src/postProcessing/functionObjects/field/Make/files +++ b/src/postProcessing/functionObjects/field/Make/files @@ -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 diff --git a/src/postProcessing/functionObjects/field/fieldValues/Make/files b/src/postProcessing/functionObjects/field/fieldValues/Make/files deleted file mode 100644 index 66028b4812..0000000000 --- a/src/postProcessing/functionObjects/field/fieldValues/Make/files +++ /dev/null @@ -1,9 +0,0 @@ -fieldValue/fieldValue.C - -face/faceSource.C -face/faceSourceFunctionObject.C - -cell/cellSource.C -cell/cellSourceFunctionObject.C - -LIB = $(FOAM_LIBBIN)/libfieldValueFunctionObjects diff --git a/src/postProcessing/functionObjects/field/fieldValues/Make/options b/src/postProcessing/functionObjects/field/fieldValues/Make/options deleted file mode 100644 index 5166bcc9e3..0000000000 --- a/src/postProcessing/functionObjects/field/fieldValues/Make/options +++ /dev/null @@ -1,9 +0,0 @@ -EXE_INC = \ - -I$(LIB_SRC)/finiteVolume/lnInclude \ - -I$(LIB_SRC)/meshTools/lnInclude \ - -I$(LIB_SRC)/sampling/lnInclude - -LIB_LIBS = \ - -lfiniteVolume \ - -lmeshTools \ - -lsampling diff --git a/src/postProcessing/functionObjects/field/fieldValues/controlDict b/src/postProcessing/functionObjects/field/fieldValues/controlDict index 88ea120317..7d9ab1f656 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/controlDict +++ b/src/postProcessing/functionObjects/field/fieldValues/controlDict @@ -50,7 +50,7 @@ functions faceObj1 { type faceSource; - functionObjectLibs ("libfieldValueFunctionObjects.so"); + functionObjectLibs ("libfieldFunctionObjects.so"); enabled true; outputControl outputTime; log true; @@ -71,7 +71,7 @@ functions faceObj2 { type faceSource; - functionObjectLibs ("libfieldValueFunctionObjects.so"); + functionObjectLibs ("libfieldFunctionObjects.so"); enabled true; outputControl outputTime; log true; @@ -88,7 +88,7 @@ functions cellObj1 { type cellSource; - functionObjectLibs ("libfieldValueFunctionObjects.so"); + functionObjectLibs ("libfieldFunctionObjects.so"); enabled true; outputControl outputTime; log true;