NeoN
A framework for CFD software
Loading...
Searching...
No Matches
surfaceField.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 - 2026 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <vector>
12
14{
15
26template<typename ValueType>
27class SurfaceField : public DomainMixin<ValueType>, public FieldDatabaseMixin
28{
29
30public:
31
32 using VectorValueType = ValueType;
33
43 const Executor& exec,
44 std::string fieldName,
47 )
48 : DomainMixin<ValueType>(
49 exec,
50 fieldName,
51 mesh,
52 Field<ValueType>(exec, mesh.nInternalFaces(), mesh.boundaryMesh().offset())
53 ),
54 FieldDatabaseMixin(), boundaryConditions_(boundaryConditions)
55 {}
56
57 /* @brief Constructor for a surfaceVector with a given internal field
58 *
59 * @param exec The executor
60 * @param mesh The underlying mesh
61 * @param internalVector the underlying internal field
62 * @param boundaryConditions a vector of boundary conditions
63 */
65 const Executor& exec,
67 const Field<ValueType>& domainVector,
69 )
70 : DomainMixin<ValueType>(exec, mesh, domainVector), FieldDatabaseMixin(),
71 boundaryConditions_(boundaryConditions)
72 {}
73
74 /* @brief Constructor for a surfaceVector with a given internal field
75 *
76 * @param exec The executor
77 * @param mesh The underlying mesh
78 * @param internalVector the underlying internal field
79 * @param boundaryVectors the underlying boundary data fields
80 * @param boundaryConditions a vector of boundary conditions
81 */
83 const Executor& exec,
86 const BoundaryData<ValueType>& boundaryVectors,
88 )
89 : DomainMixin<ValueType>(exec, mesh, {exec, mesh, internalVector, boundaryVectors}),
90 FieldDatabaseMixin(), boundaryConditions_(boundaryConditions)
91 {}
92
93 /* @brief Constructor for a surface field with a given internal field and database registration.
94 *
95 * Mirrors the VolumeField db-registering constructor.
96 *
97 * @param exec The executor
98 * @param fieldName The name of the field
99 * @param mesh The underlying mesh
100 * @param domainVector the underlying domain field (internal + boundary laid out as Field)
101 * @param boundaryConditions a vector of boundary conditions
102 * @param db The database to register with
103 * @param dbKey The key of the field in the database
104 * @param collectionName The name of the field collection in the database
105 */
107 const Executor& exec,
108 std::string fieldName,
109 const UnstructuredMesh& mesh,
110 const Field<ValueType>& domainVector,
112 Database& db,
113 std::string dbKey,
114 std::string collectionName
115 )
116 : DomainMixin<ValueType>(exec, fieldName, mesh, domainVector),
117 FieldDatabaseMixin(db, std::move(dbKey), std::move(collectionName)),
118 boundaryConditions_(boundaryConditions)
119 {}
120
127 : DomainMixin<ValueType>(other), FieldDatabaseMixin(other),
128 boundaryConditions_(other.boundaryConditions_)
129 {}
130
138 {
139 // One-time set() pass: initialise constant patch data once per field instance (e.g. the
140 // processor BC's unused mixed-BC coefficients).
141 if (!boundaryConditionsSet_)
142 {
143 for (auto& boundaryCondition : boundaryConditions_)
144 {
145 boundaryCondition.set(this->field_);
146 }
147 boundaryConditionsSet_ = true;
148 }
149 // Per-iteration update(): proc patches post their (already face-valued) data without
150 // draining, so all are in flight before any completes.
151 for (auto& boundaryCondition : boundaryConditions_)
152 {
153 boundaryCondition.update(this->field_);
154 }
155 // Drain any processor-halo exchange once, after all proc patches have posted. See
156 // VolumeField::correctBoundaryConditions for the rationale (batched post-then-wait).
157 this->field_.boundaryData().waitAll();
158 }
159
160 std::vector<SurfaceBoundary<ValueType>> boundaryConditions() const
161 {
162 return boundaryConditions_;
163 }
164
165private:
166
167 std::vector<SurfaceBoundary<ValueType>>
168 boundaryConditions_; // The vector of boundary conditions
169 std::optional<Database*> db_; // The optional pointer to the database
170
171 // Whether the one-time boundary set() pass has run for this field instance. Default-init to
172 // false so copies re-run set() on their first correctBoundaryConditions() call.
173 bool boundaryConditionsSet_ {false};
174};
175
176inline SurfaceField<scalar>
178{
179 SurfaceField<scalar> result(lhs);
180 result.internalVector() *= rhs.internalVector();
181 result.boundaryData().value() *= rhs.boundaryData().value();
182 return result;
183}
184
185inline SurfaceField<scalar>
187{
188 SurfaceField<scalar> result(lhs);
189 result.internalVector() += rhs.internalVector();
190 result.boundaryData().value() += rhs.boundaryData().value();
191 return result;
192}
193
194inline SurfaceField<scalar>
196{
197 SurfaceField<scalar> result(lhs);
198 result.internalVector() -= rhs.internalVector();
199 result.boundaryData().value() -= rhs.boundaryData().value();
200 return result;
201}
202
204{
205 SurfaceField<scalar> result(fld);
206 result.internalVector() *= s;
207 result.boundaryData().value() *= s;
208 return result;
209}
210
211} // namespace NeoN
Represents the boundary fields for a computational domain.
Represents the domain fields for a computational domain.
Definition field.hpp:34
Represents an unstructured mesh in NeoN.
A class to contain the data and executors for a field and define some basic operations.
Definition vector.hpp:27
This class represents a mixin for a geometric field.
Definition domain.hpp:28
const UnstructuredMesh & mesh() const
Returns a const reference to the unstructured mesh object.
Definition domain.hpp:122
const BoundaryData< ValueType > & boundaryData() const
Returns a const reference to the boundary field.
Definition domain.hpp:101
const Executor & exec() const
Returns a const reference to the executor object.
Definition domain.hpp:115
const Vector< ValueType > & internalVector() const
Returns a const reference to the internal field.
Definition domain.hpp:80
Mixin for database registration for fields (volume/surface).
Represents a surface boundary field for a cell-centered finite volume method.
Represents a surface field in a finite volume method.
SurfaceField(const Executor &exec, std::string fieldName, const UnstructuredMesh &mesh, const Field< ValueType > &domainVector, const std::vector< SurfaceBoundary< ValueType > > &boundaryConditions, Database &db, std::string dbKey, std::string collectionName)
std::vector< SurfaceBoundary< ValueType > > boundaryConditions() const
SurfaceField(const Executor &exec, std::string fieldName, const UnstructuredMesh &mesh, const std::vector< SurfaceBoundary< ValueType > > &boundaryConditions)
Constructor for a surfaceVector with a given name and mesh.
SurfaceField(const SurfaceField &other)
Copy constructor for a surface field.
SurfaceField(const Executor &exec, const UnstructuredMesh &mesh, const Field< ValueType > &domainVector, const std::vector< SurfaceBoundary< ValueType > > &boundaryConditions)
void correctBoundaryConditions()
Corrects the boundary conditions of the surface field.
SurfaceField(const Executor &exec, const UnstructuredMesh &mesh, const Vector< ValueType > &internalVector, const BoundaryData< ValueType > &boundaryVectors, const std::vector< SurfaceBoundary< ValueType > > &boundaryConditions)
SurfaceField< scalar > operator+(const SurfaceField< scalar > &lhs, const SurfaceField< scalar > &rhs)
SurfaceField< scalar > operator-(const SurfaceField< scalar > &lhs, const SurfaceField< scalar > &rhs)
SurfaceField< scalar > operator*(const SurfaceField< scalar > &lhs, const SurfaceField< scalar > &rhs)
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:20
float scalar
Definition scalar.hpp:17