mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: upgrade to use some C++17 constructs
- 'if constexpr (...)' * instead of std::enable_if * terminate template recursion * compile-time elimination of code - use C++14 '_t', '_v' versions, eg, std::is_integral_v<T> instead of std::is_integral<T>::value - std::begin, std::end, std::void_t instead of prev stdFoam versions - provide is_contiguous_v<..> as short form of is_contiguous<..>::value with the additional benefit of removing any cv qualifiers. ENH: include is_rotational_vectorspace trait - tests for vector-space and nComponents > 1 (ie, not sphericalTensor) ENH: improve robustness of pTraits_.. tests by removing cv qualifiers
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -187,8 +187,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef DMDModels_STDMD_H
|
||||
#define DMDModels_STDMD_H
|
||||
#ifndef Foam_DMDModels_STDMD_H
|
||||
#define Foam_DMDModels_STDMD_H
|
||||
|
||||
#include "DMDModel.H"
|
||||
#include "SquareMatrix.H"
|
||||
@ -400,28 +400,9 @@ class STDMD
|
||||
template<class GeoFieldType>
|
||||
bool calcModes();
|
||||
|
||||
//- Compute a mode for a given scalar-based input field
|
||||
//- Compute a mode for a given scalar-based or other input field
|
||||
template<class GeoFieldType>
|
||||
typename std::enable_if
|
||||
<
|
||||
std::is_same<scalar, typename GeoFieldType::value_type>::value,
|
||||
void
|
||||
>::type calcMode
|
||||
(
|
||||
GeoFieldType& modeRe,
|
||||
GeoFieldType& modeIm,
|
||||
const RMatrix& primitiveMode,
|
||||
const label magi,
|
||||
const label rowi = 0
|
||||
);
|
||||
|
||||
//- Compute a mode for a given non-scalar-based input field
|
||||
template<class GeoFieldType>
|
||||
typename std::enable_if
|
||||
<
|
||||
!std::is_same<scalar, typename GeoFieldType::value_type>::value,
|
||||
void
|
||||
>::type calcMode
|
||||
void calcMode
|
||||
(
|
||||
GeoFieldType& modeRe,
|
||||
GeoFieldType& modeIm,
|
||||
|
||||
@ -184,41 +184,7 @@ bool Foam::DMDModels::STDMD::calcModes()
|
||||
|
||||
|
||||
template<class GeoFieldType>
|
||||
typename std::enable_if
|
||||
<
|
||||
std::is_same<Foam::scalar, typename GeoFieldType::value_type>::value,
|
||||
void
|
||||
>::type Foam::DMDModels::STDMD::calcMode
|
||||
(
|
||||
GeoFieldType& modeRe,
|
||||
GeoFieldType& modeIm,
|
||||
const RMatrix& primitiveMode,
|
||||
const label magi,
|
||||
const label rowi
|
||||
)
|
||||
{
|
||||
const label szfld = modeRe.size();
|
||||
|
||||
for (label i = rowi; i < szfld + rowi; ++i)
|
||||
{
|
||||
complex mode(Zero);
|
||||
for (label j = 0; j < evecs_.m(); ++j)
|
||||
{
|
||||
mode += primitiveMode(i, j)*evecs_(j, magi);
|
||||
}
|
||||
const label k = (i-rowi)%szfld;
|
||||
modeRe[k] = mode.real();
|
||||
modeIm[k] = mode.imag();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class GeoFieldType>
|
||||
typename std::enable_if
|
||||
<
|
||||
!std::is_same<Foam::scalar, typename GeoFieldType::value_type>::value,
|
||||
void
|
||||
>::type Foam::DMDModels::STDMD::calcMode
|
||||
void Foam::DMDModels::STDMD::calcMode
|
||||
(
|
||||
GeoFieldType& modeRe,
|
||||
GeoFieldType& modeIm,
|
||||
@ -238,10 +204,23 @@ typename std::enable_if
|
||||
{
|
||||
mode += primitiveMode(i, j)*evecs_(j, magi);
|
||||
}
|
||||
|
||||
const label k = (i-rowi)%szfld;
|
||||
const label m = (i-rowi)/szfld;
|
||||
modeRe[k][m] = mode.real();
|
||||
modeIm[k][m] = mode.imag();
|
||||
|
||||
if constexpr
|
||||
(
|
||||
std::is_same_v<scalar, typename GeoFieldType::value_type>
|
||||
)
|
||||
{
|
||||
modeRe[k] = mode.real();
|
||||
modeIm[k] = mode.imag();
|
||||
}
|
||||
else
|
||||
{
|
||||
const label m = (i-rowi)/szfld;
|
||||
modeRe[k][m] = mode.real();
|
||||
modeIm[k][m] = mode.imag();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -88,8 +88,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_multiply_H
|
||||
#define functionObjects_multiply_H
|
||||
#ifndef Foam_functionObjects_multiply_H
|
||||
#define Foam_functionObjects_multiply_H
|
||||
|
||||
#include "fieldsExpression.H"
|
||||
|
||||
@ -127,23 +127,7 @@ class multiply
|
||||
bool multiplyResult(const word& fieldName, bool& processed);
|
||||
|
||||
template<class Type1, class Type2>
|
||||
typename std::enable_if
|
||||
<
|
||||
is_valid_op<Type1, Type2>::value, bool
|
||||
>::type
|
||||
multiplyFieldType
|
||||
(
|
||||
GeometricField<Type1, fvPatchField, volMesh>& result,
|
||||
const word& fieldName,
|
||||
bool& processed
|
||||
);
|
||||
|
||||
template<class Type1, class Type2>
|
||||
typename std::enable_if
|
||||
<
|
||||
!is_valid_op<Type1, Type2>::value, bool
|
||||
>::type
|
||||
multiplyFieldType
|
||||
bool multiplyFieldType
|
||||
(
|
||||
GeometricField<Type1, fvPatchField, volMesh>& result,
|
||||
const word& fieldName,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -88,11 +88,7 @@ bool Foam::functionObjects::multiply::multiplyResult
|
||||
|
||||
|
||||
template<class Type1, class Type2>
|
||||
typename std::enable_if
|
||||
<
|
||||
Foam::functionObjects::multiply::is_valid_op<Type1, Type2>::value, bool
|
||||
>::type
|
||||
Foam::functionObjects::multiply::multiplyFieldType
|
||||
bool Foam::functionObjects::multiply::multiplyFieldType
|
||||
(
|
||||
GeometricField<Type1, fvPatchField, volMesh>& result,
|
||||
const word& fieldName,
|
||||
@ -107,46 +103,30 @@ Foam::functionObjects::multiply::multiplyFieldType
|
||||
|
||||
if (fieldPtr)
|
||||
{
|
||||
Log << " Performing " << result.name() << " * " << fieldPtr->name()
|
||||
<< endl;
|
||||
if constexpr
|
||||
(
|
||||
Foam::functionObjects::multiply::is_valid_op<Type1, Type2>::value
|
||||
)
|
||||
{
|
||||
Log << " Performing "
|
||||
<< result.name() << " * " << fieldPtr->name()
|
||||
<< endl;
|
||||
|
||||
auto newResult(result*(*fieldPtr));
|
||||
result.checkOut();
|
||||
auto newResult(result*(*fieldPtr));
|
||||
result.checkOut();
|
||||
|
||||
store(resultName_, newResult);
|
||||
store(resultName_, newResult);
|
||||
|
||||
processed = true;
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
|
||||
template<class Type1, class Type2>
|
||||
typename std::enable_if
|
||||
<
|
||||
!Foam::functionObjects::multiply::is_valid_op<Type1, Type2>::value, bool
|
||||
>::type
|
||||
Foam::functionObjects::multiply::multiplyFieldType
|
||||
(
|
||||
GeometricField<Type1, fvPatchField, volMesh>& result,
|
||||
const word& fieldName,
|
||||
bool& processed
|
||||
)
|
||||
{
|
||||
if (processed) return processed;
|
||||
|
||||
typedef GeometricField<Type2, fvPatchField, volMesh> volFieldType;
|
||||
|
||||
auto* fieldPtr = mesh_.cfindObject<volFieldType>(fieldName);
|
||||
|
||||
if (fieldPtr)
|
||||
{
|
||||
Info<< " Unsupported operation for "
|
||||
<< result.name() << '(' << pTraits<Type1>::typeName << ')'
|
||||
<< " * "
|
||||
<< fieldPtr->name() << '(' << pTraits<Type2>::typeName << ')'
|
||||
<< endl;
|
||||
processed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Unsupported operation for "
|
||||
<< result.name() << '(' << pTraits<Type1>::typeName << ')'
|
||||
<< " * "
|
||||
<< fieldPtr->name() << '(' << pTraits<Type2>::typeName << ')'
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
return processed;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2024 OpenCFD Ltd.
|
||||
Copyright (C) 2024-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -131,7 +131,7 @@ bool Foam::functionObjects::ensightCloudWriteObject::writeCloud
|
||||
|
||||
|
||||
// Copy positions (for simplicity and for filtering).
|
||||
// Store as floatVector, since that is what Ensight will write anyhow
|
||||
// Store as floatVector, since Ensight will write float components anyhow
|
||||
|
||||
DynamicList<floatVector> positions;
|
||||
positions.reserve(UPstream::master() ? procAddr_.maxSize() : nParcels);
|
||||
@ -145,46 +145,42 @@ bool Foam::functionObjects::ensightCloudWriteObject::writeCloud
|
||||
|
||||
if (applyFilter_)
|
||||
{
|
||||
if (std::is_same<float, vector::cmptType>::value)
|
||||
for (const label idx : parcelAddr_)
|
||||
{
|
||||
for (const label idx : parcelAddr_)
|
||||
{
|
||||
*iter = points[idx];
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const label idx : parcelAddr_)
|
||||
{
|
||||
const auto& pos = points[idx];
|
||||
const auto& pos = points[idx];
|
||||
|
||||
if constexpr (std::is_same_v<float, vector::cmptType>)
|
||||
{
|
||||
// Direct copy
|
||||
*iter = pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy with narrowing
|
||||
(*iter).x() = narrowFloat(pos.x());
|
||||
(*iter).y() = narrowFloat(pos.y());
|
||||
(*iter).z() = narrowFloat(pos.z());
|
||||
++iter;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (std::is_same<float, vector::cmptType>::value)
|
||||
for (const auto& pos : points)
|
||||
{
|
||||
for (const auto& pos : points)
|
||||
if constexpr (std::is_same_v<float, vector::cmptType>)
|
||||
{
|
||||
// Direct copy
|
||||
*iter = pos;
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const auto& pos : points)
|
||||
else
|
||||
{
|
||||
// Copy with narrowing
|
||||
(*iter).x() = narrowFloat(pos.x());
|
||||
(*iter).y() = narrowFloat(pos.y());
|
||||
(*iter).z() = narrowFloat(pos.z());
|
||||
++iter;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2024 OpenCFD Ltd.
|
||||
Copyright (C) 2024-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -37,11 +37,13 @@ Foam::wordList Foam::functionObjects::ensightCloudWriteObject::writeFields
|
||||
const objectRegistry& obrTmp
|
||||
)
|
||||
{
|
||||
using cmptType = typename pTraits<Type>::cmptType;
|
||||
|
||||
static_assert
|
||||
(
|
||||
(
|
||||
std::is_same<label, typename pTraits<Type>::cmptType>::value
|
||||
|| std::is_floating_point<typename pTraits<Type>::cmptType>::value
|
||||
std::is_same_v<label, cmptType>
|
||||
|| std::is_floating_point_v<cmptType>
|
||||
),
|
||||
"Label and Floating-point vector space only"
|
||||
);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2024 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2025 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,11 +39,13 @@ Foam::wordList Foam::functionObjects::vtkCloud::writeFields
|
||||
{
|
||||
const direction nCmpt(pTraits<Type>::nComponents);
|
||||
|
||||
typedef typename pTraits<Type>::cmptType cmptType;
|
||||
|
||||
static_assert
|
||||
(
|
||||
(
|
||||
std::is_same<label, typename pTraits<Type>::cmptType>::value
|
||||
|| std::is_floating_point<typename pTraits<Type>::cmptType>::value
|
||||
std::is_same_v<label, cmptType>
|
||||
|| std::is_floating_point_v<cmptType>
|
||||
),
|
||||
"Label and Floating-point vector space only"
|
||||
);
|
||||
@ -72,7 +74,7 @@ Foam::wordList Foam::functionObjects::vtkCloud::writeFields
|
||||
|
||||
if (UPstream::master())
|
||||
{
|
||||
if (std::is_same<label, typename pTraits<Type>::cmptType>::value)
|
||||
if constexpr (std::is_same_v<label, cmptType>)
|
||||
{
|
||||
const uint64_t payLoad =
|
||||
vtk::sizeofData<label, nCmpt>(nTotParcels);
|
||||
|
||||
Reference in New Issue
Block a user