NeoN
A framework for CFD software
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
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)
28{
29 const auto iVector = domainVector.internalVector().view();
30
31 auto [refGradient, value, valueFraction, refValue, faceCells] = views(
32 domainVector.boundaryData().refGrad(),
33 domainVector.boundaryData().value(),
34 domainVector.boundaryData().valueFraction(),
35 domainVector.boundaryData().refValue(),
36 mesh.boundaryMesh().faceCells()
37 );
38
39
41 domainVector.exec(),
42 range,
43 KOKKOS_LAMBDA(const localIdx i) {
44 // operator / is not defined for all ValueTypes
45 ValueType internalCellValue = iVector[faceCells[i]];
46 value[i] = internalCellValue;
47 valueFraction[i] = 1.0; // only use refValue
48 refValue[i] = internalCellValue; // not used
49 refGradient[i] = zero<ValueType>();
50 },
51 "extrapolateValue"
52 );
53}
54}
55
56template<typename ValueType>
58 public VolumeBoundaryFactory<ValueType>::template Register<Extrapolated<ValueType>>
59{
61
62public:
63
65
66 Extrapolated(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
67 : Base(mesh, dict, patchID, {.assignable = true}), mesh_(mesh)
68 {}
69
70 virtual void correctBoundaryCondition([[maybe_unused]] Field<ValueType>& domainVector) final
71 {
72 detail::extrapolateValue(domainVector, mesh_, this->range());
73 }
74
75 static std::string name() { return "extrapolated"; }
76
77 static std::string doc() { return "TBD"; }
78
79 static std::string schema() { return "none"; }
80
81 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
82 {
83 return std::make_unique<Extrapolated>(*this);
84 }
85
86private:
87
88 const UnstructuredMesh& mesh_;
89};
90}
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:108