diff --git a/include/NeoFOAM/DSL/coeff.hpp b/include/NeoFOAM/DSL/coeff.hpp index d1acdfe15..ec2d20d60 100644 --- a/include/NeoFOAM/DSL/coeff.hpp +++ b/include/NeoFOAM/DSL/coeff.hpp @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: 2023 NeoFOAM authors #pragma once -namespace NeoFOAM::dsl +namespace NeoFOAM::DSL { /** @@ -38,17 +38,30 @@ class Coeff coeff_ *= rhs; return *this; } - /* function to force evaluation to a newly created field */ + + /* @brief function to force evaluation to a field, the field will be resized to hold either a + * single value or the full field + * + * @param field to store the result + */ void toField(Field& rhs) { - rhs.resize(span_.size()); - fill(rhs, 1.0); - auto rhsSpan = rhs.span(); - // otherwise we are unable to capture values in the lambda - auto& coeff = *this; - parallelFor( - rhs.exec(), rhs.range(), KOKKOS_LAMBDA(const size_t i) { rhsSpan[i] *= coeff[i]; } - ); + if (hasSpan_) + { + rhs.resize(span_.size()); + fill(rhs, 1.0); + auto rhsSpan = rhs.span(); + // otherwise we are unable to capture values in the lambda + auto& coeff = *this; + parallelFor( + rhs.exec(), rhs.range(), KOKKOS_LAMBDA(const size_t i) { rhsSpan[i] *= coeff[i]; } + ); + } + else + { + rhs.resize(1); + fill(rhs, coeff_); + } } Coeff& operator*=(const Coeff& rhs) diff --git a/test/dsl/coeff.cpp b/test/dsl/coeff.cpp index 64585b058..a3561f625 100644 --- a/test/dsl/coeff.cpp +++ b/test/dsl/coeff.cpp @@ -11,7 +11,7 @@ #include "NeoFOAM/DSL/coeff.hpp" using Field = NeoFOAM::Field; -using Coeff = NeoFOAM::dsl::Coeff; +using Coeff = NeoFOAM::DSL::Coeff; TEST_CASE("Coeff")