ENH: simplify component handling

- raw writer, components functionObject
This commit is contained in:
Mark Olesen
2022-01-31 17:46:35 +01:00
parent 7db2a29413
commit fb4fe06306
5 changed files with 56 additions and 79 deletions

View File

@ -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<vector>();
processed = processed || calcComponents<sphericalTensor>();
processed = processed || calcComponents<symmTensor>();
processed = processed || calcComponents<tensor>();
return processed;
return
(
calcComponents<vector>()
|| calcComponents<sphericalTensor>()
|| calcComponents<symmTensor>()
|| calcComponents<tensor>()
);
}

View File

@ -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<class GeoFieldType>
bool calcFieldComponents();
bool calcComponents(const GeoFieldType& field);
//- Calculate the components of the field with the specified
//- element type and register the result
template<class Type>
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
// ************************************************************************* //

View File

@ -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<class GeoFieldType>
bool Foam::functionObjects::components::calcFieldComponents()
bool Foam::functionObjects::components::calcComponents
(
const GeoFieldType& field
)
{
typedef typename GeoFieldType::value_type Type;
const GeoFieldType& field = lookupObject<GeoFieldType>(fieldName_);
resultNames_.setSize(Type::nComponents);
resultNames_.resize(pTraits<Type>::nComponents);
bool stored = true;
for (direction i = 0; i < Type::nComponents; ++i)
for (direction i = 0; i < pTraits<Type>::nComponents; ++i)
{
resultName_ = fieldName_ + word(Type::componentNames[i]);
resultName_ = fieldName_ + word(pTraits<Type>::componentNames[i]);
resultNames_[i] = resultName_;
stored = stored && store(resultName_, field.component(i));
@ -57,16 +58,16 @@ bool Foam::functionObjects::components::calcFieldComponents()
template<class Type>
bool Foam::functionObjects::components::calcComponents()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
if (foundObject<VolFieldType>(fieldName_, false))
const auto* vfield = cfindObject<VolumeField<Type>>(fieldName_);
if (vfield)
{
return calcFieldComponents<VolFieldType>();
return calcComponents(*vfield);
}
else if (foundObject<SurfaceFieldType>(fieldName_, false))
const auto* sfield = cfindObject<SurfaceField<Type>>(fieldName_);
if (sfield)
{
return calcFieldComponents<SurfaceFieldType>();
return calcComponents(*sfield);
}
return false;