NeoN
A framework for CFD software
Loading...
Searching...
No Matches
fixedValue.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <Kokkos_Core.hpp>
8
13
15{
16
17namespace detail
18{
19// TODO move to source
20// Without this function the compiler warns that calling a __host__ function
21// from a __device__ function is not allowed
22template<typename ValueType>
24 Field<ValueType>& domainVector, std::pair<size_t, size_t> range, ValueType fixedValue
25)
26{
27 auto [refGradient, value, valueFraction, refValue] = views(
28 domainVector.boundaryData().refGrad(),
29 domainVector.boundaryData().value(),
30 domainVector.boundaryData().valueFraction(),
31 domainVector.boundaryData().refValue()
32 );
33
35 domainVector.exec(),
36 range,
37 KOKKOS_LAMBDA(const localIdx i) {
38 refValue[i] = fixedValue;
39 value[i] = fixedValue;
40 valueFraction[i] = 1.0; // only used refValue
41 refGradient[i] = fixedValue; // not used
42 }
43 );
44}
45
46}
47
48template<typename ValueType>
49class FixedValue : public VolumeBoundaryFactory<ValueType>::template Register<FixedValue<ValueType>>
50{
52
53public:
54
55 FixedValue(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
56 : Base(mesh, dict, patchID, {.assignable = false}),
57 fixedValue_(dict.get<ValueType>("fixedValue"))
58 {}
59
60 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) final
61 {
62 detail::setFixedValue(domainVector, this->range(), fixedValue_);
63 }
64
65 static std::string name() { return "fixedValue"; }
66
67 static std::string doc() { return "Set a fixed value on the boundary"; }
68
69 static std::string schema() { return "none"; }
70
71 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
72 {
73 return std::make_unique<FixedValue>(*this);
74 }
75
76private:
77
78 ValueType fixedValue_;
79};
80
81}
const Vector< T > & refGrad() const
Get the view storing the Neumann boundary values.
const Vector< T > & refValue() const
Get the view storing the Dirichlet boundary values.
const Vector< T > & value() const
Get the view storing the computed values from the boundary condition.
const Vector< scalar > & valueFraction() const
Get the view storing the fraction of the boundary value.
A class representing a dictionary that stores key-value pairs.
Represents the domain fields for a computational domain.
Definition field.hpp:36
const BoundaryData< ValueType > & boundaryData() const
Definition field.hpp:98
const Executor & exec() const
Definition field.hpp:103
Represents an unstructured mesh in NeoN.
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)
A template class for registering derived classes with a base class.
void setFixedValue(Field< ValueType > &domainVector, std::pair< size_t, size_t > range, ValueType fixedValue)
void parallelFor(const Executor &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name="parallelFor")
int32_t localIdx
Definition label.hpp:32
auto views(Types &... args)
Unpacks all views of the passed classes.
Definition view.hpp:110