OpenLB 1.7
Loading...
Searching...
No Matches
mask.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef GPU_CUDA_MASK_H_
25#define GPU_CUDA_MASK_H_
26
27#include "column.h"
28
29namespace olb {
30
31template <typename T>
33private:
35 std::size_t _weight;
36
37 bool _modified;
38
39public:
40 ConcreteBlockMask(std::size_t size):
41 _mask(size),
42 _weight(0),
43 _modified(true) { }
44
45 bool operator[](std::size_t i) const {
46 return _mask[i];
47 }
48
49 void set(std::size_t i, bool active) {
50 if ( _mask[i] && !active) {
51 _weight -= 1;
52 } else if (!_mask[i] && active) {
53 _weight += 1;
54 }
55 _mask[i] = active;
56 _modified = true;
57 }
58
59 std::size_t weight() const {
60 return _weight;
61 }
62
63 bool* deviceData() {
64 return _mask.deviceData();
65 }
66
68 if (_modified && context == ProcessingContext::Simulation) {
69 _mask.setProcessingContext(context);
70 _modified = false;
71 }
72 }
73
75 std::size_t getNblock() const override;
77 std::size_t getSerializableSize() const override;
79 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
80
81};
82
83template<typename T>
85{
86 return 1 + _mask.getNblock();
87}
88
89template<typename T>
91{
92 return sizeof(_weight) + _mask.getSerializableSize();
93}
94
95template<typename T>
96bool* ConcreteBlockMask<T,Platform::GPU_CUDA>::getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode)
97{
98 std::size_t currentBlock = 0;
99 bool* dataPtr = nullptr;
100
101 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _weight);
102 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _mask, loadingMode);
103
104 return dataPtr;
105}
106
107
108}
109
110#endif
bool operator[](std::size_t i) const
Definition mask.h:45
void setProcessingContext(ProcessingContext context)
Definition mask.h:67
void set(std::size_t i, bool active)
Definition mask.h:49
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
Definition serializer.h:145
Plain column for CUDA GPU targets.
Definition column.h:49
const T * deviceData() const
Definition column.hh:146
void setProcessingContext(ProcessingContext)
Definition column.hh:158
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
Definition platform.h:55
@ Simulation
Data available on host for e.g. functor evaluation.
Platform
OpenLB execution targets.
Definition platform.h:36
@ GPU_CUDA
Vector CPU (AVX2 / AVX-512 collision)