OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM > Class Template Reference

Map between cell indices and concrete dynamics. More...

#include <blockDynamicsMap.h>

+ Inheritance diagram for olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >:
+ Collaboration diagram for olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >:

Public Member Functions

 BlockDynamicsMap (ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > &lattice)
 Constructor for a BlockDynamicsMap.
 
Dynamics< T, DESCRIPTOR > * get (DynamicsPromise< T, DESCRIPTOR > &&promise)
 Returns a pointer to dynamics matching the promise.
 
const Dynamics< T, DESCRIPTOR > * get (std::size_t iCell) const
 
Dynamics< T, DESCRIPTOR > * get (std::size_t iCell)
 
void set (std::size_t iCell, DynamicsPromise< T, DESCRIPTOR > &&promise)
 Assigns promised dynamics to cell index iCell.
 
void set (std::size_t iCell, Dynamics< T, DESCRIPTOR > *dynamics)
 Assigns dynamics pointer to cell index iCell.
 
void collide (CollisionDispatchStrategy strategy)
 Executes local collision step for entire non-overlap area of lattice.
 
std::string describe ()
 Returns a human-readable string listing all managed dynamics and their assigned fraction of cells.
 

Detailed Description

template<typename T, typename DESCRIPTOR, Platform PLATFORM>
class olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >

Map between cell indices and concrete dynamics.

Central class for managing and applying dynamics of / to a block lattice.

Maintains both a map of cell indices to dynamics and of dynamics to a mask of all assigned cell indices.

Automatically determines the dominant dynamics and applies the collision step to all cells via the dominant dynamics' ConcreteBlockCollisionO.

Definition at line 358 of file blockDynamicsMap.h.

Constructor & Destructor Documentation

◆ BlockDynamicsMap()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >::BlockDynamicsMap ( ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > & lattice)
inline

Constructor for a BlockDynamicsMap.

Setup support for legacy dynamics

Definition at line 401 of file blockDynamicsMap.h.

401 :
402 _lattice(lattice),
403 _dynamicsOfCells(new Dynamics<T,DESCRIPTOR>* [_lattice.getNcells()] { nullptr }),
404 _operatorOfCells(new BlockCollisionO<T,DESCRIPTOR,PLATFORM>*[_lattice.getNcells()] { nullptr }),
405 _coreMask(lattice.template getData<CollisionSubdomainMask>()),
406 _dominantCollisionO(nullptr)
407 {
408 _lattice.forCoreSpatialLocations([&](LatticeR<DESCRIPTOR::d> lattice) {
409 _coreMask.set(_lattice.getCellId(lattice), true);
410 });
411
412 if constexpr (isPlatformCPU(PLATFORM)) {
414 using LegacyO = LegacyBlockCollisionO<T,DESCRIPTOR,PLATFORM>;
415 _map[typeid(LegacyO)] = std::make_unique<LegacyO>(_lattice.getNcells(),
416 _dynamicsOfCells.get());
417 _map[typeid(LegacyO)]->setup(_lattice);
418 }
419 }
std::size_t getNcells() const
Get number of cells.
void forCoreSpatialLocations(F f) const
CellID getCellId(LatticeR< D > latticeR) const
Get 1D cell ID.
constexpr bool isPlatformCPU(Platform platform)
Returns true if platform is equal to Platform::CPU_*.
Definition platform.h:154

Member Function Documentation

◆ collide()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
void olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >::collide ( CollisionDispatchStrategy strategy)
inline

Executes local collision step for entire non-overlap area of lattice.

When using the default CollisionDispatchStrategy::Dominant, the most frequently assigned dynamics resp. collision operator is applied and responsible for also colliding cells excluded by its masks using their respective dynamics.

Correspondingly, the alternative CollisionDispatchStrategy::Individual applies all dynamics separately using a list-based approach.

Definition at line 480 of file blockDynamicsMap.h.

