NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
boundaryData.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2024 NeoN authors
3#pragma once
4
5#include <Kokkos_Core.hpp>
6
7
11#include "NeoN/core/vector.hpp"
12
13#include <vector>
14#include <utility>
15
16namespace NeoN
17{
18
19
31template<typename T>
33{
34
35public:
36
42 : exec_(rhs.exec_), value_(rhs.value_), refValue_(rhs.refValue_),
43 valueFraction_(rhs.valueFraction_), refGrad_(rhs.refGrad_),
44 boundaryTypes_(rhs.boundaryTypes_), offset_(rhs.offset_), nBoundaries_(rhs.nBoundaries_),
45 nBoundaryFaces_(rhs.nBoundaryFaces_)
46 {}
47
48
54 : exec_(rhs.exec_), value_(exec, rhs.value_), refValue_(exec, rhs.refValue_),
55 valueFraction_(exec, rhs.valueFraction_), refGrad_(exec, rhs.refGrad_),
56 boundaryTypes_(exec, rhs.boundaryTypes_), offset_(exec, rhs.offset_),
57 nBoundaries_(rhs.nBoundaries_), nBoundaryFaces_(rhs.nBoundaryFaces_)
58 {}
59
60
68 : exec_(exec), value_(exec, nBoundaryFaces), refValue_(exec, nBoundaryFaces),
69 valueFraction_(exec, nBoundaryFaces), refGrad_(exec, nBoundaryFaces),
70 boundaryTypes_(exec, nBoundaryTypes), offset_(exec, nBoundaryTypes + 1),
71 nBoundaries_(nBoundaryTypes), nBoundaryFaces_(nBoundaryFaces)
72 {}
73
80 BoundaryData(const Executor& exec, const std::vector<localIdx>& offsets)
81 : BoundaryData(exec, offsets.back(), static_cast<localIdx>(offsets.size() - 1))
82 {
83 offset_ = Vector(exec, offsets);
84 }
85
86
88 const Vector<T>& value() const { return value_; }
89
95 Vector<T>& value() { return value_; }
96
98 const Vector<T>& refValue() const { return refValue_; }
99
104 Vector<T>& refValue() { return refValue_; }
105
107 const Vector<scalar>& valueFraction() const { return valueFraction_; }
108
113 Vector<scalar>& valueFraction() { return valueFraction_; }
114
116 const Vector<T>& refGrad() const { return refGrad_; }
117
122 Vector<T>& refGrad() { return refGrad_; }
123
128 const Vector<int>& boundaryTypes() const { return boundaryTypes_; }
129
134 const Vector<localIdx>& offset() const { return offset_; }
135
140 localIdx nBoundaries() const { return nBoundaries_; }
141
146 localIdx nBoundaryFaces() const { return nBoundaryFaces_; }
147
148 const Executor& exec() { return exec_; }
149
151 {
152
153 // TODO maybe dont overwrite nBoundaries and nBoundaryFaces
154 // but use them for a sanity check
155 nBoundaries_ = rhs.nBoundaries_;
156 nBoundaryFaces_ = rhs.nBoundaryFaces_;
157
158 value_ = rhs.value_;
159 refValue_ = rhs.refValue_;
160 valueFraction_ = rhs.valueFraction_;
161 refGrad_ = rhs.refGrad_;
162 boundaryTypes_ = rhs.boundaryTypes_;
163 offset_ = rhs.offset_;
164 return *this;
165 }
166
168 {
169
170 // TODO maybe dont overwrite nBoundaries and nBoundaryFaces
171 // but use them for a sanity check
172 nBoundaries_ = rhs.nBoundaries_;
173 nBoundaryFaces_ = rhs.nBoundaryFaces_;
174
175 value_ = std::move(rhs.value_);
176 refValue_ = std::move(rhs.refValue_);
177 valueFraction_ = std::move(rhs.valueFraction_);
178 refGrad_ = std::move(rhs.refGrad_);
179 boundaryTypes_ = std::move(rhs.boundaryTypes_);
180 offset_ = std::move(rhs.offset_);
181 return *this;
182 }
183
188 std::pair<localIdx, localIdx> range(localIdx patchId) const
189 {
190 return {offset_.data()[patchId], offset_.data()[patchId + 1]};
191 }
192
193private:
194
195 Executor exec_;
196 Vector<T> value_;
198 Vector<T> refValue_;
199 Vector<scalar> valueFraction_;
201 Vector<T> refGrad_;
202 Vector<int> boundaryTypes_;
203 Vector<localIdx> offset_;
204 localIdx nBoundaries_;
205 localIdx nBoundaryFaces_;
206};
207
208}
Represents the boundary fields for a computational domain.
Vector< T > & refValue()
Get the view storing the Dirichlet boundary values.
const Vector< T > & refGrad() const
Get the view storing the Neumann boundary values.
BoundaryData(const BoundaryData< T > &rhs)
Copy constructor.
BoundaryData(const Executor &exec, localIdx nBoundaryFaces, localIdx nBoundaryTypes)
constructor with default initialized Vectors from sizes.
Vector< T > & refGrad()
Get the view storing the Neumann boundary values.
Vector< scalar > & valueFraction()
Get the view storing the fraction of the boundary value.
localIdx nBoundaries() const
Get the number of boundaries.
std::pair< localIdx, localIdx > range(localIdx patchId) const
Get the range for a given patchId.
BoundaryData(const Executor &exec, const BoundaryData< T > &rhs)
Copy constructor.
const Vector< int > & boundaryTypes() const
Get the view storing the boundary types.
BoundaryData< T > & operator=(const BoundaryData< T > &rhs)
const Vector< localIdx > & offset() const
Get the view storing the offsets of each boundary.
BoundaryData(const Executor &exec, const std::vector< localIdx > &offsets)
constructor from a given offsets vector @warn all members except offsets are default constructed
const Executor & exec()
const Vector< T > & refValue() const
Get the view storing the Dirichlet boundary values.
BoundaryData< T > & operator=(const BoundaryData< T > &&rhs)
const Vector< T > & value() const
Get the view storing the computed values from the boundary condition.
localIdx nBoundaryFaces() const
Get the number of boundary faces.
Vector< T > & value()
Get the view storing the computed values from the boundary condition.
const Vector< scalar > & valueFraction() const
Get the view storing the fraction of the boundary value.
A class to contain the data and executors for a field and define some basic operations.
Definition vector.hpp:53
ValueType * data()
Direct access to the underlying field data.
Definition vector.hpp:346
int32_t localIdx
Definition label.hpp:30
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16