NeoN
A framework for CFD software
Loading...
Searching...
No Matches
boundary.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
11
21
26
28{
29
30/* @brief creates a vector of boundary conditions of type calculated for every boundary
31 *
32 * @tparam Type of the Boundary ie SurfaceBoundary<scalar>
33 */
34template<typename BoundaryType>
35std::vector<BoundaryType> createCalculatedBCs(const UnstructuredMesh& mesh)
36{
37 std::vector<BoundaryType> bcs;
38 bcs.reserve(static_cast<std::size_t>(mesh.nBoundaries()));
39
40 for (localIdx patchID = 0; patchID < mesh.nBoundaries(); patchID++)
41 {
42 Dictionary patchDict({{"type", std::string("calculated")}});
43 bcs.emplace_back(mesh, patchDict, patchID);
44 }
45 return bcs;
46};
47
48template<typename BoundaryType>
49std::vector<BoundaryType> createCalculatedProcBCs(const UnstructuredMesh& mesh)
50{
51 std::vector<BoundaryType> bcs;
52 bcs.reserve(static_cast<std::size_t>(mesh.nBoundaries()));
53 // Distributed-aware 'calculated': physical patches get the calculated BC (the value is computed
54 // by an operator), but processor (coupled) patches must carry the processor halo-exchange BC so
55 // that a single correctBoundaryConditions() fills their tail with the NEIGHBOUR cell value
56 // across the rank boundary. createCalculatedBCs leaves processor patches 'calculated' (no
57 // exchange), so a derived field that needs the neighbour value at proc faces — e.g. the cell
58 // gradient consumed by the corrected/limitedCorrected face-normal gradient — must use this
59 // variant and then correctBoundaryConditions() instead of a bespoke halo exchange.
60 // Processor (coupled) patches are the trailing patches of the boundary mesh;
61 // nProcBoundaryPatches is 0 on a serial / non-distributed mesh, so this degenerates to
62 // createCalculatedBCs there.
63 const auto nProcPatches = mesh.boundaryMesh().nProcBoundaryPatches();
64 const auto firstProcPatch = mesh.nBoundaries() - nProcPatches;
65 for (localIdx patchID = 0; patchID < mesh.nBoundaries(); patchID++)
66 {
67 const std::string type =
68 (patchID >= firstProcPatch) ? std::string("processor") : std::string("calculated");
69 Dictionary patchDict({{"type", type}});
70 bcs.emplace_back(mesh, patchDict, patchID);
71 }
72 return bcs;
73};
74
75template<typename BoundaryType>
76std::vector<BoundaryType> createExtrapolatedBCs(const UnstructuredMesh& mesh)
77{
78 std::vector<BoundaryType> bcs;
79 bcs.reserve(mesh.nBoundaries());
80 // Processor (coupled) patches are the trailing patches of the boundary mesh. A coupled patch
81 // must always carry the processor halo-exchange BC so its boundary tail holds the NEIGHBOUR
82 // cell value — interpolation/flux at processor faces read that tail as the far-side value.
83 // An 'extrapolated' tail would instead hold the OWNER value, which silently degenerates
84 // linear interpolation at proc faces to w*own+(1-w)*own=own (different on each rank) and so
85 // makes the assembled pressure matrix non-symmetric. Only physical patches get 'extrapolated'.
86 const auto nProcPatches = mesh.boundaryMesh().nProcBoundaryPatches();
87 const auto firstProcPatch = mesh.nBoundaries() - nProcPatches;
88 for (localIdx patchID = 0; patchID < mesh.nBoundaries(); patchID++)
89 {
90 const std::string type =
91 (patchID >= firstProcPatch) ? std::string("processor") : std::string("extrapolated");
92 Dictionary patchDict({{"type", type}});
93 bcs.emplace_back(mesh, patchDict, patchID);
94 }
95 return bcs;
96};
97
98}
99
100namespace NeoN
101{
102
103namespace fvcc = finiteVolume::cellCentred;
104
109
110template class fvcc::volumeBoundary::FixedValue<scalar>;
111template class fvcc::volumeBoundary::FixedValue<Vec3>;
112
113template class fvcc::volumeBoundary::FixedGradient<scalar>;
114template class fvcc::volumeBoundary::FixedGradient<Vec3>;
115
116template class fvcc::volumeBoundary::FixedFluxPressure<scalar>;
117
118template class fvcc::volumeBoundary::Calculated<scalar>;
119template class fvcc::volumeBoundary::Calculated<Vec3>;
120template class fvcc::volumeBoundary::Calculated<Tensor>;
121template class fvcc::volumeBoundary::Calculated<SymmTensor>;
122
123template class fvcc::volumeBoundary::Extrapolated<scalar>;
124template class fvcc::volumeBoundary::Extrapolated<Vec3>;
125
126template class fvcc::volumeBoundary::Empty<scalar>;
127template class fvcc::volumeBoundary::Empty<Vec3>;
128
129template class fvcc::volumeBoundary::Symmetry<scalar>;
130template class fvcc::volumeBoundary::Symmetry<Vec3>;
131
132template class fvcc::volumeBoundary::Slip<scalar>;
133template class fvcc::volumeBoundary::Slip<Vec3>;
134
135template class fvcc::volumeBoundary::InletOutlet<scalar>;
136template class fvcc::volumeBoundary::InletOutlet<Vec3>;
137
142
143template class fvcc::surfaceBoundary::FixedValue<scalar>;
144template class fvcc::surfaceBoundary::FixedValue<Vec3>;
145
146template class fvcc::surfaceBoundary::Calculated<scalar>;
147template class fvcc::surfaceBoundary::Calculated<Vec3>;
148template class fvcc::surfaceBoundary::Calculated<Tensor>;
149template class fvcc::surfaceBoundary::Calculated<SymmTensor>;
150
151template class fvcc::surfaceBoundary::Empty<scalar>;
152template class fvcc::surfaceBoundary::Empty<Vec3>;
153
154template class fvcc::surfaceBoundary::Symmetry<scalar>;
155template class fvcc::surfaceBoundary::Symmetry<Vec3>;
156
157}
localIdx nProcBoundaryPatches() const
number of proc boundary patches
A class representing a dictionary that stores key-value pairs.
Represents an unstructured mesh in NeoN.
localIdx nBoundaries() const
Get the number of boundaries patches in the mesh.
const BoundaryMesh & boundaryMesh() const
Get the boundary mesh.
std::vector< BoundaryType > createCalculatedProcBCs(const UnstructuredMesh &mesh)
Definition boundary.hpp:49
std::vector< BoundaryType > createCalculatedBCs(const UnstructuredMesh &mesh)
Definition boundary.hpp:35
std::vector< BoundaryType > createExtrapolatedBCs(const UnstructuredMesh &mesh)
Definition boundary.hpp:76
Integer types used throughout NeoN.
Definition array.hpp:18
int32_t localIdx
Definition label.hpp:50