/*---------------------------------------------------------------------------*\ ========= | \\ / 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 { namespace expression { // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // //- A DimensionedField is expressionable template class PrimitiveField> struct Expressionable> : public std::integral_constant {}; //- Access to the dimensions of a DimensionedField is not expressionable. It // returns a non-expressionable object (i.e., a dimensionSet). template class PrimitiveField> struct Expressionable < DimensionedField, Arguments > : public std::integral_constant {}; //- Define access to the base primitive field of a DimensionedField. Note // that expression::Value is specified as well as expression::Base. This is // not important here, but it is important when accessing dimensioned // constants in the same layer. The presence of expression::Value will ensure // that their dimensions are removed and only their value is retained in the // accessed expression. template class PrimitiveField> struct Operate < DimensionedField, Arguments > { using type = const PrimitiveField&; static type access ( const DimensionedField& f, const Value&, const Base& ) { return f.primitiveField(); } }; //- Access the dimensions of a DimensionedField template class PrimitiveField> struct Operate < DimensionedField, Arguments > { using type = dimensionsOrVariableExponent; static type access ( const DimensionedField& f, const dimensionSet& ) { return type(f.dimensions()); } }; //- Define the result types for a DimensionedField 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, Arguments >::type >; template using elementType = dimensioned>; template using type = DimensionedField, GeoMesh, Field>; }; //- Implement a reduction of DimensionedField which reduces the primitive // field (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 < DimensionedField >::template elementType value ( const Expression& e, const bool globalReduce, const label comm ) { return typename Result < DimensionedField >::template elementType ( Op::name(name(e)), access(e, NullObjectRef()), Reduce>::template value ( access(e, Value(), Base()), globalReduce, comm ) ); } template static typename Result < DimensionedField >::template elementType average ( const Expression& e, const bool globalReduce, const label comm ) { return typename Result < DimensionedField >::template elementType ( word("average(", name(e), ')'), access(e, NullObjectRef()), Reduce>::average ( access(e, Value(), Base()), globalReduce, comm ) ); } template static typename Result < DimensionedField >::template elementType weightedAverage ( const Expression& e, const WeightExpression& we, const bool globalReduce, const label comm ) { return typename Result < DimensionedField >::template elementType ( word("weightedAverage(", name(e), ',', name(we), ')'), access(e, NullObjectRef()), Reduce>::weightedAverage ( access(e, Value(), Base()), access(we, Value(), Base()), globalReduce, comm ) ); } }; //- The name of a DimensionedField is stored in its IOobject, so use this // rather than the default string representation of the type and pointer template class PrimitiveField> struct Name < DimensionedField, EnableIfExpressionable < DimensionedField > > { static word& append ( word& name, const DimensionedField& f ) { return name.append(f.name()); } static const word& value ( const DimensionedField& f ) { return f.name(); } }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace expression } // End namespace Foam // ************************************************************************* //