Skip to content

Commit

Permalink
fix namespace and toField docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
greole committed Oct 4, 2024
1 parent 6ee8e1f commit 658de08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions include/NeoFOAM/DSL/coeff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: 2023 NeoFOAM authors
#pragma once

namespace NeoFOAM::dsl
namespace NeoFOAM::DSL
{

/**
Expand Down Expand Up @@ -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<scalar>& 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)
Expand Down
2 changes: 1 addition & 1 deletion test/dsl/coeff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "NeoFOAM/DSL/coeff.hpp"

using Field = NeoFOAM::Field<NeoFOAM::scalar>;
using Coeff = NeoFOAM::dsl::Coeff;
using Coeff = NeoFOAM::DSL::Coeff;


TEST_CASE("Coeff")
Expand Down

0 comments on commit 658de08

Please sign in to comment.