Skip to content
Snippets Groups Projects
Commit fb4fe063 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: simplify component handling

- raw writer, components functionObject
parent 7db2a294
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
template<>
void writeHeader<sphericalTensor>(Ostream& os, const word& fieldName)
{
writeHeaderComponents<sphericalTensor>(os, fieldName);
}
const auto nCmpts(pTraits<Type>::nComponents);
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);
if (pTraits<Type>::rank || nCmpts > 1)
{
for (direction d = 0; d < nCmpts; ++d)
{
os << ' ' << fieldName
<< '_' << pTraits<Type>::componentNames[d];
}
}
else
{
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<Type>(os, fieldName);
if (withFaceNormal)
{
writeHeaderArea(os);
}
os << nl;
os << nl;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment