NeoN
A framework for CFD software
Loading...
Searching...
No Matches
boundaryData.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <Kokkos_Core.hpp>
8
9
14
15#include <vector>
16#include <utility>
17
18namespace NeoN
19{
20
21
33template<typename T>
35{
36
37public:
38
44 : exec_(rhs.exec_), value_(rhs.value_), refValue_(rhs.refValue_),
45 valueFraction_(rhs.valueFraction_), refGrad_(rhs.refGrad_),
46 boundaryTypes_(rhs.boundaryTypes_), offset_(rhs.offset_), nBoundaries_(rhs.nBoundaries_),
47 nBoundaryFaces_(rhs.nBoundaryFaces_)
48 {}
49
50
56 : exec_(rhs.exec_), value_(exec, rhs.value_), refValue_(exec, rhs.refValue_),
57 valueFraction_(exec, rhs.valueFraction_), refGrad_(exec, rhs.refGrad_),
58 boundaryTypes_(exec, rhs.boundaryTypes_), offset_(SerialExecutor {}, rhs.offset_),
59 nBoundaries_(rhs.nBoundaries_), nBoundaryFaces_(rhs.nBoundaryFaces_)
60 {}
61
62
70 : exec_(exec), value_(exec, nBoundaryFaces), refValue_(exec, nBoundaryFaces),
71 valueFraction_(exec, nBoundaryFaces), refGrad_(exec, nBoundaryFaces),
72 boundaryTypes_(exec, nBoundaryTypes), offset_(SerialExecutor {}, nBoundaryTypes + 1),
73 nBoundaries_(nBoundaryTypes), nBoundaryFaces_(nBoundaryFaces)
74 {}
75
82 BoundaryData(const Executor& exec, const std::vector<localIdx>& offsets)
83 : BoundaryData(exec, offsets.back(), static_cast<localIdx>(offsets.size() - 1))
84 {
85 offset_ = Vector(SerialExecutor {}, offsets);
86 }
87
88
90 const Vector<T>& value() const { return value_; }
91
97 Vector<T>& value() { return value_; }
98
100 const Vector<T>& refValue() const { return refValue_; }
101
106 Vector<T>& refValue() { return refValue_; }
107
109 const Vector<scalar>& valueFraction() const { return valueFraction_; }
110
115 Vector<scalar>& valueFraction() { return valueFraction_; }
116
118 const Vector<T>& refGrad() const { return refGrad_; }
119
124 Vector<T>& refGrad() { return refGrad_; }
125
130 const Vector<int>& boundaryTypes() const { return boundaryTypes_; }
131
136 const Vector<localIdx>& offset() const { return offset_; }
137
142 localIdx nBoundaries() const { return nBoundaries_; }
143
148 localIdx nBoundaryFaces() const { return nBoundaryFaces_; }
149
155 {
156 return offset_.data()[patchId + 1] - offset_.data()[patchId];
157 }
158
159 const Executor& exec() { return exec_; }
160
162 {
163
164 // TODO maybe dont overwrite nBoundaries and nBoundaryFaces
165 // but use them for a sanity check
166 nBoundaries_ = rhs.nBoundaries_;
167 nBoundaryFaces_ = rhs.nBoundaryFaces_;
168
169 value_ = rhs.value_;
170 refValue_ = rhs.refValue_;
171 valueFraction_ = rhs.valueFraction_;
172 refGrad_ = rhs.refGrad_;
173 boundaryTypes_ = rhs.boundaryTypes_;
174 offset_ = rhs.offset_;
175 return *this;
176 }
177
179 {
180
181 // TODO maybe dont overwrite nBoundaries and nBoundaryFaces
182 // but use them for a sanity check
183 nBoundaries_ = rhs.nBoundaries_;
184 nBoundaryFaces_ = rhs.nBoundaryFaces_;
185
186 value_ = std::move(rhs.value_);
187 refValue_ = std::move(rhs.refValue_);
188 valueFraction_ = std::move(rhs.valueFraction_);
189 refGrad_ = std::move(rhs.refGrad_);
190 boundaryTypes_ = std::move(rhs.boundaryTypes_);
191 offset_ = std::move(rhs.offset_);
192 return *this;
193 }
194
199 std::pair<localIdx, localIdx> range(localIdx patchId) const
200 {
201 return {offset_.data()[patchId], offset_.data()[patchId + 1]};
202 }
203
204private:
205
206 Executor exec_;
207 Vector<T> value_;
209 Vector<T> refValue_;
210 Vector<scalar> valueFraction_;
212 Vector<T> refGrad_;
213 Vector<int> boundaryTypes_;
214 Vector<localIdx> offset_;
215 localIdx nBoundaries_;
216 localIdx nBoundaryFaces_;
217};
218
219}
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()
localIdx nBoundaryFaces(localIdx patchId) const
Get the number of boundary faces for this patch.
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.
Reference executor for serial CPU execution.
A class to contain the data and executors for a field and define some basic operations.
Definition vector.hpp:30
ValueType * data()
Direct access to the underlying field data.
Definition vector.hpp:217
Definition array.hpp:20
int32_t localIdx
Definition label.hpp:32
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:18