NeoN
A framework for CFD software
Loading...
Searching...
No Matches
symmetry.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 <Kokkos_Core.hpp>
8
13
15{
16namespace detail
17{
18// Scalar specialization: zero flux at the symmetry plane
19inline void applySymmetry(
20 Field<scalar>& domainVector,
21 [[maybe_unused]] const UnstructuredMesh&,
22 std::pair<size_t, size_t> range
23)
24{
25 auto [refValueV, valueV] =
26 views(domainVector.boundaryData().refValue(), domainVector.boundaryData().value());
27
29 domainVector.exec(),
30 range,
31 NEON_LAMBDA(const localIdx i) {
32 refValueV[i] = 0;
33 valueV[i] = 0;
34 },
35 "computeSymmetryBoundaryScalar"
36 );
37}
38
39// Vec3 specialization: zero the normal component of the existing face value
40inline void applySymmetry(
41 Field<Vec3>& domainVector, const UnstructuredMesh& mesh, std::pair<size_t, size_t> range
42)
43{
44 auto [refValueV, valueV, nHatV] = views(
45 domainVector.boundaryData().refValue(),
46 domainVector.boundaryData().value(),
48 );
49
51 domainVector.exec(),
52 range,
53 NEON_LAMBDA(const localIdx i) {
54 const Vec3 n = nHatV[i];
55 const Vec3 v = valueV[i];
56 const scalar vn = v & n;
57 const Vec3 vtan = v - n * vn;
58
59 refValueV[i] = vtan;
60 valueV[i] = vtan;
61 },
62 "computeSymmetryBoundaryVec3"
63 );
64}
65} // namespace detail
66
67
68template<typename ValueType>
69class Symmetry : public SurfaceBoundaryFactory<ValueType>::template Register<Symmetry<ValueType>>
70{
72
73public:
74
75 Symmetry(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
76 : Base(mesh, dict, patchID), mesh_(mesh)
77 {}
78
79 void correctBoundaryCondition(Field<ValueType>& domainVector) override
80 {
81 detail::applySymmetry(domainVector, mesh_, this->range());
82 }
83
84 static std::string name() { return "symmetry"; }
85 static std::string doc()
86 {
87 return "Symmetry plane (zero gradient for scalars, mirror for vectors)";
88 }
89 static std::string schema() { return "none"; }
90
91 std::unique_ptr<SurfaceBoundaryFactory<ValueType>> clone() const override
92 {
93 return std::make_unique<Symmetry>(*this);
94 }
95
96private:
97
98 const UnstructuredMesh& mesh_;
99};
100
101} // namespace NeoN::finiteVolume::cellCentred::surfaceBoundary
const vectorVector & faceUnitNormals() const
Get the field of face unit normal vectors.
A class representing a dictionary that stores key-value pairs.
Represents the domain fields for a computational domain.
Definition field.hpp:34
const BoundaryData< ValueType > & boundaryData() const
Definition field.hpp:96
const Executor & exec() const
Definition field.hpp:101
Represents an unstructured mesh in NeoN.
const BoundaryMesh & boundaryMesh() const
Get the boundary mesh.
A class for the representation of a 3D Vec3.
Definition vec3.hpp:24
Symmetry(const UnstructuredMesh &mesh, const Dictionary &dict, localIdx patchID)
Definition symmetry.hpp:75
std::unique_ptr< SurfaceBoundaryFactory< ValueType > > clone() const override
Definition symmetry.hpp:91
void correctBoundaryCondition(Field< ValueType > &domainVector) override
Definition symmetry.hpp:79
A template class for registering derived classes with a base class.
void applySymmetry(Field< scalar > &domainVector, const UnstructuredMesh &, std::pair< size_t, size_t > range)
Definition symmetry.hpp:19
int32_t localIdx
Definition label.hpp:50
float scalar
Definition scalar.hpp:17
void parallelFor(const ExecutorType &, std::pair< localIdx, localIdx > range, const Kernel &kernel, std::string name)
auto views(Types &... args)
Unpacks all views of the passed classes.
Definition view.hpp:107
#define NEON_LAMBDA