24#ifndef FIELD_ARRAY_D_H
25#define FIELD_ARRAY_D_H
41template<
typename T,
typename DESCRIPTOR, Platform PLATFORM,
typename FIELD>
48template<
typename T,
typename DESCRIPTOR,
typename FIELD>
51 virtual const typename FIELD::template column_type<T>& getAbstractColumn(
unsigned iDim)
const = 0;
52 virtual typename FIELD::template column_type<T>& getAbstractColumn(
unsigned iDim) = 0;
64 template <Platform PLATFORM>
70 throw std::invalid_argument(
"FieldArrayD is not of PLATFORM");
79 throw std::invalid_argument(
"FieldArrayD is not based on ColumnVectorBase. Something is wrong.");
86 virtual void resize(std::size_t newCount) = 0;
90 return getAbstractColumn(iDim);
95 return getAbstractColumn(iDim);
98 auto get(std::size_t i)
const
100 if constexpr (DESCRIPTOR::template size<FIELD>() == 1) {
104 DESCRIPTOR::template size<FIELD>()>([
this,i](
unsigned iD) {
112 for (
unsigned iD=0; iD < DESCRIPTOR::template size<FIELD>(); ++iD) {
124 return ptr(*
this, i);
130template<
typename T,
typename DESCRIPTOR,
typename FIELD>
132 :
public ScalarVector<const typename FIELD::template value_type<T>,
133 DESCRIPTOR::template size<FIELD>(),
140 DESCRIPTOR::template size<FIELD>(),
152 _index(rhs._index) { }
156 return &_data[iDim][_index];
172template<
typename T,
typename DESCRIPTOR,
typename FIELD>
174 :
public ScalarVector<typename FIELD::template value_type<T>,
175 DESCRIPTOR::template size<FIELD>(),
182 DESCRIPTOR::template size<FIELD>(),
194 _index(rhs._index) { }
198 return &_data[iDim][_index];
203 return &_data[iDim][_index];
206 template <
typename U,
typename IMPL>
209 for (
unsigned iD=0; iD < DESCRIPTOR::template size<FIELD>(); ++iD) {
229template<
typename T,
typename DESCRIPTOR, Platform PLATFORM,
typename FIELD>
230class FieldArrayD final :
public ColumnVector<typename ImplementationOf<typename FIELD::template column_type<T>,PLATFORM>::type,
231 DESCRIPTOR::template size<FIELD>()>
235 const typename FIELD::template
column_type<T>& getAbstractColumn(
unsigned iDim)
const override
240 typename FIELD::template
column_type<T>& getAbstractColumn(
unsigned iDim)
override
256 DESCRIPTOR::template size<FIELD>()>(count)
258 const auto initial = FIELD::template getInitialValue<T,DESCRIPTOR>();
259 for (std::size_t i=0; i < count; ++i) {
281 for (
unsigned iDim=0; iDim < DESCRIPTOR::template size<FIELD>(); ++iDim) {
282 this->
operator[](iDim).setProcessingContext(context);
286 void resize(std::size_t newCount)
override {
287 const std::size_t oldCount = this->
_count;
288 for (
unsigned iDim=0; iDim < DESCRIPTOR::template size<FIELD>(); ++iDim) {
292 if (oldCount < newCount) {
293 const auto initial = FIELD::template getInitialValue<T,DESCRIPTOR>();
294 for (std::size_t i=oldCount; i < newCount; ++i) {
303 return this->
getRow(iCell);
324template <
typename T,
typename DESCRIPTOR,
typename FIELD>
330 template <Platform PLATFORM>
341template <
typename T,
typename DESCRIPTOR,
typename FIELD>
345 #if defined(PLATFORM_GPU_CUDA)
347 return std::unique_ptr<AbstractFieldArrayD<T,DESCRIPTOR,FIELD>>(
350 return std::unique_ptr<AbstractFieldArrayD<T,DESCRIPTOR,FIELD>>(
354 return std::unique_ptr<AbstractFieldArrayD<T,DESCRIPTOR,FIELD>>(
359template <
typename T,
typename DESCRIPTOR, Platform PLATFORM,
typename FIELD>
366 _communicatee{communicatee} { }
374 >(_communicatee).
size(indices));
379 std::uint8_t* buffer)
const override
381 std::uint8_t* curr = buffer;
385 >(_communicatee).
serialize(indices, curr);
386 return curr - buffer;
391 const std::uint8_t* buffer)
override
393 const std::uint8_t* curr = buffer;
398 return curr - buffer;
409template<
typename T,
typename DESCRIPTOR,
Platform PLATFORM,
typename... FIELDS>
415 std::tuple<FieldArrayD<T,DESCRIPTOR,PLATFORM,FIELDS>...> _static;
424 _static((std::void_t<FIELDS>(), count)...)
427 template <
typename FIELD>
430 static_assert(
meta::contains<FIELD,FIELDS...>(),
"FIELD not contained in FIELDS");
431 return std::get<(fields_t::template index<FIELD>())>(_static);
434 template <
typename FIELD>
437 static_assert(
meta::contains<FIELD,FIELDS...>(),
"FIELD not contained in FIELDS");
438 return std::get<(fields_t::template index<FIELD>())>(_static);
442 template <
typename FIELD>
449 template <
typename FIELD>
455 template <
typename FIELD>
456 const typename FIELD::template value_type<T>&
getFieldComponent(std::size_t iCell,
unsigned iDim)
const;
457 template <
typename FIELD>
458 typename FIELD::template value_type<T>&
getFieldComponent(std::size_t iCell,
unsigned iDim);
460 template <
typename FIELD>
465 template <
typename FIELD>
472 template <
typename F>
474 template <
typename F>
477 template <
typename F>
487 fieldArray.resize(newCount);
493 void swap(std::size_t i, std::size_t j)
496 fieldArray.swap(i,j);
502 fieldArray.setProcessingContext(context);
511 bool*
getBlock(std::size_t iBlock, std::size_t& sizeBlock,
bool loadingMode)
override;
522template <
typename T,
typename DESCRIPTOR,
Platform PLATFORM,
typename... FIELDS>
529 _communicatee{communicatee} { }
537 >(_communicatee.template get<FIELDS>()).
size(indices) + ... + 0);
542 std::uint8_t* buffer)
const override
544 std::uint8_t* curr = buffer;
546 using FIELD =
typename decltype(field)::type;
550 >(_communicatee.get(field)).serialize(indices, curr);
552 return curr - buffer;
557 const std::uint8_t* buffer)
override
559 const std::uint8_t* curr = buffer;
561 using FIELD =
typename decltype(field)::type;
565 >(_communicatee.get(field)).deserialize(indices, curr);
567 return curr - buffer;
573template <
typename T,
typename GROUPS>
575template <
typename T,
typename... GROUPS>
578 template <
typename GROUP>
579 struct GroupedFieldArrayD {
580 template <
typename... FIELDS>
582 using type =
typename GROUP::template decompose_into<curried>;
585 std::tuple<typename GroupedFieldArrayD<GROUPS>::type...> _data;
591 _data((std::void_t<GROUPS>(), count)...), _count(count) { }
593 template <
typename GROUP>
598 throw std::invalid_argument(
"This DynamicFieldGroupsD does not provide GROUP.");
602 std::size_t
count(){
return _count; }
605 (get<GROUPS>().resize(newCount), ...);
609 void swap(std::size_t i, std::size_t j)
611 (get<GROUPS>().swap(i,j), ...);
616 return (get<GROUPS>().getSerializableSize() + ... + 0);
625template<
typename DATA,
typename... GROUPS>
637 std::size_t
size = 0;
639 using GROUP =
typename decltype(group)::type;
642 size += communicatable.size(indices);
650 std::uint8_t* curr = buffer;
652 using GROUP =
typename decltype(group)::type;
655 curr += communicatable.serialize(indices, curr);
657 return curr - buffer;
663 const std::uint8_t* curr = buffer;
665 using GROUP =
typename decltype(group)::type;
668 curr += communicatable.deserialize(indices, curr);
670 return curr - buffer;
675template <
typename DATA,
typename DESCRIPTOR>
677 template<
typename... GROUPS>
680 using type =
typename DESCRIPTOR::template decompose_into<CurriedFieldGroupsCommunicatable>;
684template <
typename T,
typename DESCRIPTOR, Platform PLATFORM>
686 template<
typename... FIELDS>
689 using type =
typename DESCRIPTOR::fields_t::template decompose_into<CurriedMultiFieldArrayD>;
693template <
typename T,
typename DESCRIPTOR, Platform PLATFORM=Platform::CPU_SISD>
Read-only proxy for accessing a column vector entry.
const FIELD::template value_type< T > * getComponentPointer(unsigned iDim) const
const_ptr(const AbstractFieldArrayD< T, DESCRIPTOR, FIELD > &data, std::size_t index)
const_ptr(const_ptr &&rhs)
std::size_t getIndex() const
void setIndex(std::size_t index)
Proxy for accessing a column vector entry.
ptr & operator=(const GenericVector< U, DESCRIPTOR::template size< FIELD >(), IMPL > &rhs)
const FIELD::template value_type< T > * getComponentPointer(unsigned iDim) const
FIELD::template value_type< T > * getComponentPointer(unsigned iDim)
ptr(AbstractFieldArrayD< T, DESCRIPTOR, FIELD > &data, std::size_t index)
std::size_t getIndex() const
void setIndex(std::size_t index)
Platform-agnostic interface to concrete host-side field arrays.
auto & operator[](unsigned iDim)
const auto & operator[](unsigned iDim) const
void set(std::size_t i, const FieldD< T, DESCRIPTOR, FIELD > &data)
const_ptr getPointer(std::size_t i) const
auto get(std::size_t i) const
virtual Platform getPlatform() const =0
Returns Platform of concrete FieldArrayD.
FieldArrayD< T, DESCRIPTOR, PLATFORM, FIELD > & asConcrete()
Cast to concrete FieldArrayD<PLATFORM>
ColumnVectorBase & asColumnVectorBase()
virtual void setProcessingContext(ProcessingContext context)=0
Sets processing context (Platform dependent)
virtual void resize(std::size_t newCount)=0
Resize to size newCount.
ptr getPointer(std::size_t i)
auto setRow(std::size_t i, const Vector< typename ImplementationOf< FIELD::template column_type< T >, PLATFORM >::type::value_t, D > &value)
auto getRow(std::size_t i) const
ptr getRowPointer(std::size_t i)
std::size_t size() const
ADDITIONAL NON OVERWITTEN CALLS: Removing the necessity to provide indices.
std::size_t deserialize(ConstSpan< CellID > indices, const std::uint8_t *buffer) override
Deserialize data at locations indices to buffer
std::size_t serialize(ConstSpan< CellID > indices, std::uint8_t *buffer) const override
Serialize data at locations indices to buffer
Storage for dynamic field groups (Prototype for ParticleSystem)
SoA storage for instances of a single FIELD.
AbstractFieldArrayD< T, DESCRIPTOR, FIELD > & asAbstract()
auto getFieldPointer(std::size_t iCell) const
auto getField(std::size_t iCell) const
Return copy of FIELD data for cell iCell.
void setProcessingContext(ProcessingContext context) override
Sets processing context (Platform dependent)
Platform getPlatform() const override
Returns Platform of concrete FieldArrayD.
static constexpr Platform platform
void resize(std::size_t newCount) override
const AbstractFieldArrayD< T, DESCRIPTOR, FIELD > & asAbstract() const
void setField(std::size_t iCell, const FieldD< T, DESCRIPTOR, FIELD > &v)
Set FIELD data at cell iCell.
auto getFieldPointer(std::size_t iCell)
FieldArrayD(std::size_t count)
typename FIELD::template value_type< T > value_type
typename ImplementationOf< typename FIELD::template column_type< T >, PLATFORM >::type column_type
GroupedDataCommunicatable(DATA &data)
std::size_t serialize(ConstSpan< CellID > indices, std::uint8_t *buffer) const
Serialize data at locations indices to buffer
std::size_t size(ConstSpan< CellID > indices) const
Get serialized size for data at locations indices
std::size_t deserialize(ConstSpan< CellID > indices, const std::uint8_t *buffer)
Deserialize data at locations indices to buffer
Base class for all LoadBalancer.
bool isLocal(const int &glob) const
returns whether glob is on this process
Storage for a fixed set of FIELDS.
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
Return a pointer to the memory of the current block and its size for the serializable interface.
MultiFieldArrayD(std::size_t count=1)
void setField(std::size_t iCell, const FieldD< T, DESCRIPTOR, FIELD > &v)
Set FIELD data at cell iCell.
auto getField(std::size_t iCell) const
Return copy of FIELD data for cell iCell.
std::size_t getSerializableSize() const override
Binary size for the serializer.
void resize(std::size_t newCount)
Change number of rows.
void swap(std::size_t i, std::size_t j)
Swap contents of rows i and j.
auto getFieldPointer(std::size_t iCell)
auto getFieldPointer(std::size_t iCell) const
const FIELD::template value_type< T > & getFieldComponent(std::size_t iCell, unsigned iDim) const
void setProcessingContext(ProcessingContext context)
void forFieldsAt(std::size_t idx, F f)
Apply generic lambda expression to each FIELD of a cell.
std::size_t getNblock() const override
Number of data blocks for the serializable interface.
const FieldArrayD< T, DESCRIPTOR, PLATFORM, FIELD > & get(meta::id< FIELD > field=meta::id< FIELD >()) const
FieldArrayD< T, DESCRIPTOR, PLATFORM, FIELD > & get(meta::id< FIELD > field=meta::id< FIELD >())
void forFields(F f) const
Apply generic expression to each FIELD array.
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
constexpr unsigned getIndexInFieldList()
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
Platform
OpenLB execution targets.
@ GPU_CUDA
Vector CPU (AVX2 / AVX-512 collision)
typename MultiFieldArrayForDescriptorHelper< T, DESCRIPTOR, PLATFORM >::type MultiFieldArrayForDescriptorD
MultiFieldArrayD containing each field in DESCRIPTOR::fields_t.
std::unique_ptr< AbstractFieldArrayD< T, DESCRIPTOR, FIELD > > makeSharedAbstractFieldArrayD(LoadBalancer< T > &loadBalancer, std::size_t count=1)
Constructs FieldArrayD accessible on all locally used platforms.
Base to identify whether a type is some kind of AbstractFieldArrayD without caring about the specific...
Base of all ColumnVector specializations.
Curried FieldArrayD template for use in callUsingConcretePlatform.
Generic vector of values supporting basic arithmetic.
static constexpr unsigned size()
Declare GroupedDataCommunicatable containing each GROUP in DESCRIPTOR::fields_t.
typename DESCRIPTOR::template decompose_into< CurriedFieldGroupsCommunicatable > type
Specializable declarator for concrete implementations of abstract storage types.
Declare MultiFieldArrayD containing each field in DESCRIPTOR::fields_t.
typename DESCRIPTOR::fields_t::template decompose_into< CurriedMultiFieldArrayD > type
efficient implementation of a vector class