NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
extrapolated.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
10
12{
13
14// TODO move to source file
15namespace detail
16{
17// Without this function the compiler warns that calling a __host__ function
18// from a __device__ function is not allowed
19// NOTE: patchID was removed since it was unused
20// I guess it was replaced by range
21template<typename ValueType>
23 Field<ValueType>& domainVector,
24 const UnstructuredMesh& mesh,
25 std::pair<localIdx, localIdx> range
26)
27{
28 const auto iVector = domainVector.internalVector().view();
29
30 auto [refGradient, value, valueFraction, refValue, faceCells] = views(
31 domainVector.boundaryData().refGrad(),
32 domainVector.boundaryData().value(),
33 domainVector.boundaryData().valueFraction(),
34 domainVector.boundaryData().refValue(),
35 mesh.boundaryMesh().faceCells()
36 );
37
38
40 domainVector.exec(),
41 range,
42 KOKKOS_LAMBDA(const localIdx i) {
43 // operator / is not defined for all ValueTypes
44 ValueType internalCellValue = iVector[faceCells[i]];
45 value[i] = internalCellValue;
46 valueFraction[i] = 1.0; // only use refValue
47 refValue[i] = internalCellValue; // not used
48 refGradient[i] = zero<ValueType>();
49 },
50 "extrapolateValue"
51 );
52}
53}
54
55template<typename ValueType>
57 public VolumeBoundaryFactory<ValueType>::template Register<Extrapolated<ValueType>>
58{
60
61public:
62
64
65 Extrapolated(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
66 : Base(mesh, dict, patchID), mesh_(mesh)
67 {}
68
69 virtual void correctBoundaryCondition([[maybe_unused]] Field<ValueType>& domainVector) final
70 {
71 detail::extrapolateValue(domainVector, mesh_, this->range());
72 }
73
74 static std::string name() { return "extrapolated"; }
75
76 static std::string doc() { return "TBD"; }
77
78 static std::string schema() { return "none"; }
79
80 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
81 {
82 return std::make_unique<Extrapolated>(*this);
83 }
84
85private:
86
87 const UnstructuredMesh& mesh_;
88};
89}
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 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 void correctBoundaryCondition(Field< ValueType > &domainVector) final
Extrapolated(const UnstructuredMesh &mesh, const Dictionary &dict, localIdx patchID)
virtual std::unique_ptr< VolumeBoundaryFactory< ValueType > > clone() const final
A template class for registering derived classes with a base class.
void extrapolateValue(Field< ValueType > &domainVector, const UnstructuredMesh &mesh, std::pair< localIdx, localIdx > range)
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