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 const Field<ValueType>& domainVector,
107 Database& db,
108 std::string dbKey,
109 std::string collectionName
110 );
111
113
114 VolumeField<ValueType>& operator-=(const ValueType rhs);
115
116 VolumeField<ValueType>& operator+=(const ValueType rhs);
117
125
127
128 std::vector<VolumeBoundary<ValueType>> boundaryConditions() const
129 {
130 return boundaryConditions_;
131 }
132
133private:
134
135 std::vector<VolumeBoundary<ValueType>> boundaryConditions_; // The vector of boundary conditions
136 std::optional<Database*> db_; // The optional pointer to the database
137
138 // Whether the one-time boundary set() pass has run for this field instance. Reset to false
139 // for copies (default member init below) so a copied field re-runs set() on its first
140 // correctBoundaryConditions() call.
141 bool boundaryConditionsSet_ {false};
142};
143
144// Deliberately not called ``detail``: an inner ``detail`` here would shadow
145// ``NeoN::detail`` for every unqualified lookup inside this namespace, which
146// breaks divOperator/laplacianOperator's ``detail::RefHolder``.
147namespace volumeFieldDetail
148{
149
151inline void crossInto(const Executor& exec, Vector<Vec3>& target, const Vector<Vec3>& other)
152{
153 auto out = target.view();
154 auto rhs = other.view();
156 exec,
157 {0, out.size()},
158 KOKKOS_LAMBDA(const localIdx i) { out[i] = out[i] ^ rhs[i]; },
159 "vec3FieldCross"
160 );
161}
162
163} // namespace volumeFieldDetail
164
173{
174 VolumeField<Vec3> result(lhs);
175 volumeFieldDetail::crossInto(result.exec(), result.internalVector(), rhs.internalVector());
176 volumeFieldDetail::crossInto(
177 result.exec(), result.boundaryData().value(), rhs.boundaryData().value()
178 );
179 return result;
180}
181
182} // 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
View< ValueType > view() &&=delete
Carries named field references for context-aware boundary conditions.
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 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< ValueType > & operator+=(const ValueType rhs)
void correctBoundaryConditions()
Corrects the boundary conditions of the surface field.
std::vector< VolumeBoundary< ValueType > > boundaryConditions() const
VolumeField(const Executor &exec, std::string fieldName, const UnstructuredMesh &mesh, const 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 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, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions)
Constructor for a uninitialized VolumeField.
VolumeField< Vec3 > cross(const VolumeField< Vec3 > &lhs, const VolumeField< Vec3 > &rhs)
Element-wise cross product of two Vec3 volume fields.
int32_t localIdx
Definition label.hpp:50
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:20
void parallelFor(const ExecutorType &, std::pair< localIdx, localIdx > range, const Kernel &kernel, std::string name)