NeoFOAM
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 NeoFOAM authors
3
4#pragma once
5
6#include <Kokkos_Core.hpp>
7
11
13{
14
15namespace detail
16{
17// Without this function the compiler warns that calling a __host__ function
18// from a __device__ function is not allowed
19template<typename ValueType>
21 DomainField<ValueType>& domainField,
22 const UnstructuredMesh& mesh,
23 std::pair<size_t, size_t> range,
24 size_t patchID,
25 ValueType fixedGradient
26)
27{
28 const auto iField = domainField.internalField().span();
29 auto refGradient = domainField.boundaryField().refGrad().span();
30 auto value = domainField.boundaryField().value().span();
31 auto faceCells = mesh.boundaryMesh().faceCells(static_cast<localIdx>(patchID));
32 auto deltaCoeffs = mesh.boundaryMesh().deltaCoeffs(static_cast<localIdx>(patchID));
33
35 domainField.exec(),
36 range,
37 KOKKOS_LAMBDA(const size_t i) {
38 refGradient[i] = fixedGradient;
39 // operator / is not defined for all ValueTypes
40 value[i] =
41 iField[static_cast<size_t>(faceCells[i])] + fixedGradient * (1 / deltaCoeffs[i]);
42 },
43 "setGradientValue"
44 );
45}
46}
47
48template<typename ValueType>
50 public VolumeBoundaryFactory<ValueType>::template Register<FixedGradient<ValueType>>
51{
53
54public:
55
57
58 FixedGradient(const UnstructuredMesh& mesh, const Dictionary& dict, std::size_t patchID)
59 : Base(mesh, dict, patchID), mesh_(mesh),
60 fixedGradient_(dict.get<ValueType>("fixedGradient"))
61 {}
62
63 virtual void correctBoundaryCondition(DomainField<ValueType>& domainField) final
64 {
66 domainField, mesh_, this->range(), this->patchID(), fixedGradient_
67 );
68 }
69
70 static std::string name() { return "fixedGradient"; }
71
72 static std::string doc() { return "Set a fixed gradient on the boundary."; }
73
74 static std::string schema() { return "none"; }
75
76 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
77 {
78 return std::make_unique<FixedGradient>(*this);
79 }
80
81private:
82
83 const UnstructuredMesh& mesh_;
84 ValueType fixedGradient_;
85};
86
87}
const NeoFOAM::Field< T > & refGrad() const
Get the view storing the Neumann boundary values.
const NeoFOAM::Field< T > & value() const
Get the view storing the computed values from the boundary condition.
const scalarField & deltaCoeffs() const
Get the field of delta coefficients.
const labelField & 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.
const Executor & exec() const
const BoundaryFields< ValueType > & boundaryField() const
const Field< ValueType > & internalField() const
Represents an unstructured mesh in NeoFOAM.
const BoundaryMesh & boundaryMesh() const
Get the boundary mesh.
FixedGradient(const UnstructuredMesh &mesh, const Dictionary &dict, std::size_t patchID)
virtual std::unique_ptr< VolumeBoundaryFactory< ValueType > > clone() const final
virtual void correctBoundaryCondition(DomainField< ValueType > &domainField) final
A template class for registering derived classes with a base class.
void setGradientValue(DomainField< ValueType > &domainField, const UnstructuredMesh &mesh, std::pair< size_t, size_t > range, size_t patchID, ValueType fixedGradient)
uint32_t localIdx
Definition label.hpp:14
void parallelFor(const Executor &exec, std::pair< size_t, size_t > range, Kernel kernel, std::string name="parallelFor")