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) 2021 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 CPU_SISD_MASK_H_
25#define CPU_SISD_MASK_H_
26
27#include "column.h"
28
29namespace olb {
30
31template <typename T>
33private:
35 std::size_t _weight;
36
37public:
38 ConcreteBlockMask(std::size_t size):
39 _mask(size),
40 _weight(0)
41 { }
42
44 return _mask;
45 }
46
47 bool operator[](std::size_t i) const {
48 return _mask[i];
49 }
50
51 void set(std::size_t i, bool active) {
52 if ( _mask[i] && !active) {
53 _weight -= 1;
54 } else if (!_mask[i] && active) {
55 _weight += 1;
56 }
57 _mask[i] = active;
58 }
59
60 std::size_t weight() const {
61 return _weight;
62 }
63
65
67 std::size_t getNblock() const override;
69 std::size_t getSerializableSize() const override;
71 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
72
73};
74
75template<typename T>
77{
78 return 1 + _mask.getNblock();
79}
80
81template<typename T>
83{
84 return sizeof(_weight) + _mask.getSerializableSize();
85}
86
87template<typename T>
88bool* ConcreteBlockMask<T,Platform::CPU_SISD>::getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode)
89{
90 std::size_t currentBlock = 0;
91 bool* dataPtr = nullptr;
92
93 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _weight);
94 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _mask, loadingMode);
95
96 return dataPtr;
97}
98
99
100}
101
102#endif
bool operator[](std::size_t i) const
Definition mask.h:47
AbstractColumn< bool > & asAbstract()
Definition mask.h:43
void set(std::size_t i, bool active)
Definition mask.h:51
void setProcessingContext(ProcessingContext)
Definition mask.h:64
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
Definition serializer.h:145
Plain column for SISD CPU targets (default)
Definition column.h:45
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
Definition platform.h:54
Platform
OpenLB execution targets.
Definition platform.h:35
Abstract declarator of Column-like storage.
Definition column.h:34