14#include <Kokkos_Core.hpp>
34 bool cellLimitedGradient =
false
50template<
typename ValueType>
60 : Base(exec, mesh), geometryScheme_(
GeometryScheme::readOrCreate(mesh)),
61 twoByk_(readTwoByk(input)), cellLimitedGradient_(readCellLimited(input))
65 geometryScheme_->ensureFaceDeltas();
68 static std::string
name() {
return "limitedLinear"; }
70 static std::string
doc() {
return "limitedLinear interpolation (TVD limited blend)"; }
72 static std::string
schema() {
return "none"; }
79 NF_ERROR_EXIT(
"limitedLinear interpolation scheme requires a faceFlux");
90 "limitedLinearWeights",
94 weight(flux, src, blended);
100 NF_ERROR_EXIT(
"limitedLinear interpolation scheme requires a faceFlux");
112 geometryScheme_->weights(),
113 geometryScheme_->faceDeltaOwner(),
114 geometryScheme_->faceDeltaNeighbour(),
121 std::unique_ptr<SurfaceInterpolationFactory<ValueType>>
clone()
const override
123 return std::make_unique<LimitedLinear>(*
this);
135 if (std::holds_alternative<NeoN::TokenList>(input))
137 auto& tokens = std::get<NeoN::TokenList>(input);
138 if (tokens.peekIs<
scalar>())
140 k = tokens.next<
scalar>();
142 else if (tokens.peekIs<
label>())
148 NF_THROW(
"limitedLinear requires a numeric coefficient: 'limitedLinear <k>'");
153 const auto& dict = std::get<NeoN::Dictionary>(input);
154 if (!dict.contains(
"limitedLinearCoeff"))
156 NF_THROW(
"limitedLinear requires the dictionary entry 'limitedLinearCoeff'");
158 k = dict.get<
scalar>(
"limitedLinearCoeff");
164 std::string(
"limitedLinear coefficient must be in [0, 1], got ") + std::to_string(k)
173 static bool readCellLimited(
Input& input)
175 if (std::holds_alternative<NeoN::TokenList>(input))
177 auto& tokens = std::get<NeoN::TokenList>(input);
178 if (!tokens.peekIs<std::string>())
return false;
180 const auto word = tokens.next<std::string>();
181 if (
word ==
"cellLimited")
return true;
183 std::string(
"limitedLinear accepts only 'cellLimited' after its coefficient, got ")
188 const auto& dict = std::get<NeoN::Dictionary>(input);
189 if (!dict.contains(
"limitedLinearGrad"))
return false;
191 const auto word = dict.get<std::string>(
"limitedLinearGrad");
192 if (
word ==
"cellLimited")
return true;
193 if (
word ==
"Gauss")
return false;
194 NF_THROW(std::string(
"limitedLinearGrad must be 'Gauss' or 'cellLimited', got ") +
word);
197 const std::shared_ptr<GeometryScheme> geometryScheme_;
199 bool cellLimitedGradient_;
Represents an unstructured mesh in NeoN.
const UnstructuredMesh & mesh() const
Returns a const reference to the unstructured mesh object.
const Executor & exec() const
Returns a const reference to the executor object.
static std::string schema()
void weight(const SurfaceField< scalar > &flux, const VolumeField< ValueType > &src, SurfaceField< scalar > &weights) const override
void interpolate(const VolumeField< ValueType > &src, SurfaceField< ValueType > &dst) const override
void interpolate(const SurfaceField< scalar > &flux, const VolumeField< ValueType > &src, SurfaceField< ValueType > &dst) const override
LimitedLinear(const Executor &exec, const UnstructuredMesh &mesh, Input input)
std::unique_ptr< SurfaceInterpolationFactory< ValueType > > clone() const override
void weight(const VolumeField< ValueType > &, SurfaceField< scalar > &) const override
static std::string name()
Represents a surface boundary field for a cell-centered finite volume method.
Represents a surface field in a finite volume method.
SurfaceInterpolationFactory(const Executor &exec, const UnstructuredMesh &mesh)
Represents a volume field in a finite volume method.
A template class for registering derived classes with a base class.
#define NF_THROW(message)
Macro for throwing a NeoNException with the specified error message.
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
void computeLinearInterpolation(const VolumeField< ValueType > &src, const SurfaceField< scalar > &weights, SurfaceField< ValueType > &dst)
void computeLimitedLinearWeights(const VolumeField< scalar > &src, const SurfaceField< scalar > &flux, const SurfaceField< scalar > &cdWeights, const SurfaceField< Vec3 > &faceDeltaOwner, const SurfaceField< Vec3 > &faceDeltaNeighbour, scalar twoByk, SurfaceField< scalar > &weights, bool cellLimitedGradient=false)
std::vector< BoundaryType > createCalculatedBCs(const UnstructuredMesh &mesh)
Integer types used throughout NeoN.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
std::variant< Dictionary, TokenList > Input
constexpr scalar ROOTVSMALL