diff --git a/src/functionObjects/field/components/components.C b/src/functionObjects/field/components/components.C index 0ceb92d743..408a28fe42 100644 --- a/src/functionObjects/field/components/components.C +++ b/src/functionObjects/field/components/components.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,18 +41,23 @@ namespace functionObjects } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Implementation +#include "componentsImpl.C" + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // bool Foam::functionObjects::components::calc() { - bool processed = false; - - processed = processed || calcComponents(); - processed = processed || calcComponents(); - processed = processed || calcComponents(); - processed = processed || calcComponents(); - - return processed; + return + ( + calcComponents() + || calcComponents() + || calcComponents() + || calcComponents() + ); } diff --git a/src/functionObjects/field/components/components.H b/src/functionObjects/field/components/components.H index a594cdb99a..0d6281a2ee 100644 --- a/src/functionObjects/field/components/components.H +++ b/src/functionObjects/field/components/components.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -103,8 +103,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef functionObjects_components_H -#define functionObjects_components_H +#ifndef Foam_functionObjects_components_H +#define Foam_functionObjects_components_H #include "fieldExpression.H" @@ -134,14 +134,15 @@ class components //- Calculate the components of the field with the specified type //- and register the result template - bool calcFieldComponents(); + bool calcComponents(const GeoFieldType& field); //- Calculate the components of the field with the specified //- element type and register the result template bool calcComponents(); - //- Calculate the components of the field and return true if successful + //- Calculate the components of the field + // \return True if successful virtual bool calc(); @@ -189,12 +190,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository - #include "componentsTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/functionObjects/field/components/componentsTemplates.C b/src/functionObjects/field/components/componentsImpl.C similarity index 72% rename from src/functionObjects/field/components/componentsTemplates.C rename to src/functionObjects/field/components/componentsImpl.C index 64f152e6f4..5821580a29 100644 --- a/src/functionObjects/field/components/componentsTemplates.C +++ b/src/functionObjects/field/components/componentsImpl.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,19 +32,20 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -bool Foam::functionObjects::components::calcFieldComponents() +bool Foam::functionObjects::components::calcComponents +( + const GeoFieldType& field +) { typedef typename GeoFieldType::value_type Type; - const GeoFieldType& field = lookupObject(fieldName_); - - resultNames_.setSize(Type::nComponents); + resultNames_.resize(pTraits::nComponents); bool stored = true; - for (direction i = 0; i < Type::nComponents; ++i) + for (direction i = 0; i < pTraits::nComponents; ++i) { - resultName_ = fieldName_ + word(Type::componentNames[i]); + resultName_ = fieldName_ + word(pTraits::componentNames[i]); resultNames_[i] = resultName_; stored = stored && store(resultName_, field.component(i)); @@ -57,16 +58,16 @@ bool Foam::functionObjects::components::calcFieldComponents() template bool Foam::functionObjects::components::calcComponents() { - typedef GeometricField VolFieldType; - typedef GeometricField SurfaceFieldType; - - if (foundObject(fieldName_, false)) + const auto* vfield = cfindObject>(fieldName_); + if (vfield) { - return calcFieldComponents(); + return calcComponents(*vfield); } - else if (foundObject(fieldName_, false)) + + const auto* sfield = cfindObject>(fieldName_); + if (sfield) { - return calcFieldComponents(); + return calcComponents(*sfield); } return false; diff --git a/src/surfMesh/writers/raw/rawSurfaceWriter.C b/src/surfMesh/writers/raw/rawSurfaceWriter.C index 787d733afe..e06a9547d8 100644 --- a/src/surfMesh/writers/raw/rawSurfaceWriter.C +++ b/src/surfMesh/writers/raw/rawSurfaceWriter.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -158,7 +158,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write() // Header { os << "# geometry NO_DATA " << faces.size() << nl; - writeHeaderXYZ(os); + os << "# x y z"; if (withFaceNormal) { writeHeaderArea(os); diff --git a/src/surfMesh/writers/raw/rawSurfaceWriterImpl.C b/src/surfMesh/writers/raw/rawSurfaceWriterImpl.C index 928f421231..ae1247796d 100644 --- a/src/surfMesh/writers/raw/rawSurfaceWriterImpl.C +++ b/src/surfMesh/writers/raw/rawSurfaceWriterImpl.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -44,62 +44,38 @@ namespace Foam template static inline void writeData(Ostream& os, const Type& val) { - for (direction i=0; i < pTraits::nComponents; ++i) + for (direction d = 0; d < pTraits::nComponents; ++d) { - os << ' ' << component(val, i); + os << ' ' << component(val, d); } } - // Write x/y/z header. Must be called first - static inline void writeHeaderXYZ(Ostream& os) - { - os << "# x y z"; - } - // Write area header static inline void writeHeaderArea(Ostream& os) { os << " area_x area_y area_z"; } + // Write field name, use named components for VectorSpace template static inline void writeHeader(Ostream& os, const word& fieldName) - { - os << " " << fieldName; - } - - template - void writeHeaderComponents(Ostream& os, const word& fieldName) { os << ' '; - for (direction i=0; i < pTraits::nComponents; ++i) + + const auto nCmpts(pTraits::nComponents); + + if (pTraits::rank || nCmpts > 1) { - os << ' ' << fieldName << '_' << Type::componentNames[i]; + for (direction d = 0; d < nCmpts; ++d) + { + os << ' ' << fieldName + << '_' << pTraits::componentNames[d]; + } + } + else + { + os << ' ' << fieldName; } - } - - template<> - void writeHeader(Ostream& os, const word& fieldName) - { - writeHeaderComponents(os, fieldName); - } - - template<> - void writeHeader(Ostream& os, const word& fieldName) - { - writeHeaderComponents(os, fieldName); - } - - template<> - void writeHeader(Ostream& os, const word& fieldName) - { - writeHeaderComponents(os, fieldName); - } - - template<> - void writeHeader(Ostream& os, const word& fieldName) - { - writeHeaderComponents(os, fieldName); } } // End namespace Foam @@ -184,13 +160,13 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate } os << values.size() << nl; - writeHeaderXYZ(os); + os << "# x y z"; writeHeader(os, fieldName); if (withFaceNormal) { writeHeaderArea(os); } - os << nl; + os << nl; }