NeoN
A framework for CFD software
Loading...
Searching...
No Matches
symmetry.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2025 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 --------------------------------------------------------
19inline void applySymmetry(
20 Field<scalar>& domainVector, const UnstructuredMesh& mesh, std::pair<size_t, size_t> range
21)
22{
23 auto [refValueV, valueV, internalValuesV, faceCellsV] = views(
24 domainVector.boundaryData().refValue(),
25 domainVector.boundaryData().value(),
26 domainVector.internalVector(),
27 mesh.boundaryMesh().faceCells()
28 );
29
30 const localIdx nInternalFaces = mesh.nInternalFaces();
31
33 domainVector.exec(),
34 range,
35 KOKKOS_LAMBDA(const localIdx i) {
36 const localIdx owner = faceCellsV[i];
37 const scalar v = internalValuesV[owner];
38
39 refValueV[i] = v;
40 valueV[i] = v;
41 },
42 "computeSymmetryBoundaryScalar"
43 );
44}
45
46// Vec3 specialization ----------------------------------------------------------
47inline void applySymmetry(
48 Field<Vec3>& domainVector, const UnstructuredMesh& mesh, std::pair<size_t, size_t> range
49)
50{
51 auto [refValueV, valueV, internalValuesV, faceCellsV, nHatV] = views(
52 domainVector.boundaryData().refValue(),
53 domainVector.boundaryData().value(),
54 domainVector.internalVector(),
55 mesh.boundaryMesh().faceCells(),
56 mesh.boundaryMesh().nf()
57 );
58
59 const localIdx nInternalFaces = mesh.nInternalFaces();
60
62 domainVector.exec(),
63 range,
64 KOKKOS_LAMBDA(const localIdx i) {
65 const localIdx owner = faceCellsV[i];
66 const Vec3 n = nHatV[i];
67
68 Vec3 v = internalValuesV[owner];
69 const scalar vn = v & n; // dot product
70 const auto vtan = v - n * vn;
71
72 refValueV[i] = vtan;
73 valueV[i] = vtan;
74 },
75 "computeSymmetryBoundaryVec3"
76 );
77}
78} // namespace detail
79
80
81template<typename ValueType>
82class Symmetry : public SurfaceBoundaryFactory<ValueType>::template Register<Symmetry<ValueType>>
83{
85
86public:
87
88 Symmetry(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
89 : Base(mesh, dict, patchID), mesh_(mesh)
90 {}
91
92 void correctBoundaryCondition(Field<ValueType>& domainVector) override
93 {
94 detail::applySymmetry(domainVector, mesh_, this->range());
95 }
96
97 static std::string name() { return "symmetry"; }
98 static std::string doc()
99 {
100 return "Symmetry plane (zero gradient for scalars, mirror for vectors)";
101 }
102 static std::string schema() { return "none"; }
103
104 std::unique_ptr<SurfaceBoundaryFactory<ValueType>> clone() const override
105 {
106 return std::make_unique<Symmetry>(*this);
107 }
108
109private:
110
111 const UnstructuredMesh& mesh_;
112};
113
114} // namespace NeoN::finiteVolume::cellCentred::surfaceBoundary
const Vector< T > & refValue() const
Get the view storing the Dirichlet boundary values.
const Vector< T > & value() const
Get the view storing the computed values from the boundary condition.
const vectorVector & nf() const
Get the field of face unit normals.
const labelVector & faceCells() const
Get the field of face cells.
A class representing a dictionary that stores key-value pairs.
Represents the domain fields for a computational domain.
Definition field.hpp:36
const BoundaryData< ValueType > & boundaryData() const
Definition field.hpp:98
const Executor & exec() const
Definition field.hpp:103
const Vector< ValueType > & internalVector() const
Definition field.hpp:92
Represents an unstructured mesh in NeoN.
localIdx nInternalFaces() const
Get the number of internal faces in the mesh.
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:88
std::unique_ptr< SurfaceBoundaryFactory< ValueType > > clone() const override
Definition symmetry.hpp:104
void correctBoundaryCondition(Field< ValueType > &domainVector) override
Definition symmetry.hpp:92
A template class for registering derived classes with a base class.
void applySymmetry(Field< scalar > &domainVector, const UnstructuredMesh &mesh, std::pair< size_t, size_t > range)
Definition symmetry.hpp:19
int32_t localIdx
Definition label.hpp:32
float scalar
Definition scalar.hpp:16
void parallelFor(const ExecutorType &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name)
auto views(Types &... args)
Unpacks all views of the passed classes.
Definition view.hpp:110