OpenLB 1.8.1
Loading...
Searching...
No Matches
operator.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2024 Adrian Kummerlaender
4 *
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25#ifndef REFINEMENT_PLATFORM_GPU_CUDA_OPERATOR_HH
26#define REFINEMENT_PLATFORM_GPU_CUDA_OPERATOR_HH
27
28#include "operator.h"
29
30namespace olb {
31
32namespace gpu::cuda {
33
34namespace kernel {
35
36template <typename COARSE, typename FINE, typename CONTEXT, typename PARAMETERS, typename OPERATOR>
38 FINE fLattice,
39 CONTEXT data,
40 PARAMETERS parameters,
41 std::size_t n) __global__ {
42 const CellID i = blockIdx.x * blockDim.x + threadIdx.x;
43 if (!(i < n)) {
44 return;
45 }
46
47 auto cellIdCoarse = data.template getField<fields::refinement::CELL_ID_COARSE>();
48 auto cellIdFine = data.template getField<fields::refinement::CELL_ID_FINE>();
49
50 if constexpr (OPERATOR::scope == refinement::OperatorScope::PerCoarseCell) {
51 if (cellIdCoarse[0][i] != 0) {
52 Cell cCell{cLattice, cellIdCoarse[0][i]};
53 Cell fCell{fLattice, cellIdFine[0][i]};
54 DataOnlyCell cData{data, i};
55 OPERATOR().apply(cCell, fCell, cData, parameters);
56 }
57 } else if constexpr (OPERATOR::scope == refinement::OperatorScope::PerFineCell) {
58 if constexpr (OPERATOR::data::template contains<fields::refinement::CONTEXT_NEIGHBORS>()) {
59 Cell fCell{fLattice, cellIdFine[0][i]};
60 refinement::CoarseCell cCell{Cell{cLattice, cellIdCoarse[0][i]},
61 fLattice.getLatticeR(cellIdFine[0][i])};
63 OPERATOR().apply(cCell, fCell, cData, parameters);
64 } else {
65 Cell fCell{fLattice, cellIdFine[0][i]};
66 refinement::CoarseCell cCell{Cell{cLattice, cellIdCoarse[0][i]},
67 fLattice.getLatticeR(cellIdFine[0][i])};
69 OPERATOR().apply(cCell, fCell, cData, parameters);
70 }
71 }
72}
73
74}
75
76template <typename COARSE, typename FINE, typename CONTEXT, typename PARAMETERS, typename OPERATOR>
77void call_refinement_coupling_operator(COARSE& cLattice, FINE& fLattice,
78 CONTEXT& data,
79 PARAMETERS& parameters,
81 const std::size_t n = data.getNcells();
82 if (n > 0) {
83 const auto block_size = 32;
84 const auto block_count = (n + block_size - 1) / block_size;
86 <<<block_count,block_size>>>(cLattice, fLattice, data, parameters, n);
88 }
89}
90
91}
92
93template <typename T, typename DESCRIPTOR, typename OPERATOR>
96{
97 auto& cLattice = context.getCoarseLattice();
98 auto& fLattice = context.getFineLattice();
99 auto& data = context.getConcreteData();
100
101 auto parameters = data.template getData<OperatorParameters<OPERATOR>>().parameters;
102
103 gpu::cuda::DeviceBlockLattice deviceCoarseLattice{cLattice};
104 gpu::cuda::DeviceBlockLattice deviceFineLattice{fLattice};
105 gpu::cuda::DeviceContext deviceData{data};
106
108 deviceFineLattice,
109 deviceData,
110 parameters,
111 meta::id<OPERATOR>{});
112}
113
114}
115
116#endif
#define OPERATOR(OP, rhs)
Definition aDiffTape.h:64
Context for the execution of block refinement operators.
Device-side implementation of the Cell concept for post processors.
Definition context.hh:313
Device-side implementation of the data-only Cell concept for collision steps.
Definition dynamics.hh:37
Device-side view of a block lattice.
Definition context.hh:244
void check()
Check errors.
Definition device.hh:48
void call_refinement_coupling_operator(COARSE cLattice, FINE fLattice, CONTEXT data, PARAMETERS parameters, std::size_t n) __global__
Definition operator.hh:37
void call_refinement_coupling_operator(COARSE &cLattice, FINE &fLattice, CONTEXT &data, PARAMETERS &parameters, meta::id< OPERATOR >)
Definition operator.hh:77
@ PerFineCell
OPERATOR is provided a fine cell and a coarse cell proxy.
@ PerCoarseCell
OPERATOR is provided a coarse cell and its co-incident fine cell.
Top level namespace for all of OpenLB.
std::uint32_t CellID
Type for sequential block-local cell indices.
Executor of a concrete block refinement operator in a given context.
Definition operator.h:40
Identity type to pass non-constructible types as value.
Definition meta.h:79