OpenLB 1.8.1
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 return _mask;
69 }
70
72 if (_modified && context == ProcessingContext::Simulation) {
73 _mask.setProcessingContext(context);
74 _modified = false;
75 }
76 }
77
79 std::size_t getNblock() const override;
81 std::size_t getSerializableSize() const override;
83 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
84
85};
86
87template<typename T>
89{
90 return 1 + _mask.getNblock();
91}
92
93template<typename T>
95{
96 return sizeof(_weight) + _mask.getSerializableSize();
97}
98
99template<typename T>
100bool* ConcreteBlockMask<T,Platform::GPU_CUDA>::getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode)
101{
102 std::size_t currentBlock = 0;
103 bool* dataPtr = nullptr;
104
105 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _weight);
106 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _mask, loadingMode);
107
108 return dataPtr;
109}
110
111
112}
113
114#endif
AbstractColumn< bool > & asAbstract()
Definition mask.h:67
bool operator[](std::size_t i) const
Definition mask.h:45
void setProcessingContext(ProcessingContext context)
Definition mask.h:71
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:54
@ Simulation
Data available on host for e.g. functor evaluation.
Platform
OpenLB execution targets.
Definition platform.h:35
@ GPU_CUDA
Vector CPU (AVX2 / AVX-512 collision)
Abstract declarator of Column-like storage.
Definition column.h:34