votca 2024.2-dev
Loading...
Searching...
No Matches
nblist.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#ifndef VOTCA_CSG_NBLIST_H
19#define VOTCA_CSG_NBLIST_H
20
21// Local VOTCA includes
22#include "beadlist.h"
23#include "beadpair.h"
24#include "exclusionlist.h"
25#include "pairlist.h"
26
27namespace votca {
28namespace csg {
29
39class NBList : public PairList<Bead *, BeadPair> {
40 public:
41 NBList();
42 ~NBList() override;
43
45 virtual void Generate(BeadList &list1, BeadList &list2,
46 bool do_exclusions = true);
48 virtual void Generate(BeadList &list, bool do_exclusions = true) {
49 Generate(list, list, do_exclusions);
50 }
51
53 void setCutoff(double cutoff) { cutoff_ = cutoff; }
55 double getCutoff() const { return cutoff_; }
56
71 template <typename T>
72 void SetMatchFunction(T *object,
73 bool (T::*fkt)(Bead *, Bead *, const Eigen::Vector3d &,
74 double dist));
75
77 void SetMatchFunction(bool (*fkt)(Bead *, Bead *, const Eigen::Vector3d &,
78 double));
79
81 static bool match_always(Bead *, Bead *, const Eigen::Vector3d &, double) {
82 return true;
83 }
84
86 template <typename pair_type>
87 void setPairType();
88
89 protected:
91 double cutoff_;
94
96 template <typename pair_type>
97 static BeadPair *beadpair_create_policy(Bead *bead1, Bead *bead2,
98 const Eigen::Vector3d &r) {
99 return dynamic_cast<BeadPair *>(new pair_type(bead1, bead2, r));
100 }
101
102 using pair_creator_t = BeadPair *(*)(Bead *, Bead *, const Eigen::Vector3d &);
105
106 protected:
109 class Functor {
110 public:
111 Functor() = default;
112 virtual bool operator()(Bead *, Bead *, const Eigen::Vector3d &,
113 const double dist) = 0;
114 virtual ~Functor() = default;
115 };
116
118 template <typename T>
119 class FunctorMember : public Functor {
120 public:
121 using fkt_t = bool (T::*)(Bead *, Bead *, const Eigen::Vector3d &, double);
122
123 FunctorMember(T *cls, fkt_t fkt) : cls_(cls), fkt_(fkt) {}
124
125 bool operator()(Bead *b1, Bead *b2, const Eigen::Vector3d &r,
126 double dist) override {
127 return (cls_->*fkt_)(b1, b2, r, dist);
128 }
129
130 private:
133 };
134
136 class FunctorNonMember : public Functor {
137 public:
138 using fkt_t = bool (*)(Bead *, Bead *, const Eigen::Vector3d &, double);
140
141 bool operator()(Bead *b1, Bead *b2, const Eigen::Vector3d &r,
142 double dist) override {
143 return (*fkt_)(b1, b2, r, dist);
144 }
145
146 private:
148 };
149
150 std::unique_ptr<Functor> match_function_;
151};
152
153template <typename pair_type>
157
158template <typename T>
159inline void NBList::SetMatchFunction(T *object,
160 bool (T::*fkt)(Bead *, Bead *,
161 const Eigen::Vector3d &,
162 double)) {
163 match_function_.reset(new FunctorMember<T>(object, fkt));
164}
165
166inline void NBList::SetMatchFunction(bool (*fkt)(Bead *, Bead *,
167 const Eigen::Vector3d &,
168 double)) {
169 match_function_.reset(new FunctorNonMember(fkt));
170}
171
172} // namespace csg
173} // namespace votca
174
175#endif // VOTCA_CSG_NBLIST_H
A particle pair.
Definition beadpair.h:35
information about a bead
Definition bead.h:50
Functor for member functions.
Definition nblist.h:119
bool operator()(Bead *b1, Bead *b2, const Eigen::Vector3d &r, double dist) override
Definition nblist.h:125
bool(T::*)(Bead *, Bead *, const Eigen::Vector3d &, double) fkt_t
Definition nblist.h:121
FunctorMember(T *cls, fkt_t fkt)
Definition nblist.h:123
Functor for non-member functions.
Definition nblist.h:136
bool(*)(Bead *, Bead *, const Eigen::Vector3d &, double) fkt_t
Definition nblist.h:138
bool operator()(Bead *b1, Bead *b2, const Eigen::Vector3d &r, double dist) override
Definition nblist.h:141
virtual ~Functor()=default
virtual bool operator()(Bead *, Bead *, const Eigen::Vector3d &, const double dist)=0
Neighbour list class.
Definition nblist.h:39
virtual void Generate(BeadList &list1, BeadList &list2, bool do_exclusions=true)
Generate the neighbour list based on two bead lists (e.g. bead types)
Definition nblist.cc:37
std::unique_ptr< Functor > match_function_
Definition nblist.h:150
virtual void Generate(BeadList &list, bool do_exclusions=true)
Generate the neighbour list based on a single bead list.
Definition nblist.h:48
bool do_exclusions_
take into account exclusions from topolgoy
Definition nblist.h:93
BeadPair *(*)(Bead *, Bead *, const Eigen::Vector3d &) pair_creator_t
Definition nblist.h:102
~NBList() override
Definition nblist.cc:33
void setPairType()
function to use a user defined pair type
Definition nblist.h:154
double getCutoff() const
get the cutoff for the neighbour search
Definition nblist.h:55
void SetMatchFunction(T *object, bool(T::*fkt)(Bead *, Bead *, const Eigen::Vector3d &, double dist))
match function for class member functions
Definition nblist.h:159
void setCutoff(double cutoff)
set the cutoff for the neighbour search
Definition nblist.h:53
static BeadPair * beadpair_create_policy(Bead *bead1, Bead *bead2, const Eigen::Vector3d &r)
policy function to create new bead types
Definition nblist.h:97
static bool match_always(Bead *, Bead *, const Eigen::Vector3d &, double)
standard match function
Definition nblist.h:81
pair_creator_t pair_creator_
the current bead pair creator function
Definition nblist.h:104
double cutoff_
cutoff
Definition nblist.h:91
base class for all analysis tools
Definition basebead.h:33