NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
fixedGradient.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
11
13{
14
15// TODO move to source file
16namespace detail
17{
18// Without this function the compiler warns that calling a __host__ function
19// from a __device__ function is not allowed
20// NOTE: patchID was removed since it was unused
21// I guess it was replaced by range
22template<typename ValueType>
24 Field<ValueType>& domainVector,
25 const UnstructuredMesh& mesh,
26 std::pair<localIdx, localIdx> range,
27 ValueType fixedGradient
28)
29{
30 const auto iVector = domainVector.internalVector().view();
31
32 auto [refGradient, value, valueFraction, refValue, faceCells, deltaCoeffs] = views(
33 domainVector.boundaryData().refGrad(),
34 domainVector.boundaryData().value(),
35 domainVector.boundaryData().valueFraction(),
36 domainVector.boundaryData().refValue(),
37 mesh.boundaryMesh().faceCells(),
39 );
40
41
43 domainVector.exec(),
44 range,
45 KOKKOS_LAMBDA(const localIdx i) {
46 refGradient[i] = fixedGradient;
47 // operator / is not defined for all ValueTypes
48 value[i] = iVector[faceCells[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
66
67 FixedGradient(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
68 : Base(mesh, dict, patchID), mesh_(mesh),
69 fixedGradient_(dict.get<ValueType>("fixedGradient"))
70 {}
71
72 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) final
73 {
74 detail::setGradientValue(domainVector, mesh_, this->range(), fixedGradient_);
75 }
76
77 static std::string name() { return "fixedGradient"; }
78
79 static std::string doc() { return "Set a fixed gradient on the boundary."; }
80
81 static std::string schema() { return "none"; }
82
83 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
84 {
85 return std::make_unique<FixedGradient>(*this);
86 }
87
88private:
89
90 const UnstructuredMesh& mesh_;
91 ValueType fixedGradient_;
92};
93
94}
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: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)
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