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 |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016 OpenFOAM Foundation
|
Copyright (C) 2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2019 OpenCFD Ltd.
|
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -41,18 +41,23 @@ namespace functionObjects
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// Implementation
|
||||||
|
#include "componentsImpl.C"
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::components::calc()
|
bool Foam::functionObjects::components::calc()
|
||||||
{
|
{
|
||||||
bool processed = false;
|
return
|
||||||
|
(
|
||||||
processed = processed || calcComponents<vector>();
|
calcComponents<vector>()
|
||||||
processed = processed || calcComponents<sphericalTensor>();
|
|| calcComponents<sphericalTensor>()
|
||||||
processed = processed || calcComponents<symmTensor>();
|
|| calcComponents<symmTensor>()
|
||||||
processed = processed || calcComponents<tensor>();
|
|| calcComponents<tensor>()
|
||||||
|
);
|
||||||
return processed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016 OpenFOAM Foundation
|
Copyright (C) 2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -103,8 +103,8 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef functionObjects_components_H
|
#ifndef Foam_functionObjects_components_H
|
||||||
#define functionObjects_components_H
|
#define Foam_functionObjects_components_H
|
||||||
|
|
||||||
#include "fieldExpression.H"
|
#include "fieldExpression.H"
|
||||||
|
|
||||||
@ -134,14 +134,15 @@ class components
|
|||||||
//- Calculate the components of the field with the specified type
|
//- Calculate the components of the field with the specified type
|
||||||
//- and register the result
|
//- and register the result
|
||||||
template<class GeoFieldType>
|
template<class GeoFieldType>
|
||||||
bool calcFieldComponents();
|
bool calcComponents(const GeoFieldType& field);
|
||||||
|
|
||||||
//- Calculate the components of the field with the specified
|
//- Calculate the components of the field with the specified
|
||||||
//- element type and register the result
|
//- element type and register the result
|
||||||
template<class Type>
|
template<class Type>
|
||||||
bool calcComponents();
|
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();
|
virtual bool calc();
|
||||||
|
|
||||||
|
|
||||||
@ -189,12 +190,6 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#ifdef NoRepository
|
|
||||||
#include "componentsTemplates.C"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016 OpenFOAM Foundation
|
Copyright (C) 2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -32,19 +32,20 @@ License
|
|||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class GeoFieldType>
|
template<class GeoFieldType>
|
||||||
bool Foam::functionObjects::components::calcFieldComponents()
|
bool Foam::functionObjects::components::calcComponents
|
||||||
|
(
|
||||||
|
const GeoFieldType& field
|
||||||
|
)
|
||||||
{
|
{
|
||||||
typedef typename GeoFieldType::value_type Type;
|
typedef typename GeoFieldType::value_type Type;
|
||||||
|
|
||||||
const GeoFieldType& field = lookupObject<GeoFieldType>(fieldName_);
|
resultNames_.resize(pTraits<Type>::nComponents);
|
||||||
|
|
||||||
resultNames_.setSize(Type::nComponents);
|
|
||||||
|
|
||||||
bool stored = true;
|
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_;
|
resultNames_[i] = resultName_;
|
||||||
|
|
||||||
stored = stored && store(resultName_, field.component(i));
|
stored = stored && store(resultName_, field.component(i));
|
||||||
@ -57,16 +58,16 @@ bool Foam::functionObjects::components::calcFieldComponents()
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
bool Foam::functionObjects::components::calcComponents()
|
bool Foam::functionObjects::components::calcComponents()
|
||||||
{
|
{
|
||||||
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
const auto* vfield = cfindObject<VolumeField<Type>>(fieldName_);
|
||||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
|
if (vfield)
|
||||||
|
|
||||||
if (foundObject<VolFieldType>(fieldName_, false))
|
|
||||||
{
|
{
|
||||||
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;
|
return false;
|
||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -158,7 +158,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write()
|
|||||||
// Header
|
// Header
|
||||||
{
|
{
|
||||||
os << "# geometry NO_DATA " << faces.size() << nl;
|
os << "# geometry NO_DATA " << faces.size() << nl;
|
||||||
writeHeaderXYZ(os);
|
os << "# x y z";
|
||||||
if (withFaceNormal)
|
if (withFaceNormal)
|
||||||
{
|
{
|
||||||
writeHeaderArea(os);
|
writeHeaderArea(os);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2014 OpenFOAM Foundation
|
Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -44,62 +44,38 @@ namespace Foam
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
static inline void writeData(Ostream& os, const Type& val)
|
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
|
// Write area header
|
||||||
static inline void writeHeaderArea(Ostream& os)
|
static inline void writeHeaderArea(Ostream& os)
|
||||||
{
|
{
|
||||||
os << " area_x area_y area_z";
|
os << " area_x area_y area_z";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write field name, use named components for VectorSpace
|
||||||
template<class Type>
|
template<class Type>
|
||||||
static inline void writeHeader(Ostream& os, const word& fieldName)
|
static inline void writeHeader(Ostream& os, const word& fieldName)
|
||||||
{
|
|
||||||
os << " " << fieldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Type>
|
|
||||||
void writeHeaderComponents(Ostream& os, const word& fieldName)
|
|
||||||
{
|
{
|
||||||
os << ' ';
|
os << ' ';
|
||||||
for (direction i=0; i < pTraits<Type>::nComponents; ++i)
|
|
||||||
|
const auto nCmpts(pTraits<Type>::nComponents);
|
||||||
|
|
||||||
|
if (pTraits<Type>::rank || nCmpts > 1)
|
||||||
{
|
{
|
||||||
os << ' ' << fieldName << '_' << Type::componentNames[i];
|
for (direction d = 0; d < nCmpts; ++d)
|
||||||
|
{
|
||||||
|
os << ' ' << fieldName
|
||||||
|
<< '_' << pTraits<Type>::componentNames[d];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << ' ' << fieldName;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void writeHeader<vector>(Ostream& os, const word& fieldName)
|
|
||||||
{
|
|
||||||
writeHeaderComponents<vector>(os, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void writeHeader<sphericalTensor>(Ostream& os, const word& fieldName)
|
|
||||||
{
|
|
||||||
writeHeaderComponents<sphericalTensor>(os, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void writeHeader<symmTensor>(Ostream& os, const word& fieldName)
|
|
||||||
{
|
|
||||||
writeHeaderComponents<symmTensor>(os, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
void writeHeader<tensor>(Ostream& os, const word& fieldName)
|
|
||||||
{
|
|
||||||
writeHeaderComponents<tensor>(os, fieldName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
@ -184,13 +160,13 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
|
|||||||
}
|
}
|
||||||
os << values.size() << nl;
|
os << values.size() << nl;
|
||||||
|
|
||||||
writeHeaderXYZ(os);
|
os << "# x y z";
|
||||||
writeHeader<Type>(os, fieldName);
|
writeHeader<Type>(os, fieldName);
|
||||||
if (withFaceNormal)
|
if (withFaceNormal)
|
||||||
{
|
{
|
||||||
writeHeaderArea(os);
|
writeHeaderArea(os);
|
||||||
}
|
}
|
||||||
os << nl;
|
os << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user