Skip to content

Commit

Permalink
rename scalingFields to scaling handler, update docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
greole committed Sep 30, 2024
1 parent aa05d2d commit 540f634
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,39 +17,45 @@ namespace NeoFOAM
* @tparam ValueType The type of the values stored in the class.
*/
template<typename ValueType>
struct ScalingField
class scalingHandler
{
ScalingField() = default;
ScalingField(std::span<ValueType> values) : values(values), value(1.0), useSpan(true) {}

ScalingField(std::span<ValueType> values, NeoFOAM::scalar value)
public:

scalingHandler() = default;

scalingHandler(std::span<ValueType> values) : values(values), value(1.0), useSpan(true) {}

scalingHandler(std::span<ValueType> values, scalar value)
: values(values), value(value), useSpan(true)
{}

ScalingField(NeoFOAM::scalar value) : values(), value(value), useSpan(false) {}

std::span<ValueType> 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<ValueType> 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<ValueType> values;

const scalar value;

bool useSpan;
};

} // namespace NeoFOAM

0 comments on commit 540f634

Please sign in to comment.