NeoN
A framework for CFD software
Loading...
Searching...
No Matches
upwind.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
12
13#include <Kokkos_Core.hpp>
14
15#include <functional>
16
18{
19
20/* @brief computional kernel to perform an upwind 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 where w_1 is either 0,1 depending on the
25** direction of the flux
26**
27**@param src the input field
28**@param weights weights for the interpolation
29**@param dst the target field
30*/
31template<typename ValueType>
33 const VolumeField<ValueType>& src,
34 const SurfaceField<scalar>& flux,
35 const SurfaceField<scalar>& weights,
37);
38
39
40template<typename ValueType>
42 const SurfaceField<scalar>& flux,
43 const VolumeField<ValueType>& src,
45);
46
47
48template<typename ValueType>
49class Upwind : public SurfaceInterpolationFactory<ValueType>::template Register<Upwind<ValueType>>
50{
51
53
54public:
55
56 Upwind(const Executor& exec, const UnstructuredMesh& mesh, [[maybe_unused]] Input input)
57 : Base(exec, mesh), geometryScheme_(GeometryScheme::readOrCreate(mesh)) {};
58
59 static std::string name() { return "upwind"; }
60
61 static std::string doc() { return "upwind interpolation"; }
62
63 static std::string schema() { return "none"; }
64
66 [[maybe_unused]] const VolumeField<ValueType>& src,
67 [[maybe_unused]] SurfaceField<ValueType>& dst
68 ) const override
69 {
70 NF_ERROR_EXIT("limited scheme require a faceFlux");
71 }
72
74 const SurfaceField<scalar>& flux,
75 const VolumeField<ValueType>& src,
77 ) const override
78 {
79 computeUpwindInterpolation(src, flux, geometryScheme_->weights(), dst);
80 }
81
82 // src weight
84 {
85 NF_ERROR_EXIT("upwind interpolation scheme requires a faceFlux");
86 }
87
88 // flux, src, weight
89 void weight(
90 const SurfaceField<scalar>& faceFlux,
91 const VolumeField<ValueType>& src,
93 ) const override
94 {
95 computeUpwindInterpolationWeights(faceFlux, src, weights);
96 }
97
98 std::unique_ptr<SurfaceInterpolationFactory<ValueType>> clone() const override
99 {
100 return std::make_unique<Upwind>(*this);
101 }
102
103private:
104
105 const std::shared_ptr<GeometryScheme> geometryScheme_;
106};
107
108} // namespace NeoN
109
110
111namespace NeoN
112{
113
114namespace fvcc = finiteVolume::cellCentred;
115
116template class fvcc::Upwind<scalar>;
117template class fvcc::Upwind<Vec3>;
118
119}
Represents an unstructured mesh in NeoN.
Represents a surface field in a finite volume method.
Upwind(const Executor &exec, const UnstructuredMesh &mesh, Input input)
Definition upwind.hpp:56
void weight(const SurfaceField< scalar > &faceFlux, const VolumeField< ValueType > &src, SurfaceField< scalar > &weights) const override
Definition upwind.hpp:89
void weight(const VolumeField< ValueType > &, SurfaceField< scalar > &) const override
Definition upwind.hpp:83
std::unique_ptr< SurfaceInterpolationFactory< ValueType > > clone() const override
Definition upwind.hpp:98
void interpolate(const VolumeField< ValueType > &src, SurfaceField< ValueType > &dst) const override
Definition upwind.hpp:65
void interpolate(const SurfaceField< scalar > &flux, const VolumeField< ValueType > &src, SurfaceField< ValueType > &dst) const override
Definition upwind.hpp:73
Represents a volume field in a finite volume method.
A template class for registering derived classes with a base class.
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
Definition error.hpp:110
void computeUpwindInterpolationWeights(const SurfaceField< scalar > &flux, const VolumeField< ValueType > &src, SurfaceField< scalar > &weights)
void computeUpwindInterpolation(const VolumeField< ValueType > &src, const SurfaceField< scalar > &flux, const SurfaceField< scalar > &weights, SurfaceField< ValueType > &dst)
Definition array.hpp:20
std::variant< Dictionary, TokenList > Input
Definition input.hpp:15
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:18