NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
coeff.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 NeoFOAM authors
3#pragma once
4
7
8namespace NeoFOAM::dsl
9{
10
21class Coeff
22{
23
24public:
25
27
28 Coeff(scalar value);
29
30 Coeff(scalar coeff, const Field<scalar>& field);
31
32 Coeff(const Field<scalar>& field);
33
34 KOKKOS_INLINE_FUNCTION
35 scalar operator[](const size_t i) const { return (hasSpan_) ? span_[i] * coeff_ : coeff_; }
36
37 bool hasSpan();
38
39 std::span<const scalar> span();
40
42
43
44 Coeff& operator*=(const Coeff& rhs);
45
46
47private:
48
49 scalar coeff_;
50
51 std::span<const scalar> span_;
52
53 bool hasSpan_;
54};
55
56
57[[nodiscard]] inline Coeff operator*(const Coeff& lhs, const Coeff& rhs)
58{
59 Coeff result = lhs;
60 result *= rhs;
61 return result;
62}
63
64namespace detail
65{
66/* @brief function to force evaluation to a field, the field will be resized to hold either a
67 * single value or the full field
68 *
69 * @param field to store the result
70 */
71void toField(Coeff& coeff, Field<scalar>& rhs);
72
73} // namespace detail
74
75} // namespace NeoFOAM::dsl
A class to contain the data and executors for a field and define some basic operations.
Definition field.hpp:49
A class that represents a coefficient for the NeoFOAM dsl.
Definition coeff.hpp:22
Coeff(scalar value)
KOKKOS_INLINE_FUNCTION scalar operator[](const size_t i) const
Definition coeff.hpp:35
Coeff(const Field< scalar > &field)
Coeff & operator*=(scalar rhs)
Coeff(scalar coeff, const Field< scalar > &field)
Coeff & operator*=(const Coeff &rhs)
std::span< const scalar > span()
Coeff operator*(const Coeff &lhs, const Coeff &rhs)
Definition coeff.hpp:57
float scalar
Definition scalar.hpp:11