NeoN
A framework for CFD software
Loading...
Searching...
No Matches
fixedValue.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2026 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 NEON_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 "setFixedValueVolume"
44 );
45}
46
47}
48
49template<typename ValueType>
50class FixedValue : public VolumeBoundaryFactory<ValueType>::template Register<FixedValue<ValueType>>
51{
53
54public:
55
56 using Base::correctBoundaryCondition;
57
58 FixedValue(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
59 : Base(mesh, dict, patchID, {.assignable = false, .fixesValue = true}),
60 fixedValue_(dict.get<ValueType>("fixedValue"))
61 {}
62
63 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) final
64 {
65 detail::setFixedValue(domainVector, this->range(), fixedValue_);
66 }
67
68 static std::string name() { return "fixedValue"; }
69
70 std::string getName() const override { return name(); }
71
72 static std::string doc() { return "Set a fixed value on the boundary"; }
73
74 static std::string schema() { return "none"; }
75
76 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
77 {
78 return std::make_unique<FixedValue>(*this);
79 }
80
81private:
82
83 ValueType fixedValue_;
84};
85
86}
A class representing a dictionary that stores key-value pairs.
Represents the domain fields for a computational domain.
Definition field.hpp:34
const BoundaryData< ValueType > & boundaryData() const
Definition field.hpp:96
const Executor & exec() const
Definition field.hpp:101
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)
int32_t localIdx
Definition label.hpp:50
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.
Definition view.hpp:107
#define NEON_LAMBDA