481 {
482 switch (strategy) {
484 if (!_dominantCollisionO) {
485 _dominantCollisionO = std::max_element(_map.begin(),
486 _map.end(),
487 [](const auto& lhs, const auto& rhs) -> bool {
488 return lhs.second->weight() < rhs.second->weight();
489 })->second.get();
490 }
491 _dominantCollisionO->apply(_lattice, _coreMask, strategy);
492 break;
493
495 for (auto& [id, collisionO] : _map) {
496 if (collisionO->weight() > 0) {
497 collisionO->apply(_lattice, _coreMask, strategy);
498 }
499 }
500 break;
501
502 default:
503 throw std::runtime_error("Invalid collision dispatch strategy");
504 break;
505 }
506 }
@ Individual
Apply all dynamics individually (async for Platform::GPU_CUDA)
@ Dominant
Apply dominant dynamics using mask and fallback to virtual dispatch for others.

References olb::BlockCollisionO< T, DESCRIPTOR, PLATFORM >::apply(), olb::Dominant, olb::Individual, and olb::AbstractCollisionO< T, DESCRIPTOR >::weight().

+ Here is the call graph for this function:

◆ describe()

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
std::string olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >::describe ( )
inline

Returns a human-readable string listing all managed dynamics and their assigned fraction of cells.

Definition at line 509 of file blockDynamicsMap.h.

510 {
511 std::stringstream out;
512 for (auto& [_, collisionO] : _map) {
513 out << collisionO->getDynamics()->getName() << ", "
514 << static_cast<double>(collisionO.weight()) / (_coreMask.weight())
515 << std::endl;
516 }
517 return out.str();
518 }

References olb::AbstractCollisionO< T, DESCRIPTOR >::getDynamics(), and olb::AbstractCollisionO< T, DESCRIPTOR >::weight().

+ Here is the call graph for this function:

◆ get() [1/3]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
Dynamics< T, DESCRIPTOR > * olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >::get ( DynamicsPromise< T, DESCRIPTOR > && promise)
inline

Returns a pointer to dynamics matching the promise.

Promise is only realized if dynamics were not previously constructed

Definition at line 425 of file blockDynamicsMap.h.

426 {
427 return resolve(std::forward<decltype(promise)>(promise)).getDynamics();
428 }
+ Here is the caller graph for this function:

◆ get() [2/3]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
Dynamics< T, DESCRIPTOR > * olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >::get ( std::size_t iCell)
inline

Definition at line 435 of file blockDynamicsMap.h.

436 {
437 return _dynamicsOfCells[iCell];
438 }

◆ get() [3/3]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
const Dynamics< T, DESCRIPTOR > * olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >::get ( std::size_t iCell) const
inline

Definition at line 430 of file blockDynamicsMap.h.

431 {
432 return _dynamicsOfCells[iCell];
433 }

◆ set() [1/2]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
void olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >::set ( std::size_t iCell,
Dynamics< T, DESCRIPTOR > * dynamics )
inline

Assigns dynamics pointer to cell index iCell.

Dynamics at the pointed address must either be legacy or previously constructed from a promise.

Definition at line 452 of file blockDynamicsMap.h.

453 {
454 auto iter = _map.find(dynamics->id());
455 if (iter != _map.end()) { // Non-legacy dynamics
456 set(iCell, *iter->second);
457 } else { // Legacy dynamics
458 iter = _map.find(typeid(LegacyBlockCollisionO<T,DESCRIPTOR,PLATFORM>));
459 if (iter != _map.end()) {
460 // Order is important here as LegacyBlockCollisionO uses the dynamics
461 // pointer to construct matching LegacyConcreteDynamics internally.
462 _dynamicsOfCells[iCell] = dynamics;
463 set(iCell, *iter->second);
464 } else {
465 throw std::runtime_error("Legacy dynamics not supported on this platform");
466 }
467 }
468 _dominantCollisionO = nullptr;
469 }

References olb::Dynamics< T, DESCRIPTOR >::id().

+ Here is the call graph for this function:

◆ set() [2/2]

template<typename T , typename DESCRIPTOR , Platform PLATFORM>
void olb::BlockDynamicsMap< T, DESCRIPTOR, PLATFORM >::set ( std::size_t iCell,
DynamicsPromise< T, DESCRIPTOR > && promise )
inline

Assigns promised dynamics to cell index iCell.

Definition at line 441 of file blockDynamicsMap.h.

442 {
443 set(iCell, resolve(std::forward<decltype(promise)>(promise)));
444 _dominantCollisionO = nullptr;
445 }

The documentation for this class was generated from the following file: