/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "expressions.H"
#include "expressionDimensionSet.H"
#include "expressionDimensionedType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
//- Type used to identify access to the underlying internal field
struct GeometricField_InternalField {};
//- Type used to identify access to the underlying boundary field
struct GeometricField_BoundaryField {};
namespace expression
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- A GeometricField is expressionable
template class PrimitiveField>
struct Expressionable>
:
public std::integral_constant
{};
//- Define access to the internal field of a GeometricField
template class PrimitiveField>
struct Operate
<
GeometricField,
Arguments
>
{
using type = const DimensionedField&;
static type access
(
const GeometricField& f,
const GeometricField_InternalField&
)
{
return f.internalField();
}
};
//- Define access to the boundary field of a GeometricField
template class PrimitiveField>
struct Operate
<
GeometricField,
Arguments
>
{
using type =
const
typename GeometricField::BoundaryField&;
static type access
(
const GeometricField& f,
const Value&,
const GeometricField_BoundaryField&
)
{
return f.boundaryField();
}
};
//- Define the result types for a GeometricField as the dimensioned
// equivalents of the primitive types
template class PrimitiveField>
struct Result>
{
template
using primitiveType =
typename Result
<
PrimitiveField
>::template elementType
<
typename Operate
<
std::decay_t
<
typename Operate
<
std::decay_t,
Arguments
>::type
>,
Arguments
>::type
>;
template
using elementType = dimensioned>;
template
using type = GeometricField, GeoMesh, Field>;
};
//- Implement a reduction of GeometricField which reduces both the primitive
// and boundary fields (locally and then globally) and then combines the
// result with the name and dimensions of the expression to return a
// dimensioned type
template class PrimitiveField>
struct Reduce>
{
// Global (parallel) reductions should be applied to the result by default
static const bool globalReduce = true;
template
static typename Result
<
GeometricField
>::template elementType value
(
const Expression& e,
const bool globalReduce,
const label comm
)
{
using BoundaryField =
typename GeometricField::
BoundaryField;
auto x =
Op::value
(
Reduce>::template value
(
access
(
access(e, GeometricField_InternalField()),
Value(),
Base()
),
globalReduce,
comm
),
Reduce::template value
(
access
(
e,
Value(),
GeometricField_BoundaryField()
),
globalReduce,
comm
)
);
return
typename Result
<
GeometricField
>::template elementType
(
Op::name(name(e)),
access
(
access(e, GeometricField_InternalField()),
NullObjectRef()
),
x
);
}
template
static typename Result
<
GeometricField
>::template elementType average
(
const Expression& e,
const bool globalReduce,
const label comm
)
{
return Reduce>::
average
(
access(e, GeometricField_InternalField()),
globalReduce,
comm
);
}
template
static typename Result
<
GeometricField
>::template elementType weightedAverage
(
const Expression& e,
const WeightExpression& we,
const bool globalReduce,
const label comm
)
{
return Reduce>::
weightedAverage
(
access(e, GeometricField_InternalField()),
access(we, GeometricField_InternalField()),
globalReduce,
comm
);
}
};
//- The name of a GeometricField is stored in its IOobject, so use this
// rather than the default string representation of the type and pointer
template class PrimitiveField>
struct Name
<
GeometricField,
EnableIfExpressionable
<
GeometricField
>
>
{
static word& append
(
word& name,
const GeometricField& f
)
{
return name.append(f.name());
}
static const word& value
(
const GeometricField& f
)
{
return f.name();
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace expression
} // End namespace Foam
// ************************************************************************* //