NeoN
A framework for CFD software
Loading...
Searching...
No Matches
processor.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{
16
17namespace detail
18{
19// One-time (set): zero the unused mixed-BC coefficients (refGrad / valueFraction / refValue) on
20// the processor patch. These are constant for the lifetime of the field, so this runs once.
21template<typename ValueType>
23 Field<ValueType>& domainVector, std::pair<localIdx, localIdx> range
24);
25
26// Per-iteration (update): seed the proc-patch ghost with the owner-cell value
27// (value[i] = internalVector[faceCells[i]]) so it can be shipped to the neighbour rank.
28template<typename ValueType>
30 Field<ValueType>& domainVector,
31 const UnstructuredMesh& mesh,
32 std::pair<localIdx, localIdx> range
33);
34
35extern template void
36setProcBoundaryCoefficients<scalar>(Field<scalar>&, std::pair<localIdx, localIdx>);
37extern template void setProcBoundaryCoefficients<Vec3>(Field<Vec3>&, std::pair<localIdx, localIdx>);
38extern template void
39setProcBoundaryCoefficients<Tensor>(Field<Tensor>&, std::pair<localIdx, localIdx>);
40
41extern template void updateProcBoundaryOwnerValue<
42 scalar>(Field<scalar>&, const UnstructuredMesh&, std::pair<localIdx, localIdx>);
43extern template void updateProcBoundaryOwnerValue<
44 Vec3>(Field<Vec3>&, const UnstructuredMesh&, std::pair<localIdx, localIdx>);
45extern template void updateProcBoundaryOwnerValue<
46 Tensor>(Field<Tensor>&, const UnstructuredMesh&, std::pair<localIdx, localIdx>);
47}
48
49template<typename ValueType>
50class Processor : public VolumeBoundaryFactory<ValueType>::template Register<Processor<ValueType>>
51{
53
54public:
55
57
58 Processor(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
59 : Base(mesh, dict, patchID, {.assignable = true, .fixesValue = false}), mesh_(mesh)
60 {}
61
62 // One-time initialisation: the unused mixed-BC coefficients never change after construction.
63 virtual void set(Field<ValueType>& domainVector) final
64 {
65 detail::setProcBoundaryCoefficients(domainVector, this->range());
66 }
67
68 // Per iteration: re-seed the owner value into the proc-patch ghost and post the halo exchange.
69 virtual void update([[maybe_unused]] Field<ValueType>& domainVector) final
70 {
71 detail::updateProcBoundaryOwnerValue(domainVector, mesh_, this->range());
72#ifdef NF_WITH_MPI_SUPPORT
73 fence(domainVector.exec());
74 const int neighborRank =
75 static_cast<int>(mesh_.boundaryMesh().neighbourRankForRange(this->range()));
76 domainVector.boundaryData().communicate(this->range(), neighborRank);
77#endif
78 }
79
80 // Full correction = one-time set() + per-iteration update(). Kept for the BoundaryContext
81 // path and any direct caller; the field's correctBoundaryConditions() calls set()/update()
82 // separately so the coefficient kernel runs only once.
83 virtual void correctBoundaryCondition([[maybe_unused]] Field<ValueType>& domainVector) final
84 {
85 set(domainVector);
86 update(domainVector);
87 }
88
89 static std::string name() { return "processor"; }
90
91 static std::string doc()
92 {
93 return "Set processor boundary values from the corresponding processor-neighbour data.";
94 }
95
96 static std::string schema() { return "none"; }
97
98 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
99 {
100 return std::make_unique<Processor>(*this);
101 }
102
103 std::string getName() const override { return name(); }
104
105
106private:
107
108 const UnstructuredMesh& mesh_;
109};
110}
localIdx neighbourRankForRange(std::pair< localIdx, localIdx > range) const
Returns the neighbour rank for the processor patch whose face range matches the given range.
A class representing a dictionary that stores key-value pairs.
Represents the domain fields for a computational domain.
Definition field.hpp:34
A class for the representation of a 3x3 tensor.
Definition tensor.hpp:26
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
virtual std::unique_ptr< VolumeBoundaryFactory< ValueType > > clone() const final
Definition processor.hpp:98
virtual void update(Field< ValueType > &domainVector) final
Definition processor.hpp:69
Processor(const UnstructuredMesh &mesh, const Dictionary &dict, localIdx patchID)
Definition processor.hpp:58
virtual void correctBoundaryCondition(Field< ValueType > &domainVector) final
Definition processor.hpp:83
virtual void set(Field< ValueType > &domainVector) final
Definition processor.hpp:63
A template class for registering derived classes with a base class.
void updateProcBoundaryOwnerValue(Field< ValueType > &domainVector, const UnstructuredMesh &mesh, std::pair< localIdx, localIdx > range)
template void setProcBoundaryCoefficients< Vec3 >(Field< Vec3 > &, std::pair< localIdx, localIdx >)
void setProcBoundaryCoefficients(Field< ValueType > &domainVector, std::pair< localIdx, localIdx > range)
template void setProcBoundaryCoefficients< scalar >(Field< scalar > &, std::pair< localIdx, localIdx >)
template void setProcBoundaryCoefficients< Tensor >(Field< Tensor > &, std::pair< localIdx, localIdx >)
void fence(const Executor &exec)
Definition executor.hpp:23
int32_t localIdx
Definition label.hpp:50
float scalar
Definition scalar.hpp:17