NeoN
A framework for CFD software
Loading...
Searching...
No Matches
upwind.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
17{
18
19/* @brief computional kernel to perform an upwind interpolation
20** from a source volumeVector to a surface field. It performs an interpolation
21** of the form
22**
23** d_f = w_f * s_O + ( 1 - w_f ) * s_N where w_1 is either 0,1 depending on the
24** direction of the flux
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>& flux,
34 const SurfaceField<scalar>& weights,
36);
37
38
39template<typename ValueType>
41 const SurfaceField<scalar>& flux,
42 const VolumeField<ValueType>& src,
44);
45
46
47template<typename ValueType>
48class Upwind : public SurfaceInterpolationFactory<ValueType>::template Register<Upwind<ValueType>>
49{
50
52
53public:
54
55 Upwind(const Executor& exec, const UnstructuredMesh& mesh, [[maybe_unused]] Input input)
56 : Base(exec, mesh), geometryScheme_(GeometryScheme::readOrCreate(mesh)) {};
57
58 static std::string name() { return "upwind"; }
59
60 static std::string doc() { return "upwind interpolation"; }
61
62 static std::string schema() { return "none"; }
63
65 [[maybe_unused]] const VolumeField<ValueType>& src,
66 [[maybe_unused]] SurfaceField<ValueType>& dst
67 ) const override
68 {
69 NF_ERROR_EXIT("limited scheme require a faceFlux");
70 }
71
73 const SurfaceField<scalar>& flux,
74 const VolumeField<ValueType>& src,
76 ) const override
77 {
78 computeUpwindInterpolation(src, flux, geometryScheme_->weights(), dst);
79 }
80
81 // src weight
83 {
84 NF_ERROR_EXIT("upwind interpolation scheme requires a faceFlux");
85 }
86
87 // flux, src, weight
88 void weight(
89 const SurfaceField<scalar>& faceFlux,
90 const VolumeField<ValueType>& src,
92 ) const override
93 {
94 computeUpwindInterpolationWeights(faceFlux, src, weights);
95 }
96
97 std::unique_ptr<SurfaceInterpolationFactory<ValueType>> clone() const override
98 {
99 return std::make_unique<Upwind>(*this);
100 }
101
102private:
103
104 const std::shared_ptr<GeometryScheme> geometryScheme_;
105};
106
107} // namespace NeoN
108
109
110namespace NeoN
111{
112
113namespace fvcc = finiteVolume::cellCentred;
114
115template class fvcc::Upwind<scalar>;
116template class fvcc::Upwind<Vec3>;
117
118}
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:55
void weight(const SurfaceField< scalar > &faceFlux, const VolumeField< ValueType > &src, SurfaceField< scalar > &weights) const override
Definition upwind.hpp:88
void weight(const VolumeField< ValueType > &, SurfaceField< scalar > &) const override
Definition upwind.hpp:82
std::unique_ptr< SurfaceInterpolationFactory< ValueType > > clone() const override
Definition upwind.hpp:97
void interpolate(const VolumeField< ValueType > &src, SurfaceField< ValueType > &dst) const override
Definition upwind.hpp:64
void interpolate(const SurfaceField< scalar > &flux, const VolumeField< ValueType > &src, SurfaceField< ValueType > &dst) const override
Definition upwind.hpp:72
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:108
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:19
std::variant< Dictionary, TokenList > Input
Definition input.hpp:13
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16