9#include <Kokkos_Core.hpp>
26template<
typename ValueType>
28 Field<ValueType>& domainVector, std::pair<sizeType, sizeType> range, ValueType fixedValue
31 auto [refGradient, value, valueFraction, refValue] =
views(
42 refValue[i] = fixedValue;
43 value[i] = fixedValue;
44 valueFraction[i] = 1.0;
45 refGradient[i] = fixedValue;
53template<
typename ValueType>
56 std::pair<sizeType, sizeType> range,
60 auto [refGradient, value, valueFraction, refValue] =
views(
66 auto fixedValuesView = fixedValues.
view();
67 const auto start =
static_cast<localIdx>(range.first);
73 auto patchValue = fixedValuesView[i - start];
74 refValue[i] = patchValue;
75 value[i] = patchValue;
76 valueFraction[i] = 1.0;
77 refGradient[i] = patchValue;
79 "setFixedValuesVolume"
85template<
typename ValueType>
92 using Base::correctBoundaryCondition;
95 : Base(mesh, dict,
patchID, {.assignable =
false, .fixesValue =
true}),
97 dict.contains(
"fixedValue") ? dict.get<ValueType>(
"fixedValue") : ValueType {}
101 dict.contains(
"fixedValues") ? dict.get<std::vector<ValueType>>(
"fixedValues")
102 : std::vector<ValueType> {}
105 const bool hasUniform = dict.contains(
"fixedValue");
106 const bool hasPerFace = dict.contains(
"fixedValues");
107 if (!hasUniform && !hasPerFace)
110 "fixedValue boundary condition on patch " + std::to_string(
patchID)
111 +
" requires either a uniform 'fixedValue' or a per-face 'fixedValues' entry"
117 if (hasPerFace &&
toLocalIdx(fixedValues_.size()) != this->patchSize())
120 "'fixedValues' holds " + std::to_string(fixedValues_.size()) +
" values but patch "
121 + std::to_string(
patchID) +
" has " + std::to_string(this->patchSize()) +
" faces"
128 if (fixedValues_.size() > 0)
138 static std::string
name() {
return "fixedValue"; }
142 static std::string
doc() {
return "Set a fixed value on the boundary"; }
144 static std::string
schema() {
return "none"; }
146 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>>
clone() const final
148 return std::make_unique<FixedValue>(*
this);
153 ValueType fixedValue_;
A class representing a dictionary that stores key-value pairs.
Represents the domain fields for a computational domain.
const BoundaryData< ValueType > & boundaryData() const
const Executor & exec() const
Represents an unstructured mesh in NeoN.
An executor-aware contiguous container for numerical data with vector-style arithmetic semantics.
View< ValueType > view() &&=delete
Prevents creating a View from a temporary Vector.
std::pair< localIdx, localIdx > range() const
VolumeBoundaryFactory(const UnstructuredMesh &mesh, const Dictionary &dict, localIdx patchID, BoundaryAttributes attributes)
virtual std::unique_ptr< VolumeBoundaryFactory< ValueType > > clone() const final
virtual void correctBoundaryCondition(Field< ValueType > &domainVector) final
FixedValue(const UnstructuredMesh &mesh, const Dictionary &dict, localIdx patchID)
static std::string schema()
std::string getName() const override
static std::string name()
A template class for registering derived classes with a base class.
#define NF_THROW(message)
Macro for throwing a NeoNException with the specified error message.
void setFixedValues(Field< ValueType > &domainVector, std::pair< sizeType, sizeType > range, const Vector< ValueType > &fixedValues)
void setFixedValue(Field< ValueType > &domainVector, std::pair< sizeType, sizeType > range, ValueType fixedValue)
localIdx toLocalIdx(sizeType value)
void parallelFor(const ExecutorType &, std::pair< localIdx, localIdx > range, const Kernel &kernel, std::string name)
auto views(Types &... args)
Unpacks all views of the passed classes.