NeoN
A framework for CFD software
Loading...
Searching...
No Matches
fixedFluxPressure.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
12
14{
15
16namespace detail
17{
18// Recompute the boundary value from the EXISTING per-face refGrad (does NOT overwrite
19// refGrad with a stored uniform, unlike setGradientValue). This is the fixedFluxPressure
20// semantics: an external caller (constrainPressure) sets refGrad each corrector so the
21// projection cancels the wall face flux; correctBoundaryCondition only re-derives the
22// boundary value from whatever refGrad currently holds.
23template<typename ValueType>
25 Field<ValueType>& domainVector,
26 const UnstructuredMesh& mesh,
27 std::pair<localIdx, localIdx> range
28)
29{
30 const auto iVector = domainVector.internalVector().view();
31
32 auto [refGradient, value, valueFraction, refValue, boundaryFaceOwners, deltaCoeffs] = views(
33 domainVector.boundaryData().refGrad(),
34 domainVector.boundaryData().value(),
35 domainVector.boundaryData().valueFraction(),
36 domainVector.boundaryData().refValue(),
37 mesh.boundaryMesh().faceOwners(),
39 );
40
42 domainVector.exec(),
43 range,
44 NEON_LAMBDA(const localIdx i) {
45 // reads (does not write) refGradient[i], set externally by constrainPressure
46 value[i] = iVector[boundaryFaceOwners[i]] + refGradient[i] * (1 / deltaCoeffs[i]);
47 valueFraction[i] = 0.0; // only use refGrad
48 refValue[i] = zero<ValueType>(); // not used
49 },
50 "applyFixedFluxPressure"
51 );
52}
53}
54
55/* @brief Fixed-flux pressure wall boundary condition.
56 *
57 * The per-face gradient (refGrad) is set EXTERNALLY (by NeoFOAM::constrainPressure) so
58 * that the pressure projection cancels
59 * the prescribed boundary face flux; correctBoundaryCondition only recomputes the boundary
60 * value from the current refGrad, and never clobbers it with a stored uniform. refGrad is
61 * zero-initialised by the boundary-data allocation, so the BC behaves as zeroGradient until
62 * the first constrainPressure call.
63 */
64template<typename ValueType>
66 public VolumeBoundaryFactory<ValueType>::template Register<FixedFluxPressure<ValueType>>
67{
69
70public:
71
72 using Base::correctBoundaryCondition;
73
75 : Base(mesh, {}, patchID, {.assignable = true, .fixesValue = false}), mesh_(mesh)
76 {}
77
78 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) final
79 {
80 detail::applyFixedFluxPressure(domainVector, mesh_, this->range());
81 }
82
83 static std::string name() { return "fixedFluxPressure"; }
84
85 std::string getName() const override { return name(); }
86
87 static std::string doc()
88 {
89 return "Fixed-flux pressure wall BC (externally updatable per-face refGrad).";
90 }
91
92 static std::string schema() { return "none"; }
93
94 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
95 {
96 return std::make_unique<FixedFluxPressure>(*this);
97 }
98
99private:
100
101 const UnstructuredMesh& mesh_;
102};
103
104}
const scalarVector & deltaCoeffs() const
Get the field of delta coefficients.
const labelVector & faceOwners() const
Get the list of labels of owner cells of boundary faces.
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
const Vector< ValueType > & internalVector() const
Definition field.hpp:90
Represents an unstructured mesh in NeoN.
const BoundaryMesh & boundaryMesh() const
Get the boundary mesh.
virtual std::unique_ptr< VolumeBoundaryFactory< ValueType > > clone() const final
FixedFluxPressure(const UnstructuredMesh &mesh, const Dictionary &, localIdx patchID)
virtual void correctBoundaryCondition(Field< ValueType > &domainVector) final
A template class for registering derived classes with a base class.
void applyFixedFluxPressure(Field< ValueType > &domainVector, const UnstructuredMesh &mesh, std::pair< localIdx, localIdx > range)
int32_t localIdx
Definition label.hpp:50
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