From 540f6349a3749c208ddd5a0eef6f78ddd92156c3 Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Mon, 30 Sep 2024 14:01:07 +0200 Subject: [PATCH] rename scalingFields to scaling handler, update docstring --- .../scalingHandler.hpp} | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) rename include/NeoFOAM/{fields/scalingField.hpp => DSL/scalingHandler.hpp} (62%) diff --git a/include/NeoFOAM/fields/scalingField.hpp b/include/NeoFOAM/DSL/scalingHandler.hpp similarity index 62% rename from include/NeoFOAM/fields/scalingField.hpp rename to include/NeoFOAM/DSL/scalingHandler.hpp index eea2ad027..652d22f61 100644 --- a/include/NeoFOAM/fields/scalingField.hpp +++ b/include/NeoFOAM/DSL/scalingHandler.hpp @@ -6,7 +6,9 @@ namespace NeoFOAM { /** - * @brief A wrapper class that represents either a span of values or a single value. + * @class scalingHandler + * @brief A wrapper class that represents either a single or a span of values. Which is used to + * simplify the implementation f of scaling with single or multiple values for the DSL. * * This class is used to store either a span of values or a single value of type `ValueType`. * It provides an indexing operator `operator[]` that returns the value at the specified index @@ -15,39 +17,45 @@ namespace NeoFOAM * @tparam ValueType The type of the values stored in the class. */ template -struct ScalingField +class scalingHandler { - ScalingField() = default; - ScalingField(std::span values) : values(values), value(1.0), useSpan(true) {} - ScalingField(std::span values, NeoFOAM::scalar value) +public: + + scalingHandler() = default; + + scalingHandler(std::span values) : values(values), value(1.0), useSpan(true) {} + + scalingHandler(std::span values, scalar value) : values(values), value(value), useSpan(true) {} - ScalingField(NeoFOAM::scalar value) : values(), value(value), useSpan(false) {} - - std::span values; - NeoFOAM::scalar value; - bool useSpan; + scalingHandler(scalar value) : values(), value(value), useSpan(false) {} KOKKOS_INLINE_FUNCTION ValueType operator[](const size_t i) const { return useSpan ? values[i] * value : value; } - void operator*=(NeoFOAM::scalar scale) { value *= scale; } - - void operator=(NeoFOAM::scalar scale) { value = scale; } + void operator*=(scalar scale) { value *= scale; } void operator*=(Field scalingField) { auto scale = scalingField.span(); // otherwise we are unable to capture values in the lambda auto selfValue = values; - NeoFOAM::parallelFor( + parallelFor( scalingField.exec(), {0, scalingField.size()}, KOKKOS_LAMBDA(const size_t i) { selfValue[i] *= scale[i]; } ); } + +private: + + const std::span values; + + const scalar value; + + bool useSpan; }; } // namespace NeoFOAM