NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
fixedValue.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 NeoN authors
3
4#pragma once
5
6#include <Kokkos_Core.hpp>
7
12
14{
15
16namespace detail
17{
18// TODO move to source
19// Without this function the compiler warns that calling a __host__ function
20// from a __device__ function is not allowed
21template<typename ValueType>
23 Field<ValueType>& domainVector, std::pair<size_t, size_t> range, ValueType fixedValue
24)
25{
26 auto [refGradient, value, valueFraction, refValue] = views(
27 domainVector.boundaryData().refGrad(),
28 domainVector.boundaryData().value(),
29 domainVector.boundaryData().valueFraction(),
30 domainVector.boundaryData().refValue()
31 );
32
34 domainVector.exec(),
35 range,
36 KOKKOS_LAMBDA(const localIdx i) {
37 refValue[i] = fixedValue;
38 value[i] = fixedValue;
39 valueFraction[i] = 1.0; // only used refValue
40 refGradient[i] = fixedValue; // not used
41 }
42 );
43}
44
45}
46
47template<typename ValueType>
48class FixedValue : public VolumeBoundaryFactory<ValueType>::template Register<FixedValue<ValueType>>
49{
51
52public:
53
54 FixedValue(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
55 : Base(mesh, dict, patchID), fixedValue_(dict.get<ValueType>("fixedValue"))
56 {}
57
58 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) final
59 {
60 detail::setFixedValue(domainVector, this->range(), fixedValue_);
61 }
62
63 static std::string name() { return "fixedValue"; }
64
65 static std::string doc() { return "Set a fixed value on the boundary"; }
66
67 static std::string schema() { return "none"; }
68
69 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
70 {
71 return std::make_unique<FixedValue>(*this);
72 }
73
74private:
75
76 ValueType fixedValue_;
77};
78
79}
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: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)
void parallelFor(const Executor &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name="parallelFor")
int32_t localIdx
Definition label.hpp:30
auto views(Types &... args)
Unpacks all views of the passed classes.
Definition view.hpp:101