mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: simplify component handling
- raw writer, components functionObject
This commit is contained in:
@ -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>()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
||||
@ -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<class Type>
|
||||
static inline void writeData(Ostream& os, const Type& val)
|
||||
{
|
||||
for (direction i=0; i < pTraits<Type>::nComponents; ++i)
|
||||
for (direction d = 0; d < pTraits<Type>::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<class Type>
|
||||
static inline void writeHeader(Ostream& os, const word& fieldName)
|
||||
{
|
||||
os << " " << fieldName;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void writeHeaderComponents(Ostream& os, const word& fieldName)
|
||||
{
|
||||
os << ' ';
|
||||
for (direction i=0; i < pTraits<Type>::nComponents; ++i)
|
||||
{
|
||||
os << ' ' << fieldName << '_' << Type::componentNames[i];
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void writeHeader<vector>(Ostream& os, const word& fieldName)
|
||||
{
|
||||
writeHeaderComponents<vector>(os, fieldName);
|
||||
}
|
||||
const auto nCmpts(pTraits<Type>::nComponents);
|
||||
|
||||
template<>
|
||||
void writeHeader<sphericalTensor>(Ostream& os, const word& fieldName)
|
||||
if (pTraits<Type>::rank || nCmpts > 1)
|
||||
{
|
||||
writeHeaderComponents<sphericalTensor>(os, fieldName);
|
||||
for (direction d = 0; d < nCmpts; ++d)
|
||||
{
|
||||
os << ' ' << fieldName
|
||||
<< '_' << pTraits<Type>::componentNames[d];
|
||||
}
|
||||
|
||||
template<>
|
||||
void writeHeader<symmTensor>(Ostream& os, const word& fieldName)
|
||||
{
|
||||
writeHeaderComponents<symmTensor>(os, fieldName);
|
||||
}
|
||||
|
||||
template<>
|
||||
void writeHeader<tensor>(Ostream& os, const word& fieldName)
|
||||
else
|
||||
{
|
||||
writeHeaderComponents<tensor>(os, fieldName);
|
||||
os << ' ' << fieldName;
|
||||
}
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
@ -184,7 +160,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
|
||||
}
|
||||
os << values.size() << nl;
|
||||
|
||||
writeHeaderXYZ(os);
|
||||
os << "# x y z";
|
||||
writeHeader<Type>(os, fieldName);
|
||||
if (withFaceNormal)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user