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
12
23
28
30{
31
32/* @brief creates a vector of boundary conditions of type calculated for every boundary
33 *
34 * @tparam Type of the Boundary ie SurfaceBoundary<scalar>
35 */
36template<typename BoundaryType>
37std::vector<BoundaryType> createCalculatedBCs(const UnstructuredMesh& mesh)
38{
39 std::vector<BoundaryType> bcs;
40 bcs.reserve(mesh.nBoundaries());
41
42 const auto nBoundaries = toLocalIdx(mesh.nBoundaries());
43 for (localIdx patchID = 0; patchID < nBoundaries; patchID++)
44 {
45 Dictionary patchDict({{"type", std::string("calculated")}});
46 bcs.emplace_back(mesh, patchDict, patchID);
47 }
48 return bcs;
49};
50
51template<typename BoundaryType>
52std::vector<BoundaryType> createCalculatedProcBCs(const UnstructuredMesh& mesh)
53{
54 std::vector<BoundaryType> bcs;
55 bcs.reserve(mesh.nBoundaries());
56 // Distributed-aware 'calculated': physical patches get the calculated BC (the value is computed
57 // by an operator), but processor (coupled) patches must carry the processor halo-exchange BC so
58 // that a single correctBoundaryConditions() fills their tail with the NEIGHBOUR cell value
59 // across the rank boundary. createCalculatedBCs leaves processor patches 'calculated' (no
60 // exchange), so a derived field that needs the neighbour value at proc faces — e.g. the cell
61 // gradient consumed by the corrected/limitedCorrected face-normal gradient — must use this
62 // variant and then correctBoundaryConditions() instead of a bespoke halo exchange.
63 // Processor (coupled) patches are the trailing patches of the boundary mesh;
64 // nProcBoundaryPatches is 0 on a serial / non-distributed mesh, so this degenerates to
65 // createCalculatedBCs there.
66 const auto nBoundaries = toLocalIdx(mesh.nBoundaries());
67 const localIdx nProcPatches = mesh.boundaryMesh().nProcBoundaryPatches();
68 const localIdx firstProcPatch = nBoundaries - nProcPatches;
69 for (localIdx patchID = 0; patchID < nBoundaries; patchID++)
70 {
71 const std::string type =
72 (patchID >= firstProcPatch) ? std::string("processor") : std::string("calculated");
73 Dictionary patchDict({{"type", type}});
74 bcs.emplace_back(mesh, patchDict, patchID);
75 }
76 return bcs;
77};
78
79template<typename BoundaryType>
80std::vector<BoundaryType> createExtrapolatedBCs(const UnstructuredMesh& mesh)
81{
82 std::vector<BoundaryType> bcs;
83 bcs.reserve(mesh.nBoundaries());
84 // Processor (coupled) patches are the trailing patches of the boundary mesh. A coupled patch
85 // must always carry the processor halo-exchange BC so its boundary tail holds the NEIGHBOUR
86 // cell value — interpolation/flux at processor faces read that tail as the far-side value.
87 // An 'extrapolated' tail would instead hold the OWNER value, which silently degenerates
88 // linear interpolation at proc faces to w*own+(1-w)*own=own (different on each rank) and so
89 // makes the assembled pressure matrix non-symmetric. Only physical patches get 'extrapolated'.
90 const auto nBoundaries = toLocalIdx(mesh.nBoundaries());
91 const localIdx nProcPatches = mesh.boundaryMesh().nProcBoundaryPatches();
92 const localIdx firstProcPatch = nBoundaries - nProcPatches;
93 for (localIdx patchID = 0; patchID < nBoundaries; patchID++)
94 {
95 const std::string type =
96 (patchID >= firstProcPatch) ? std::string("processor") : std::string("extrapolated");
97 Dictionary patchDict({{"type", type}});
98 bcs.emplace_back(mesh, patchDict, patchID);
99 }
100 return bcs;
101};
102
103}
104
105namespace NeoN
106{
107
109
114
117
120
122
127
130
133
136
139
143
148
151
156
159
162
163}
sizeType nProcBoundaryPatches() const
number of proc boundary patches
A class representing a dictionary that stores key-value pairs.
Represents an unstructured mesh in NeoN.
sizeType 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:52
std::vector< BoundaryType > createCalculatedBCs(const UnstructuredMesh &mesh)
Definition boundary.hpp:37
std::vector< BoundaryType > createExtrapolatedBCs(const UnstructuredMesh &mesh)
Definition boundary.hpp:80
Integer types used throughout NeoN.
Definition array.hpp:18
localIdx toLocalIdx(sizeType value)
int32_t localIdx
Definition label.hpp:50