NeoN
A framework for CFD software
Loading...
Searching...
No Matches
volumeField.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
13
14#include <vector>
15
17{
18
29template<typename ValueType>
30class VolumeField : public DomainMixin<ValueType>, public FieldDatabaseMixin
31{
32
33public:
34
35 using VectorValueType = ValueType;
36
37
47 const Executor& exec,
48 std::string fieldName,
51 );
52
53
64 const Executor& exec,
65 std::string name,
69 );
70
81 const Executor& exec,
82 std::string name,
85 const BoundaryData<ValueType>& boundaryVectors,
87 );
88
102 const Executor& exec,
103 std::string fieldName,
104 const UnstructuredMesh& mesh,
105 Field<ValueType> domainVector,
107 Database& db,
108 std::string dbKey,
109 std::string collectionName
110 );
111
113
119
120 VolumeField<ValueType>& operator-=(const ValueType rhs);
121
122 VolumeField<ValueType>& operator+=(const ValueType rhs);
123
131
133
134 std::vector<VolumeBoundary<ValueType>> boundaryConditions() const
135 {
136 return boundaryConditions_;
137 }
138
139private:
140
141 std::vector<VolumeBoundary<ValueType>> boundaryConditions_; // The vector of boundary conditions
142 std::optional<Database*> db_; // The optional pointer to the database
143
144 // Whether the one-time boundary set() pass has run for this field instance. Reset to false
145 // for copies (default member init below) so a copied field re-runs set() on its first
146 // correctBoundaryConditions() call.
147 bool boundaryConditionsSet_ {false};
148};
149
150// Deliberately not called ``detail``: an inner ``detail`` here would shadow
151// ``NeoN::detail`` for every unqualified lookup inside this namespace, which
152// breaks divOperator/laplacianOperator's ``detail::RefHolder``.
154{
155
157inline void crossInto(const Executor& exec, Vector<Vec3>& target, const Vector<Vec3>& other)
158{
159 auto out = target.view();
160 auto rhs = other.view();
162 exec,
163 {0, out.size()},
164 KOKKOS_LAMBDA(const localIdx i) { out[i] = out[i] ^ rhs[i]; },
165 "vec3FieldCross"
166 );
167}
168
169} // namespace volumeFieldDetail
170
179{
180 VolumeField<Vec3> result(lhs);
183 result.exec(), result.boundaryData().value(), rhs.boundaryData().value()
184 );
185 return result;
186}
187
188} // 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.
An executor-aware contiguous container for numerical data with vector-style arithmetic semantics.
Definition vector.hpp:40
View< ValueType > view() &&=delete
Prevents creating a View from a temporary Vector.
Carries named field references for context-aware boundary conditions.
DomainMixin(const Executor &exec, std::string fieldName, const UnstructuredMesh &mesh, Field< ValueType > field)
Constructor for DomainMixin.
Definition domain.hpp:44
const UnstructuredMesh & mesh() const
Returns a const reference to the unstructured mesh object.
Definition domain.hpp:124
const BoundaryData< ValueType > & boundaryData() const
Returns a const reference to the boundary field.
Definition domain.hpp:103
const Executor & exec() const
Returns a const reference to the executor object.
Definition domain.hpp:117
const Vector< ValueType > & internalVector() const
Returns a const reference to the internal field.
Definition domain.hpp:82
Represents a volume boundary field for a cell-centered finite volume method.
Represents a volume field in a finite volume method.
VolumeField(const Executor &exec, std::string name, const UnstructuredMesh &mesh, const Vector< ValueType > &internalVector, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions)
Constructor for a VolumeField with a given internal field.
VolumeField(VolumeField &&other)
Move constructor. Without it, moving a VolumeField would copy its data, since the user-declared copy ...
VolumeField< ValueType > & operator+=(const ValueType rhs)
void correctBoundaryConditions()
Corrects the boundary conditions of the surface field.
std::vector< VolumeBoundary< Vec3 > > boundaryConditions() const
VolumeField(const Executor &exec, std::string name, const UnstructuredMesh &mesh, const Vector< ValueType > &internalVector, const BoundaryData< ValueType > &boundaryVectors, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions)
Constructor for a VolumeField with a given internal and boundary field.
VolumeField< ValueType > & operator-=(const ValueType rhs)
void correctBoundaryConditions(const BoundaryContext &ctx)
VolumeField(const Executor &exec, std::string fieldName, const UnstructuredMesh &mesh, Field< ValueType > domainVector, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions, Database &db, std::string dbKey, std::string collectionName)
Constructor for a VolumeField with a given internal field and database.
VolumeField(const Executor &exec, std::string fieldName, const UnstructuredMesh &mesh, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions)
Constructor for a uninitialized VolumeField.
void crossInto(const Executor &exec, Vector< Vec3 > &target, const Vector< Vec3 > &other)
in-place element-wise cross product, target = target ^ other
VolumeField< Vec3 > cross(const VolumeField< Vec3 > &lhs, const VolumeField< Vec3 > &rhs)
Element-wise cross product of two Vec3 volume fields.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:21
void parallelFor(const ExecutorType &, std::pair< localIdx, localIdx > range, const Kernel &kernel, std::string name)
int32_t localIdx
Definition label.hpp:50