From 77a08ec13187b4de3244149634a002d7c7864795 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 24 Aug 2009 16:20:31 +0100 Subject: [PATCH] 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 + +// ************************************************************************* //