VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
KdSplitCandidateManager.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#ifndef KDSPLITCANDIDATEMANAGER_H
35#define KDSPLITCANDIDATEMANAGER_H
36
38
39#include <algorithm>
40#include <map>
41#include <vector>
42
43namespace kd_tree
44{
45template <typename T>
47{
48public:
50
51 = default;
52 /* ======================================================================================= */
53 SplitCandidate<T> &operator[](const std::size_t &i)
54 {
55#ifdef DEBUG
56 return splitCandidatesVec.at(i);
57#else
58 return splitCandidatesVec[i];
59#endif
60 }
61 /* ======================================================================================= */
62 typename std::vector<SplitCandidate<T>>::size_type size() { return splitCandidatesVec.size(); }
63 /* ======================================================================================= */
64 void add(const T &pos, const int &axis, const int &starting, const int &ending, const int &np)
65 {
66 typename std::map<T, SplitCandidate<T>>::iterator it = splitCandidates.find(pos);
67 if (it != splitCandidates
68 .end()) // split candidate is already available -> increase parameter (starting, ending and np)
69 {
70 SplitCandidate<T> &sc = it->second;
71 sc.np += np;
72 sc.starting += starting;
73 sc.ending += ending;
74 } else // split candidate is not available -> add new split candidate
75 {
76 this->splitCandidates[pos] = SplitCandidate<T>(axis, pos, starting, ending, np);
77 }
78 }
79 /* ======================================================================================= */
81 {
82 splitCandidatesVec.clear();
83 typename std::map<T, SplitCandidate<T>>::iterator it;
84 for (it = splitCandidates.begin(); it != splitCandidates.end(); ++it)
85 splitCandidatesVec.push_back(it->second);
86 splitCandidates.clear();
87 std::sort(splitCandidatesVec.begin(), splitCandidatesVec.end(), std::less<SplitCandidate<T>>());
88 }
89 /* ======================================================================================= */
90
91public:
94
95private:
96 std::map<T, SplitCandidate<T>> splitCandidates;
97 std::vector<SplitCandidate<T>> splitCandidatesVec;
98};
99} // namespace kd_tree
100
101#endif // KDSPLITCANDIDATEMANAGER_H
102
std::vector< SplitCandidate< T > >::size_type size()
void add(const T &pos, const int &axis, const int &starting, const int &ending, const int &np)
SplitCandidate< T > & operator[](const std::size_t &i)
std::shared_ptr< T > SPtr
Definition Axis.h:48