NeoN
A framework for CFD software
Loading...
Searching...
No Matches
fixedGradient.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
12
14{
15
16// TODO move to source file
17namespace detail
18{
19// Without this function the compiler warns that calling a __host__ function
20// from a __device__ function is not allowed
21// NOTE: patchID was removed since it was unused
22// I guess it was replaced by range
23template<typename ValueType>
25 Field<ValueType>& domainVector,
26 const UnstructuredMesh& mesh,
27 std::pair<localIdx, localIdx> range,
28 ValueType fixedGradient
29)
30{
31 const auto iVector = domainVector.internalVector().view();
32
33 auto [refGradient, value, valueFraction, refValue, boundaryFaceOwners, deltaCoeffs] = views(
34 domainVector.boundaryData().refGrad(),
35 domainVector.boundaryData().value(),
36 domainVector.boundaryData().valueFraction(),
37 domainVector.boundaryData().refValue(),
38 mesh.boundaryMesh().faceOwners(),
40 );
41
43 domainVector.exec(),
44 range,
45 NEON_LAMBDA(const localIdx i) {
46 refGradient[i] = fixedGradient;
47 // operator / is not defined for all ValueTypes
48 value[i] = iVector[boundaryFaceOwners[i]] + fixedGradient * (1 / deltaCoeffs[i]);
49 valueFraction[i] = 0.0; // only use refGrad
50 refValue[i] = zero<ValueType>(); // not used
51 },
52 "setGradientValue"
53 );
54}
55}
56
57template<typename ValueType>
59 public VolumeBoundaryFactory<ValueType>::template Register<FixedGradient<ValueType>>
60{
62
63public:
64
65 using Base::correctBoundaryCondition;
66
68
69 FixedGradient(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
70 : Base(mesh, dict, patchID, {.assignable = true, .fixesValue = false}), mesh_(mesh),
71 fixedGradient_(dict.get<ValueType>("fixedGradient"))
72 {}
73
74 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) final
75 {
76 detail::setGradientValue(domainVector, mesh_, this->range(), fixedGradient_);
77 }
78
79 static std::string name() { return "fixedGradient"; }
80
81 std::string getName() const override { return name(); }
82
83 static std::string doc() { return "Set a fixed gradient on the boundary."; }
84
85 static std::string schema() { return "none"; }
86
87 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
88 {
89 return std::make_unique<FixedGradient>(*this);
90 }
91
92private:
93
94 const UnstructuredMesh& mesh_;
95 ValueType fixedGradient_;
96};
97
98}
const scalarVector & deltaCoeffs() const
Get the field of delta coefficients.
const labelVector & faceOwners() const
Get the list of labels of owner cells of boundary faces.
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
const Vector< ValueType > & internalVector() const
Definition field.hpp:90
Represents an unstructured mesh in NeoN.
const BoundaryMesh & boundaryMesh() const
Get the boundary mesh.
virtual std::unique_ptr< VolumeBoundaryFactory< ValueType > > clone() const final
virtual void correctBoundaryCondition(Field< ValueType > &domainVector) final
FixedGradient(const UnstructuredMesh &mesh, const Dictionary &dict, localIdx patchID)
A template class for registering derived classes with a base class.
void setGradientValue(Field< ValueType > &domainVector, const UnstructuredMesh &mesh, std::pair< localIdx, localIdx > range, ValueType fixedGradient)
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