NeoN
A framework for CFD software
Loading...
Searching...
No Matches
limitedCorrected.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 "NeoN/core/error.hpp"
9#include "NeoN/core/input.hpp"
15
16#include <Kokkos_Core.hpp>
17
18#include <functional>
19
20
22{
23
24template<typename ValueType>
26 const VolumeField<ValueType>& volField,
27 const std::shared_ptr<GeometryScheme> geometryScheme,
28 scalar limitCoeff,
29 SurfaceField<ValueType>& surfaceField
30);
31
32template<typename ValueType>
34 const VolumeField<ValueType>& volField,
35 const std::shared_ptr<GeometryScheme> geometryScheme,
36 scalar limitCoeff,
38);
39
40template<typename ValueType>
42 public FaceNormalGradientFactory<ValueType>::template Register<LimitedCorrected<ValueType>>
43{
44 using Base =
46
47 static constexpr scalar DEFAULT_LIMIT_COEFF = 0.333;
48
49public:
50
51 LimitedCorrected(const Executor& exec, const UnstructuredMesh& mesh, const Input& inputs)
52 : Base(exec, mesh), geometryScheme_(GeometryScheme::readOrCreate(mesh)),
53 limitCoeff_(readLimitCoeff(inputs)) {};
54
55 LimitedCorrected(const Executor& exec, const UnstructuredMesh& mesh)
56 : Base(exec, mesh), geometryScheme_(GeometryScheme::readOrCreate(mesh)),
57 limitCoeff_(DEFAULT_LIMIT_COEFF) {};
58
59 static std::string name() { return "limited"; }
60
61 static std::string doc()
62 {
63 return "Limited corrected face normal gradient with bounded non-orthogonality correction";
64 }
65
66 static std::string schema() { return "none"; }
67
68 virtual void faceNormalGrad(
69 const VolumeField<ValueType>& volField, SurfaceField<ValueType>& surfaceField
70 ) const override
71 {
72 computeLimitedCorrectedFaceNormalGrad(volField, geometryScheme_, limitCoeff_, surfaceField);
73 }
74
75 virtual const SurfaceField<scalar>& deltaCoeffs() const override
76 {
77 return geometryScheme_->nonOrthDeltaCoeffs();
78 }
79
80 bool hasImplicitCorrection() const override { return true; }
81
82 virtual void implicitCorrection(
84 ) const override
85 {
86 computeLimitedCorrectionTerm(phi, geometryScheme_, limitCoeff_, corrField);
87 }
88
89 std::unique_ptr<FaceNormalGradientFactory<ValueType>> clone() const override
90 {
91 return std::make_unique<LimitedCorrected>(*this);
92 }
93
94private:
95
96 static scalar readLimitCoeff(const Input& inputs)
97 {
98 if (std::holds_alternative<NeoN::Dictionary>(inputs))
99 {
100 const auto& dict = std::get<NeoN::Dictionary>(inputs);
101 if (dict.contains("limitCoeff"))
102 {
103 return dict.get<scalar>("limitCoeff");
104 }
105 return DEFAULT_LIMIT_COEFF;
106 }
107 // TokenList: accept either OF form
108 // terse: "limited" <coeff>
109 // verbose: "limited" "corrected" <coeff>
110 // The factory has already consumed "limited"; consume an optional
111 // "corrected" sub-scheme token if present, then read the coefficient.
112 const auto& tl = std::get<NeoN::TokenList>(inputs);
113 if (tl.peekIs<std::string>())
114 {
115 const std::string& sub = tl.next<std::string>();
116 NF_ASSERT(
117 sub == "corrected", "limited snGrad: only 'corrected' sub-scheme is supported"
118 );
119 }
120 return tl.next<scalar>();
121 }
122
123 const std::shared_ptr<GeometryScheme> geometryScheme_;
124 scalar limitCoeff_;
125};
126
127// instantiate the template class
128template class LimitedCorrected<scalar>;
129template class LimitedCorrected<Vec3>;
130
131} // namespace NeoN
Represents an unstructured mesh in NeoN.
virtual const SurfaceField< scalar > & deltaCoeffs() const override
std::unique_ptr< FaceNormalGradientFactory< ValueType > > clone() const override
virtual void faceNormalGrad(const VolumeField< ValueType > &volField, SurfaceField< ValueType > &surfaceField) const override
LimitedCorrected(const Executor &exec, const UnstructuredMesh &mesh, const Input &inputs)
virtual void implicitCorrection(const VolumeField< ValueType > &phi, SurfaceField< ValueType > &corrField) const override
LimitedCorrected(const Executor &exec, const UnstructuredMesh &mesh)
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.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
Definition error.hpp:118
void computeLimitedCorrectedFaceNormalGrad(const VolumeField< ValueType > &volField, const std::shared_ptr< GeometryScheme > geometryScheme, scalar limitCoeff, SurfaceField< ValueType > &surfaceField)
void computeLimitedCorrectionTerm(const VolumeField< ValueType > &volField, const std::shared_ptr< GeometryScheme > geometryScheme, scalar limitCoeff, SurfaceField< ValueType > &corrField)
void sub(Vector< ValueType > &vect, const std::type_identity_t< ValueType > &value)
std::variant< Dictionary, TokenList > Input
Definition input.hpp:15
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:20
float scalar
Definition scalar.hpp:17