NeoN
A framework for CFD software
Loading...
Searching...
No Matches
faceNormalGradient.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2026 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <functional>
8
9#include <Kokkos_Core.hpp>
10
13#include "NeoN/core/input.hpp"
19
21{
22
23template<typename ValueType>
26 FaceNormalGradientFactory<ValueType>,
27 Parameters<const Executor&, const UnstructuredMesh&, const Input&>>
28{
29
30public:
31
32 static std::unique_ptr<FaceNormalGradientFactory>
33 create(const Executor& exec, const UnstructuredMesh& uMesh, const Input& inputs)
34 {
35 // input is dictionary the key is "interpolation"
36 std::string key =
37 (std::holds_alternative<NeoN::Dictionary>(inputs))
38 ? std::get<NeoN::Dictionary>(inputs).get<std::string>("faceNormalGradient")
39 : std::get<NeoN::TokenList>(inputs).next<std::string>();
40
42 return FaceNormalGradientFactory<ValueType>::table().at(key)(exec, uMesh, inputs);
43 }
44
45 static std::string name() { return "FaceNormalGradientFactory"; }
46
48 : exec_(exec), mesh_(mesh) {};
49
50 virtual ~FaceNormalGradientFactory() {} // Virtual destructor
51
61 virtual void faceNormalGrad(
62 const VolumeField<ValueType>& volVector, SurfaceField<ValueType>& surfaceVector
63 ) const = 0;
64
65 virtual const SurfaceField<scalar>& deltaCoeffs() const = 0;
66
67 // Returns true when this scheme contributes a non-zero explicit correction
68 // term to the implicit Laplacian RHS (i.e. corrected and limitedCorrected).
69 virtual bool hasImplicitCorrection() const { return false; }
70
71 // Fills corrField.internalVector() with the per-face correction term:
72 // corrected → corrVec[f] · interpGrad[f]
73 // limitedCorrected → limiter[f] * corrVec[f] · interpGrad[f]
74 // Default (uncorrected): fills internal vector with zeros.
75 virtual void
77 {
78 NeoN::fill(corrField.internalVector(), zero<ValueType>());
79 }
80
81 // Pure virtual function for cloning
82 virtual std::unique_ptr<FaceNormalGradientFactory<ValueType>> clone() const = 0;
83
84protected:
85
88};
89
90template<typename ValueType>
92{
93
94public:
95
97 : exec_(faceNGrad.exec_), mesh_(faceNGrad.mesh_),
98 faceNormalGradKernel_(faceNGrad.faceNormalGradKernel_->clone()) {};
99
101 : exec_(faceNGrad.exec_), mesh_(faceNGrad.mesh_),
102 faceNormalGradKernel_(std::move(faceNGrad.faceNormalGradKernel_)) {};
103
105 const Executor& exec,
106 const UnstructuredMesh& mesh,
107 std::unique_ptr<FaceNormalGradientFactory<ValueType>> faceNormalGradient
108 )
109 : exec_(exec), mesh_(mesh), faceNormalGradKernel_(std::move(faceNormalGradient)) {};
110
111 FaceNormalGradient(const Executor& exec, const UnstructuredMesh& mesh, const Input& input)
112 : exec_(exec), mesh_(mesh),
113 faceNormalGradKernel_(FaceNormalGradientFactory<ValueType>::create(exec, mesh, input)) {};
114
115
117 const VolumeField<ValueType>& volVector, SurfaceField<ValueType>& surfaceVector
118 ) const
119 {
120 faceNormalGradKernel_->faceNormalGrad(volVector, surfaceVector);
121 }
122
123 const SurfaceField<scalar>& deltaCoeffs() const { return faceNormalGradKernel_->deltaCoeffs(); }
124
125 bool hasImplicitCorrection() const { return faceNormalGradKernel_->hasImplicitCorrection(); }
126
127 void
129 {
130 faceNormalGradKernel_->implicitCorrection(phi, corrField);
131 }
132
134 {
135 std::string nameInterpolated = "interpolated_" + volVector.name;
136 SurfaceField<ValueType> surfaceVector(
137 exec_, nameInterpolated, mesh_, createCalculatedBCs<SurfaceBoundary<ValueType>>(mesh_)
138 );
139 faceNormalGrad(volVector, surfaceVector);
140 return surfaceVector;
141 }
142
143private:
144
145 const Executor exec_;
146 const UnstructuredMesh& mesh_;
147 std::unique_ptr<FaceNormalGradientFactory<ValueType>> faceNormalGradKernel_;
148};
149
150
151} // namespace NeoN
A factory class for runtime selection of derived classes.
Represents an unstructured mesh in NeoN.
const Vector< ValueType > & internalVector() const
Returns a const reference to the internal field.
Definition domain.hpp:80
static std::unique_ptr< FaceNormalGradientFactory > create(const Executor &exec, const UnstructuredMesh &uMesh, const Input &inputs)
virtual void faceNormalGrad(const VolumeField< ValueType > &volVector, SurfaceField< ValueType > &surfaceVector) const =0
Computes the face-normal gradient of volVector into surfaceVector.
virtual void implicitCorrection(const VolumeField< ValueType > &, SurfaceField< ValueType > &corrField) const
virtual const SurfaceField< scalar > & deltaCoeffs() const =0
virtual std::unique_ptr< FaceNormalGradientFactory< ValueType > > clone() const =0
FaceNormalGradientFactory(const Executor &exec, const UnstructuredMesh &mesh)
FaceNormalGradient(const Executor &exec, const UnstructuredMesh &mesh, const Input &input)
const SurfaceField< scalar > & deltaCoeffs() const
FaceNormalGradient(const Executor &exec, const UnstructuredMesh &mesh, std::unique_ptr< FaceNormalGradientFactory< ValueType > > faceNormalGradient)
SurfaceField< ValueType > faceNormalGrad(const VolumeField< ValueType > &volVector) const
FaceNormalGradient(const FaceNormalGradient &faceNGrad)
void implicitCorrection(const VolumeField< ValueType > &phi, SurfaceField< ValueType > &corrField) const
void faceNormalGrad(const VolumeField< ValueType > &volVector, SurfaceField< ValueType > &surfaceVector) const
Represents a surface boundary field for a cell-centered finite volume method.
Represents a surface field in a finite volume method.
Represents a volume field in a finite volume method.
std::vector< BoundaryType > createCalculatedBCs(const UnstructuredMesh &mesh)
Definition boundary.hpp:35
std::variant< Dictionary, TokenList > Input
Definition input.hpp:15
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:20
void fill(ContType< ValueType > &cont, const std::type_identity_t< ValueType > value, std::pair< localIdx, localIdx > range={0, 0})
Fill the field with a vector value using a specific executor.