NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
uncorrected.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 NeoFOAM authors
3
4#pragma once
5
11
12#include <Kokkos_Core.hpp>
13
14#include <functional>
15
16
18{
19
20template<typename ValueType>
22 const VolumeField<ValueType>& volField,
23 const std::shared_ptr<GeometryScheme> geometryScheme,
24 SurfaceField<ValueType>& surfaceField
25)
26{
27 const UnstructuredMesh& mesh = surfaceField.mesh();
28 const auto& exec = surfaceField.exec();
29
30 const auto [owner, neighbour, surfFaceCells] =
31 spans(mesh.faceOwner(), mesh.faceNeighbour(), mesh.boundaryMesh().faceCells());
32
33
34 const auto [phif, phi, phiBCValue, nonOrthDeltaCoeffs] = spans(
35 surfaceField.internalField(),
36 volField.internalField(),
37 volField.boundaryField().value(),
38 geometryScheme->nonOrthDeltaCoeffs().internalField()
39 );
40
41 size_t nInternalFaces = mesh.nInternalFaces();
42
44 exec,
45 {0, nInternalFaces},
46 KOKKOS_LAMBDA(const size_t facei) {
47 phif[facei] = nonOrthDeltaCoeffs[facei] * (phi[neighbour[facei]] - phi[owner[facei]]);
48 }
49 );
50
52 exec,
53 {nInternalFaces, phif.size()},
54 KOKKOS_LAMBDA(const size_t facei) {
55 auto faceBCI = facei - nInternalFaces;
56 auto own = static_cast<size_t>(surfFaceCells[faceBCI]);
57
58 phif[facei] = nonOrthDeltaCoeffs[facei] * (phiBCValue[faceBCI] - phi[own]);
59 }
60 );
61}
62
63template<typename ValueType>
65 public FaceNormalGradientFactory<ValueType>::template Register<Uncorrected<ValueType>>
66{
68
69
70public:
71
72 Uncorrected(const Executor& exec, const UnstructuredMesh& mesh, Input input)
73 : Base(exec, mesh), geometryScheme_(GeometryScheme::readOrCreate(mesh)) {};
74
75 Uncorrected(const Executor& exec, const UnstructuredMesh& mesh)
76 : Base(exec, mesh), geometryScheme_(GeometryScheme::readOrCreate(mesh)) {};
77
78 static std::string name() { return "uncorrected"; }
79
80 static std::string doc() { return "Uncorrected interpolation"; }
81
82 static std::string schema() { return "none"; }
83
84 virtual void faceNormalGrad(
85 const VolumeField<ValueType>& volField, SurfaceField<ValueType>& surfaceField
86 ) const override
87 {
88 computeFaceNormalGrad(volField, geometryScheme_, surfaceField);
89 }
90
91 virtual const SurfaceField<scalar>& deltaCoeffs() const override
92 {
93 return geometryScheme_->nonOrthDeltaCoeffs();
94 }
95
96 std::unique_ptr<FaceNormalGradientFactory<ValueType>> clone() const override
97 {
98 return std::make_unique<Uncorrected>(*this);
99 }
100
101private:
102
103 const std::shared_ptr<GeometryScheme> geometryScheme_;
104};
105
106} // namespace NeoFOAM
const NeoFOAM::Field< T > & value() const
Get the view storing the computed values from the boundary condition.
const labelField & faceCells() const
Get the field of face cells.
Represents an unstructured mesh in NeoFOAM.
const BoundaryMesh & boundaryMesh() const
Get the boundary mesh.
size_t nInternalFaces() const
Get the number of internal faces in the mesh.
const labelField & faceOwner() const
Get the field of face owner cells.
const labelField & faceNeighbour() const
Get the field of face neighbour cells.
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.
const Field< ValueType > & internalField() const
Returns a const reference to the internal field.
const BoundaryFields< ValueType > & boundaryField() const
Returns a const reference to the boundary field.
Represents a surface field in a finite volume method.
Uncorrected(const Executor &exec, const UnstructuredMesh &mesh, Input input)
Uncorrected(const Executor &exec, const UnstructuredMesh &mesh)
virtual void faceNormalGrad(const VolumeField< ValueType > &volField, SurfaceField< ValueType > &surfaceField) const override
std::unique_ptr< FaceNormalGradientFactory< ValueType > > clone() const override
virtual const SurfaceField< scalar > & deltaCoeffs() const override
Represents a volume field in a finite volume method.
A template class for registering derived classes with a base class.
void computeFaceNormalGrad(const VolumeField< ValueType > &volField, const std::shared_ptr< GeometryScheme > geometryScheme, SurfaceField< ValueType > &surfaceField)
std::variant< Dictionary, TokenList > Input
Definition input.hpp:13
void parallelFor(const Executor &exec, std::pair< size_t, size_t > range, Kernel kernel)
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16
auto spans(Args &... fields)