NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
volumeField.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2024 NeoN authors
3
4#pragma once
5
9
10#include <vector>
11
13{
14
25template<typename ValueType>
26class VolumeField : public DomainMixin<ValueType>
27{
28
29public:
30
31 using VectorValueType = ValueType;
32
33
43 const Executor& exec,
44 std::string name,
47 )
48 : DomainMixin<ValueType>(
49 exec, name, mesh, Field<ValueType>(exec, mesh.nCells(), mesh.boundaryMesh().offset())
50 ),
51 key(""), fieldCollectionName(""), boundaryConditions_(boundaryConditions),
52 db_(std::nullopt)
53 {}
54
55
66 const Executor& exec,
67 std::string name,
71 )
72 : DomainMixin<ValueType>(
73 exec, name, mesh, Field<ValueType>(exec, internalVector, mesh.boundaryMesh().offset())
74 ),
75 key(""), fieldCollectionName(""), boundaryConditions_(boundaryConditions),
76 db_(std::nullopt)
77 {}
78
89 const Executor& exec,
90 std::string name,
93 const BoundaryData<ValueType>& boundaryVectors,
95 )
96 : DomainMixin<ValueType>(exec, name, mesh, internalVector, boundaryVectors), key(""),
97 fieldCollectionName(""), boundaryConditions_(boundaryConditions), db_(std::nullopt)
98 {}
99
113 const Executor& exec,
114 std::string fieldName,
115 const UnstructuredMesh& mesh,
116 const Field<ValueType>& domainVector,
118 Database& db,
119 std::string dbKey,
120 std::string collectionName
121 )
122 : DomainMixin<ValueType>(exec, fieldName, mesh, domainVector), key(dbKey),
123 fieldCollectionName(collectionName), boundaryConditions_(boundaryConditions), db_(&db)
124 {}
125
127 : DomainMixin<ValueType>(other), key(other.key),
129 boundaryConditions_(other.boundaryConditions_), db_(other.db_)
130 {}
131
139 {
140 for (auto& boundaryCondition : boundaryConditions_)
141 {
142 boundaryCondition.correctBoundaryCondition(this->field_);
143 }
144 }
145
151 bool hasDatabase() const { return db_.has_value(); }
152
159 {
160 if (!db_.has_value())
161 {
162 throw std::runtime_error {
163 "Database not set: make sure the field is registered in the database"
164 };
165 }
166 return *db_.value();
167 }
168
174 const Database& db() const
175 {
176 if (!db_.has_value())
177 {
178 throw std::runtime_error(
179 "Database not set: make sure the field is registered in the database"
180 );
181 }
182 return *db_.value();
183 }
184
190 bool registered() const { return key != "" && fieldCollectionName != "" && db_.has_value(); }
191
192 std::vector<VolumeBoundary<ValueType>> boundaryConditions() const
193 {
194 return boundaryConditions_;
195 }
196
197 std::string key; // The key of the field in the database
198 std::string fieldCollectionName; // The name of the field collection in the database
199
200private:
201
202 std::vector<VolumeBoundary<ValueType>> boundaryConditions_; // The vector of boundary conditions
203 std::optional<Database*> db_; // The optional pointer to the database
204};
205
206} // 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:53
This class represents a mixin for a geometric field.
Definition domain.hpp:27
const UnstructuredMesh & mesh() const
Returns a const reference to the unstructured mesh object.
Definition domain.hpp:121
const Executor & exec() const
Returns a const reference to the executor object.
Definition domain.hpp:114
const Vector< ValueType > & internalVector() const
Returns a const reference to the internal field.
Definition domain.hpp:79
Represents a volume boundary field for a cell-centered finite volume method.
Represents a volume field in a finite volume method.
Database & db()
Retrieves the database.
VolumeField(const Executor &exec, std::string name, const UnstructuredMesh &mesh, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions)
Constructor for a uninitialized VolumeField.
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.
const Database & db() const
Retrieves the database.
bool hasDatabase() const
Returns true if the field has a database, false otherwise.
void correctBoundaryConditions()
Corrects the boundary conditions of the surface field.
bool registered() const
Returns true if the field is registered in the database, false otherwise.
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.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16