NeoFOAM
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 NeoFOAM authors
3
4#pragma once
5
6#include <vector>
7
11
13{
14
25template<typename ValueType>
26class VolumeField : public GeometricFieldMixin<ValueType>
27{
28
29public:
30
31 using FieldValueType = ValueType;
32
33
43 const Executor& exec,
44 std::string name,
47 )
48 : GeometricFieldMixin<ValueType>(
49 exec,
50 name,
51 mesh,
52 DomainField<ValueType>(exec, mesh.nCells(), mesh.nBoundaryFaces(), mesh.nBoundaries())
53 ),
54 key(""), fieldCollectionName(""), boundaryConditions_(boundaryConditions),
55 db_(std::nullopt)
56 {}
57
58
69 const Executor& exec,
70 std::string name,
74 )
75 : GeometricFieldMixin<ValueType>(
76 exec,
77 name,
78 mesh,
79 DomainField<ValueType>(exec, internalField, mesh.nBoundaryFaces(), mesh.nBoundaries())
80 ),
81 key(""), fieldCollectionName(""), boundaryConditions_(boundaryConditions),
82 db_(std::nullopt)
83 {}
84
95 const Executor& exec,
96 std::string name,
99 const BoundaryFields<ValueType>& boundaryFields,
101 )
102 : GeometricFieldMixin<ValueType>(exec, name, mesh, internalField, boundaryFields), key(""),
103 fieldCollectionName(""), boundaryConditions_(boundaryConditions), db_(std::nullopt)
104 {}
105
119 const Executor& exec,
120 std::string fieldName,
121 const UnstructuredMesh& mesh,
124 Database& db,
125 std::string dbKey,
126 std::string collectionName
127 )
128 : GeometricFieldMixin<ValueType>(
129 exec,
130 fieldName,
131 mesh,
132 DomainField<ValueType>(exec, internalField, mesh.nBoundaryFaces(), mesh.nBoundaries())
133 ),
134 key(dbKey), fieldCollectionName(collectionName), boundaryConditions_(boundaryConditions),
135 db_(&db)
136 {}
137
139 : GeometricFieldMixin<ValueType>(other), key(other.key),
141 boundaryConditions_(other.boundaryConditions_), db_(other.db_)
142 {}
143
151 {
152 for (auto& boundaryCondition : boundaryConditions_)
153 {
154 boundaryCondition.correctBoundaryCondition(this->field_);
155 }
156 }
157
163 bool hasDatabase() const { return db_.has_value(); }
164
171 {
172 if (!db_.has_value())
173 {
174 throw std::runtime_error(
175 "Database not set: make sure the field is registered in the database"
176 );
177 }
178 return *db_.value();
179 }
180
186 const Database& db() const
187 {
188 if (!db_.has_value())
189 {
190 throw std::runtime_error(
191 "Database not set: make sure the field is registered in the database"
192 );
193 }
194 return *db_.value();
195 }
196
202 bool registered() const { return key != "" && fieldCollectionName != "" && db_.has_value(); }
203
204 std::vector<VolumeBoundary<ValueType>> boundaryConditions() const
205 {
206 return boundaryConditions_;
207 }
208
209 std::string key; // The key of the field in the database
210 std::string fieldCollectionName; // The name of the field collection in the database
211
212private:
213
214 std::vector<VolumeBoundary<ValueType>> boundaryConditions_; // The vector of boundary conditions
215 std::optional<Database*> db_; // The optional pointer to the database
216};
217
218} // namespace NeoFOAM
Represents the boundary fields for a computational domain.
Represents the domain fields for a computational domain.
A class to contain the data and executors for a field and define some basic operations.
Definition field.hpp:49
Represents an unstructured mesh in NeoFOAM.
This class represents a mixin for a geometric field.
const UnstructuredMesh & mesh() const
Returns a const reference to the unstructured mesh object.
const Executor & exec() const
Returns a const reference to the executor object.
const Field< ValueType > & internalField() const
Returns a const reference to the internal field.
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 Field< ValueType > &internalField, const BoundaryFields< ValueType > &boundaryFields, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions)
Constructor for a VolumeField with a given internal and boundary field.
Database & db()
Retrieves the database.
bool hasDatabase() const
Returns true if the field has a database, false otherwise.
const Database & db() const
Retrieves the database.
void correctBoundaryConditions()
Corrects the boundary conditions of the surface field.
VolumeField(const Executor &exec, std::string name, const UnstructuredMesh &mesh, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions)
Constructor for a uninitialized VolumeField.
std::vector< VolumeBoundary< ValueType > > boundaryConditions() const
bool registered() const
Returns true if the field is registered in the database, false otherwise.
VolumeField(const Executor &exec, std::string fieldName, const UnstructuredMesh &mesh, const Field< ValueType > &internalField, 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 Field< ValueType > &internalField, const std::vector< VolumeBoundary< ValueType > > &boundaryConditions)
Constructor for a VolumeField with a given internal field.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16