CEPS  24.01
Cardiac ElectroPhysiology Simulator
AbstractSelector.tpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
29 /** @file AbstractSelector.tpp Utility that selects geometric entities with a criterion */
30 #include "geometry/selectors/AbstractSelector.hpp"
31 
32 template <class _Iterator>
33 AbstractSelector<_Iterator>&
34 AbstractSelector<_Iterator>::operator= (const AbstractSelector &that)
35 {
36  if (ceps::isDifferentPtr (this, &that))
37  m_selected = that.m_selected;
38  return *this;
39 }
40 
41 template <class _Iterator>
42 void
43 AbstractSelector<_Iterator>::onlyOnBoundary(CepsBool value)
44 {
45  m_keepOnBoundary = value;
46  return;
47 }
48 
49 template <class _Iterator>
50 void
51 AbstractSelector<_Iterator>::onlyOnThisProc(CepsBool value)
52 {
53  m_keepOnThisProc = value;
54  return;
55 }
56 
57 template <class _Iterator>
58 void
59 AbstractSelector<_Iterator>::appendSelectedTo (CepsVector<Object>* selected)
60 {
61  CEPS_ABORT_IF(ceps::isNullPtr(selected),
62  "Cannot append selection into vector pointed with nullptr"
63  );
64  ceps::pushBack (*selected, m_selected.begin(), m_selected.end());
65  return;
66 }
67 
68 template <class _Iterator>
69 CepsVector<typename AbstractSelector<_Iterator>::Object>
70 AbstractSelector<_Iterator>::getSelected() const
71 {
72  return m_selected;
73 }
74 
75 template <class _Iterator>
76 void
77 AbstractSelector<_Iterator>::clearSelection()
78 {
79  m_selected.clear();
80  return;
81 }
82 
83 template <class _Iterator>
84 void
85 AbstractSelector<_Iterator>::reset()
86 {
87  m_keepOnBoundary = false;
88  m_keepOnThisProc = false;
89  m_selected.clear();
90  return;
91 }
92 
93 template <class _Iterator>
94 AbstractSelector<_Iterator>::AbstractSelector():
95  m_keepOnBoundary(false),
96  m_keepOnThisProc(false)
97 {
98 }
99 
100 template <class _Iterator>
101 void
102 AbstractSelector<_Iterator>::internalRun (Selector *selector, _Iterator first, _Iterator last)
103 {
104  Selector select1 = *selector;
105  if constexpr (std::is_convertible<Object,ceps::HoldsBoundary*>::value)
106  if (m_keepOnBoundary)
107  {
108  select1 = [&] (Object obj) {
109  if (obj->isBoundary())
110  return (*selector)(obj);
111  return false;
112  };
113  }
114 
115  Selector select2 = select1;
116  if constexpr (std::is_convertible<Object,ceps::HoldsProcIds*>::value)
117  if (m_keepOnThisProc)
118  {
119  select2 = [&] (Object obj) {
120  if (obj->getOwner() == ceps::getRank())
121  return select1(obj);
122  return false;
123  };
124  }
125 
126  return internalRun2 (&select2,first,last);
127 }
128 
129 template <class _Iterator>
130 void
131 AbstractSelector<_Iterator>::internalRun2 (Selector *selector, _Iterator first, _Iterator last)
132 {
133  m_selected.clear ();
134  m_selected.reserve (std::distance (first, last));
135  for (_Iterator it = first; it != last; ++it)
136  if ((*selector) (*it))
137  m_selected.push_back (*it);
138  return;
139 }