24#ifndef SISD_OPERATOR_H
25#define SISD_OPERATOR_H
45template <
typename T,
typename DESCRIPTOR,
typename DYNAMICS>
52 _parameters{parameters} {
56 return DYNAMICS().collide(cell, *_parameters);
60 return typename DYNAMICS::MomentaF().computeRho(cell);
63 typename DYNAMICS::MomentaF().computeU(cell, u);
66 typename DYNAMICS::MomentaF().computeJ(cell, j);
69 typename DYNAMICS::MomentaF().computeRhoU(cell, rho, u);
72 typename DYNAMICS::MomentaF().computeStress(cell, rho, u, pi);
75 typename DYNAMICS::MomentaF().computeAllMomenta(cell, rho, u, pi);
79 if constexpr (DYNAMICS::parameters::template contains<descriptors::OMEGA>()) {
80 return _parameters->template get<descriptors::OMEGA>();
84 __builtin_unreachable();
88 typename DYNAMICS::EquilibriumF().compute(cell, rho, u, fEq);
92 typename DYNAMICS::MomentaF().defineRho(cell, rho);
96 typename DYNAMICS::MomentaF().defineU(cell, u);
100 typename DYNAMICS::MomentaF().defineRhoU(cell, rho, u);
104 typename DYNAMICS::MomentaF().defineAllMomenta(cell, rho, u, pi);
108 typename DYNAMICS::MomentaF().inverseShiftRhoU(cell, rho, u);
124template <
typename T,
typename DESCRIPTOR,
typename DYNAMICS>
128 std::unique_ptr<DYNAMICS> _dynamics;
129 std::unique_ptr<cpu::Dynamics<T,DESCRIPTOR,Platform::CPU_SISD>> _concreteDynamics;
136 std::vector<CellID> _cells;
146 auto& parameters = *_parameters;
149 #ifdef PARALLEL_MODE_OMP
150 #pragma omp declare reduction(+ : typename LatticeStatistics<T>::Aggregatable : omp_out += omp_in) initializer (omp_priv={})
153 if constexpr (DESCRIPTOR::d == 3) {
155 #ifdef PARALLEL_MODE_OMP
156 #pragma omp parallel for schedule(dynamic,1) reduction(+ : statistics)
158 for (
int iX=0; iX < block.
getNx(); ++iX) {
159 for (
int iY=0; iY < block.
getNy(); ++iY) {
160 std::size_t iCell = block.
getCellId(iX,iY,0);
161 for (
int iZ=0; iZ < block.
getNz(); ++iZ) {
163 if (
auto cellStatistic = mask[iCell] ? DYNAMICS().collide(cell, parameters)
164 : _dynamicsOfCells[iCell]->collide(cell)) {
165 statistics.increment(cellStatistic.rho, cellStatistic.uSqr);
172 #ifdef PARALLEL_MODE_OMP
173 #pragma omp parallel for schedule(dynamic,1)
175 for (
int iX=0; iX < block.
getNx(); ++iX) {
176 for (
int iY=0; iY < block.
getNy(); ++iY) {
177 std::size_t iCell = block.
getCellId(iX,iY,0);
178 for (
int iZ=0; iZ < block.
getNz(); ++iZ) {
180 if (mask[iCell]) [[likely]] {
181 DYNAMICS().collide(cell, parameters);
183 _dynamicsOfCells[iCell]->
collide(cell);
192 #ifdef PARALLEL_MODE_OMP
193 #pragma omp parallel for schedule(dynamic,1) reduction(+ : statistics)
195 for (
int iX=0; iX < block.
getNx(); ++iX) {
196 std::size_t iCell = block.
getCellId(iX,0);
197 for (
int iY=0; iY < block.
getNy(); ++iY) {
199 if (
auto cellStatistic = mask[iCell] ? DYNAMICS().collide(cell, parameters)
200 : _dynamicsOfCells[iCell]->collide(cell)) {
201 statistics.increment(cellStatistic.rho, cellStatistic.uSqr);
207 #ifdef PARALLEL_MODE_OMP
208 #pragma omp parallel for schedule(dynamic,1)
210 for (
int iX=0; iX < block.
getNx(); ++iX) {
211 std::size_t iCell = block.
getCellId(iX,0);
212 for (
int iY=0; iY < block.
getNy(); ++iY) {
214 if (mask[iCell]) [[likely]] {
215 DYNAMICS().collide(cell, parameters);
217 _dynamicsOfCells[iCell]->
collide(cell);
238 if (_mask->operator[](iCell)) {
239 _cells.push_back(iCell);
245 auto& parameters = *_parameters;
248 #ifdef PARALLEL_MODE_OMP
249 #pragma omp declare reduction(+ : typename LatticeStatistics<T>::Aggregatable : omp_out += omp_in) initializer (omp_priv={})
252 #ifdef PARALLEL_MODE_OMP
253 #pragma omp parallel for schedule(static) reduction(+ : statistics)
255 for (std::size_t i=0; i < _cells.size(); ++i) {
256 std::size_t iCell = _cells[i];
258 if (
auto cellStatistic = DYNAMICS().collide(cell, parameters)) {
259 statistics.increment(cellStatistic.rho, cellStatistic.uSqr);
268 _dynamics(new DYNAMICS()),
269 _parameters(nullptr),
275 std::type_index
id()
const override
277 return typeid(DYNAMICS);
282 return _mask->weight();
285 void set(
CellID iCell,
bool state,
bool overlap)
override
290 _mask->set(iCell, state);
294 _dynamicsOfCells[iCell] = _concreteDynamics.get();
301 return _dynamics.get();
306 _parameters = &block.template getData<OperatorParameters<DYNAMICS>>().parameters;
307 _mask = &block.template getData<DynamicsMask<DYNAMICS>>();
308 if constexpr (dynamics::has_parametrized_momenta_v<DYNAMICS>) {
309 _dynamics->setMomentaParameters(_parameters);
314 _dynamicsOfCells = block.template getField<cpu::DYNAMICS<T,DESCRIPTOR,Platform::CPU_SISD>>()[0].data();
327 return applyDominant(block, subdomain);
329 return applyIndividual(block, subdomain);
331 throw std::runtime_error(
"Invalid collision dispatch strategy");
339template <
typename T,
typename DESCRIPTOR, concepts::CellOperator OPERATOR>
341 :
public BlockO<T,DESCRIPTOR,Platform::CPU_SISD> {
343 std::vector<CellID> _cells;
347 std::type_index
id()
const override
354 return _cells.size();
360 _cells.emplace_back(iCell);
371 std::sort(_cells.begin(), _cells.end());
372 _cells.erase(std::unique(_cells.begin(), _cells.end()), _cells.end());
375 if (_cells.size() > 0) {
377 #ifdef PARALLEL_MODE_OMP
378 #pragma omp parallel for schedule(static) firstprivate(cell)
380 for (
CellID iCell : _cells) {
390template <
typename T,
typename DESCRIPTOR, concepts::CellOperator OPERATOR>
392 :
public BlockO<T,DESCRIPTOR,Platform::CPU_SISD> {
394 std::vector<CellID> _cells;
400 std::type_index
id()
const override
407 return _cells.size();
413 _cells.emplace_back(iCell);
420 _parameters = &block.template getData<OperatorParameters<OPERATOR>>().parameters;
426 std::sort(_cells.begin(), _cells.end());
427 _cells.erase(std::unique(_cells.begin(), _cells.end()), _cells.end());
430 if (_cells.size() > 0) {
432 #ifdef PARALLEL_MODE_OMP
433 #pragma omp parallel for schedule(static) firstprivate(cell)
435 for (
CellID iCell : _cells) {
437 OPERATOR().apply(cell, *_parameters);
449template <
typename T,
typename DESCRIPTOR, concepts::BlockOperator OPERATOR>
451 :
public BlockO<T,DESCRIPTOR,Platform::CPU_SISD> {
453 std::type_index
id()
const override
465 throw std::logic_error(
"BlockO::set not supported for OperatorScope::PerBlock");
#define OPERATOR(OP, rhs)
bool statisticsEnabled() const
LatticeStatistics< T > & getStatistics()
Return a handle to the LatticeStatistics object.
std::size_t getNcells() const
Get number of cells.
int getNy() const
Read only access to block height.
int getNx() const
Read only access to block width.
CellID getCellId(LatticeR< D > latticeR) const
Get 1D cell ID.
int getNz() const
Read only access to block height.
Collision operation of concrete DYNAMICS on concrete block lattices of PLATFORM.
Implementation of BlockLattice on a concrete PLATFORM.
Block application of concrete OPERATOR called using SCOPE on PLATFORM.
Cell concept for concrete block lattices on CPU platforms.
void setCellId(CellID iCell)
Implementation of cpu::Dynamics for concrete DYNAMICS on SISD blocks.
void defineU(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T *u) override
void defineAllMomenta(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T &rho, T *u, T *pi) override
void computeEquilibrium(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T rho, T *u, T *fEq) override
void computeStress(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T &rho, T *u, T *pi) override
T computeRho(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell) override
ConcreteDynamics(ParametersOfOperatorD< T, DESCRIPTOR, DYNAMICS > *parameters)
CellStatistic< T > collide(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell) override
void inverseShiftRhoU(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T &rho, T *u) override
void defineRhoU(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T &rho, T *u) override
T getOmegaOrFallback(T fallback) override
void computeU(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T *u) override
void computeRhoU(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T &rho, T *u) override
void defineRho(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T &rho) override
void computeJ(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T *j) override
void computeAllMomenta(cpu::Cell< T, DESCRIPTOR, Platform::CPU_SISD > &cell, T &rho, T *u, T *pi) override
Interface for post-processing steps – header file.
Top level namespace for all of OpenLB.
std::uint32_t CellID
Type for sequential block-local cell indices.
Platform
OpenLB execution targets.
CollisionDispatchStrategy
Collision dispatch strategy.
@ Individual
Apply all dynamics individually (async for Platform::GPU_CUDA)
@ Dominant
Apply dominant dynamics using mask and fallback to virtual dispatch for others.
typename ParametersD< T, DESCRIPTOR >::template include< typename OPERATOR::parameters > ParametersOfOperatorD
Deduce ParametersD of OPERATOR w.r.t. T and DESCRIPTOR.
@ PerBlock
Per-block application, i.e. OPERATOR::apply is passed a ConcreteBlockLattice.
@ PerCell
Per-cell application, i.e. OPERATOR::apply is passed a CELL concept implementation.
@ PerCellWithParameters
Per-cell application with parameters, i.e. OPERATOR::apply is passed a CELL concept implementation an...
Collision operation on concrete blocks of PLATFORM.
Base of block-wide operators such as post processors.
Return value of any collision.
Interface for per-cell dynamics.
CPU specific field mirroring BlockDynamicsMap.
Virtual interface for dynamically-dispatched dynamics access on CPU targets.
virtual CellStatistic< T > collide(Cell< T, DESCRIPTOR, PLATFORM > &cell)=0