NeoN
A framework for CFD software
Loading...
Searching...
No Matches
fixedGradient.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
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, faceCells, deltaCoeffs] = views(
34 domainVector.boundaryData().refGrad(),
35 domainVector.boundaryData().value(),
36 domainVector.boundaryData().valueFraction(),
37 domainVector.boundaryData().refValue(),
38 mesh.boundaryMesh().faceCells(),
40 );
41
42
44 domainVector.exec(),
45 range,
46 KOKKOS_LAMBDA(const localIdx i) {
47 refGradient[i] = fixedGradient;
48 // operator / is not defined for all ValueTypes
49 value[i] = iVector[faceCells[i]] + fixedGradient * (1 / deltaCoeffs[i]);
50 valueFraction[i] = 0.0; // only use refGrad
51 refValue[i] = zero<ValueType>(); // not used
52 },
53 "setGradientValue"
54 );
55}
56}
57
58template<typename ValueType>
60 public VolumeBoundaryFactory<ValueType>::template Register<FixedGradient<ValueType>>
61{
63
64public:
65
67
68 FixedGradient(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
69 : Base(mesh, dict, patchID, {.assignable = true}), mesh_(mesh),
70 fixedGradient_(dict.get<ValueType>("fixedGradient"))
71 {}
72
73 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) final
74 {
75 detail::setGradientValue(domainVector, mesh_, this->range(), fixedGradient_);
76 }
77
78 static std::string name() { return "fixedGradient"; }
79
80 static std::string doc() { return "Set a fixed gradient on the boundary."; }
81
82 static std::string schema() { return "none"; }
83
84 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
85 {
86 return std::make_unique<FixedGradient>(*this);
87 }
88
89private:
90
91 const UnstructuredMesh& mesh_;
92 ValueType fixedGradient_;
93};
94
95}
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.
const scalarVector & deltaCoeffs() const
Get the field of delta coefficients.
const labelVector & faceCells() const
Get the field of face cells.
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
const Vector< ValueType > & internalVector() const
Definition field.hpp:92
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)
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