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) 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
43 bool operator[](std::size_t i) const {
44 return _mask[i];
45 }
46
47 void set(std::size_t i, bool active) {
48 if ( _mask[i] && !active) {
49 _weight -= 1;
50 } else if (!_mask[i] && active) {
51 _weight += 1;
52 }
53 _mask[i] = active;
54 }
55
56 std::size_t weight() const {
57 return _weight;
58 }
59
61
63 std::size_t getNblock() const override;
65 std::size_t getSerializableSize() const override;
67 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
68
69};
70
71template<typename T>
73{
74 return 1 + _mask.getNblock();
75}
76
77template<typename T>
79{
80 return sizeof(_weight) + _mask.getSerializableSize();
81}
82
83template<typename T>
84bool* ConcreteBlockMask<T,Platform::CPU_SISD>::getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode)
85{
86 std::size_t currentBlock = 0;
87 bool* dataPtr = nullptr;
88
89 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _weight);
90 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _mask, loadingMode);
91
92 return dataPtr;
93}
94
95
96}
97
98#endif
bool operator[](std::size_t i) const
Definition mask.h:43
void set(std::size_t i, bool active)
Definition mask.h:47
void setProcessingContext(ProcessingContext)
Definition mask.h:60
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:55
Platform
OpenLB execution targets.
Definition platform.h:36