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 "setFixedValueVolume"
44 );
45}
46
47}
48
49template<typename ValueType>
50class FixedValue : public VolumeBoundaryFactory<ValueType>::template Register<FixedValue<ValueType>>
51{
53
54public:
55
56 FixedValue(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
57 : Base(mesh, dict, patchID, {.assignable = false}),
58 fixedValue_(dict.get<ValueType>("fixedValue"))
59 {}
60
61 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) final
62 {
63 detail::setFixedValue(domainVector, this->range(), fixedValue_);
64 }
65
66 static std::string name() { return "fixedValue"; }
67
68 static std::string doc() { return "Set a fixed value on the boundary"; }
69
70 static std::string schema() { return "none"; }
71
72 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
73 {
74 return std::make_unique<FixedValue>(*this);
75 }
76
77private:
78
79 ValueType fixedValue_;
80};
81
82}
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)
int32_t localIdx
Definition label.hpp:32
void parallelFor(const ExecutorType &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name)
auto views(Types &... args)
Unpacks all views of the passed classes.
Definition view.hpp:110