NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
linear.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 NeoN authors
3
4#pragma once
5
11
12#include <Kokkos_Core.hpp>
13
14#include <functional>
15
16
18{
19
20/* @brief computional kernel to perform a linear interpolation
21** from a source volumeVector to a surface field. It performs an interpolation
22** of the form
23**
24** d_f = w_f * s_O + ( 1 - w_f ) * s_N
25**
26**@param src the input field
27**@param weights weights for the interpolation
28**@param dst the target field
29*/
30template<typename ValueType>
32 const VolumeField<ValueType>& src,
33 const SurfaceField<scalar>& weights,
35);
36
37template<typename ValueType>
38class Linear : public SurfaceInterpolationFactory<ValueType>::template Register<Linear<ValueType>>
39{
41
42public:
43
44 Linear(const Executor& exec, const UnstructuredMesh& mesh, [[maybe_unused]] Input input)
45 : Base(exec, mesh), geometryScheme_(GeometryScheme::readOrCreate(mesh)) {};
46
47 Linear(const Executor& exec, const UnstructuredMesh& mesh)
48 : Base(exec, mesh), geometryScheme_(GeometryScheme::readOrCreate(mesh)) {};
49
50
51 static std::string name() { return "linear"; }
52
53 static std::string doc() { return "linear interpolation"; }
54
55 static std::string schema() { return "none"; }
56
57 void interpolate(const VolumeField<ValueType>& src, SurfaceField<ValueType>& dst) const override
58 {
59 computeLinearInterpolation(src, geometryScheme_->weights(), dst);
60 }
61
64 ) const override
65 {
66 interpolate(src, dst);
67 }
68
70 {
71 const SurfaceField<scalar>& linearWeight = geometryScheme_->weights();
72 weight.internalVector() = linearWeight.internalVector();
73 weight.boundaryData() = linearWeight.boundaryData();
74 }
75
76 void weight(
78 ) const override
79 {
80 const SurfaceField<scalar>& linearWeight = geometryScheme_->weights();
81 weight.internalVector() = linearWeight.internalVector();
82 weight.boundaryData() = linearWeight.boundaryData();
83 }
84
85
86 std::unique_ptr<SurfaceInterpolationFactory<ValueType>> clone() const override
87 {
88 return std::make_unique<Linear>(*this);
89 }
90
91private:
92
93 const std::shared_ptr<GeometryScheme> geometryScheme_;
94};
95
96} // namespace NeoN
97
98namespace NeoN
99{
100
101namespace fvcc = finiteVolume::cellCentred;
102
105
106template class fvcc::Linear<scalar>;
107template class fvcc::Linear<Vec3>;
108
109}
Represents an unstructured mesh in NeoN.
const BoundaryData< ValueType > & boundaryData() const
Returns a const reference to the boundary field.
Definition domain.hpp:100
const Vector< ValueType > & internalVector() const
Returns a const reference to the internal field.
Definition domain.hpp:79
std::unique_ptr< SurfaceInterpolationFactory< ValueType > > clone() const override
Definition linear.hpp:86
Linear(const Executor &exec, const UnstructuredMesh &mesh)
Definition linear.hpp:47
void weight(const SurfaceField< scalar > &, const VolumeField< ValueType > &, SurfaceField< scalar > &weight) const override
Definition linear.hpp:76
Linear(const Executor &exec, const UnstructuredMesh &mesh, Input input)
Definition linear.hpp:44
void interpolate(const VolumeField< ValueType > &src, SurfaceField< ValueType > &dst) const override
Definition linear.hpp:57
void weight(const VolumeField< ValueType > &, SurfaceField< scalar > &weight) const override
Definition linear.hpp:69
void interpolate(const SurfaceField< scalar > &, const VolumeField< ValueType > &src, SurfaceField< ValueType > &dst) const override
Definition linear.hpp:62
Represents a surface field in a finite volume method.
Represents a volume field in a finite volume method.
A template class for registering derived classes with a base class.
void computeLinearInterpolation(const VolumeField< ValueType > &src, const SurfaceField< scalar > &weights, SurfaceField< ValueType > &dst)
std::variant< Dictionary, TokenList > Input
Definition input.hpp:13
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16