votca 2024.1-dev
Loading...
Searching...
No Matches
nblist_3body.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_3BODY_H
19#define VOTCA_CSG_NBLIST_3BODY_H
20
21// Local VOTCA includes
22#include "beadlist.h"
23#include "beadtriple.h"
24#include "exclusionlist.h"
25#include "triplelist.h"
26
27namespace votca {
28namespace csg {
29
42class NBList_3Body : public TripleList<Bead *, BeadTriple> {
43 public:
45 ~NBList_3Body() override;
46
49 virtual void Generate(BeadList &list1, BeadList &list2, BeadList &list3,
50 bool do_exclusions = true);
54 virtual void Generate(BeadList &list1, BeadList &list2,
55 bool do_exclusions = true) {
56 Generate(list1, list2, list2, do_exclusions);
57 };
60 virtual void Generate(BeadList &list, bool do_exclusions = true) {
61 Generate(list, list, list, do_exclusions);
62 }
63
66 void setCutoff(const double cutoff) { cutoff_ = cutoff; }
68 double getCutoff() { return cutoff_; }
69
85 template <typename T>
87 T *object, bool (T::*fkt)(Bead *, Bead *, Bead *, const Eigen::Vector3d &,
88 const Eigen::Vector3d &,
89 const Eigen::Vector3d &, const double dist12,
90 const double dist13, const double dist23));
91
93 void SetMatchFunction(bool (*fkt)(
94 Bead *, Bead *, Bead *, const Eigen::Vector3d &, const Eigen::Vector3d &,
95 const Eigen::Vector3d &, const double dist12, const double dist13,
96 const double dist23));
97
99 static bool match_always(Bead *, Bead *, Bead *, const Eigen::Vector3d &,
100 const Eigen::Vector3d &, const Eigen::Vector3d &,
101 const double, const double, const double) {
102 return true;
103 }
104
106 template <typename triple_type>
107 void setTripleType();
108
109 protected:
111 double cutoff_;
114
116 template <typename triple_type>
118 Bead *bead3,
119 const Eigen::Vector3d &r12,
120 const Eigen::Vector3d &r13,
121 const Eigen::Vector3d &r23) {
122 return dynamic_cast<BeadTriple *>(
123 new triple_type(bead1, bead2, bead3, r12, r13, r23));
124 }
125
127 const Eigen::Vector3d &,
128 const Eigen::Vector3d &,
129 const Eigen::Vector3d &);
132
133 protected:
136 class Functor {
137 public:
138 Functor() = default;
139 virtual bool operator()(Bead *, Bead *, Bead *, const Eigen::Vector3d &,
140 const Eigen::Vector3d &, const Eigen::Vector3d &,
141 const double dist12, const double dist13,
142 const double dist23) = 0;
143 virtual ~Functor() = default;
144 };
145
147 template <typename T>
148 class FunctorMember : public Functor {
149 public:
150 using fkt_t = bool (T::*)(Bead *, Bead *, Bead *, const Eigen::Vector3d &,
151 const Eigen::Vector3d &, const Eigen::Vector3d &,
152 const double, const double, const double);
153
154 FunctorMember(T *cls, fkt_t fkt) : cls_(cls), fkt_(fkt) {}
155
156 bool operator()(Bead *b1, Bead *b2, Bead *b3, const Eigen::Vector3d &r12,
157 const Eigen::Vector3d &r13, const Eigen::Vector3d &r23,
158 const double dist12, const double dist13,
159 const double dist23) override {
160 return (cls_->*fkt_)(b1, b2, b3, r12, r13, r23, dist12, dist13, dist23);
161 }
162
163 private:
166 };
167
169 class FunctorNonMember : public Functor {
170 public:
171 using fkt_t = bool (*)(Bead *, Bead *, Bead *, const Eigen::Vector3d &,
172 const Eigen::Vector3d &, const Eigen::Vector3d &,
173 const double, const double, const double);
175
176 bool operator()(Bead *b1, Bead *b2, Bead *b3, const Eigen::Vector3d &r12,
177 const Eigen::Vector3d &r13, const Eigen::Vector3d &r23,
178 const double dist12, const double dist13,
179 const double dist23) override {
180 return (*fkt_)(b1, b2, b3, r12, r13, r23, dist12, dist13, dist23);
181 }
182
183 private:
185 };
186
187 std::unique_ptr<Functor> match_function_;
188};
189
190template <typename triple_type>
192 triple_creator_ = NBList_3Body::beadtriple_create_policy<triple_type>;
193}
194
195template <typename T>
197 T *object, bool (T::*fkt)(Bead *, Bead *, Bead *, const Eigen::Vector3d &,
198 const Eigen::Vector3d &, const Eigen::Vector3d &,
199 const double dist12, const double dist13,
200 const double dist23)) {
201
202 match_function_.reset(new FunctorMember<T>(object, fkt));
203}
204
205inline void NBList_3Body::SetMatchFunction(bool (*fkt)(
206 Bead *, Bead *, Bead *, const Eigen::Vector3d &, const Eigen::Vector3d &,
207 const Eigen::Vector3d &, const double dist12, const double dist13,
208 const double dist23)) {
209 match_function_.reset(new FunctorNonMember(fkt));
210}
211
212} // namespace csg
213} // namespace votca
214
215#endif // VOTCA_CSG_NBLIST_3BODY_H
A triplet of tree Beads.
Definition beadtriple.h:32
information about a bead
Definition bead.h:50
Functor for member functions.
bool operator()(Bead *b1, Bead *b2, Bead *b3, const Eigen::Vector3d &r12, const Eigen::Vector3d &r13, const Eigen::Vector3d &r23, const double dist12, const double dist13, const double dist23) override
bool(T::*)(Bead *, Bead *, Bead *, const Eigen::Vector3d &, const Eigen::Vector3d &, const Eigen::Vector3d &, const double, const double, const double) fkt_t
Functor for non-member functions.
bool operator()(Bead *b1, Bead *b2, Bead *b3, const Eigen::Vector3d &r12, const Eigen::Vector3d &r13, const Eigen::Vector3d &r23, const double dist12, const double dist13, const double dist23) override
bool(*)(Bead *, Bead *, Bead *, const Eigen::Vector3d &, const Eigen::Vector3d &, const Eigen::Vector3d &, const double, const double, const double) fkt_t
virtual bool operator()(Bead *, Bead *, Bead *, const Eigen::Vector3d &, const Eigen::Vector3d &, const Eigen::Vector3d &, const double dist12, const double dist13, const double dist23)=0
Neighbour list class for 3 body interactions.
void setCutoff(const double cutoff)
double getCutoff()
get the cutoff for the neighbour search
virtual void Generate(BeadList &list, bool do_exclusions=true)
bool do_exclusions_
take into account exclusions from topolgoy
static bool match_always(Bead *, Bead *, Bead *, const Eigen::Vector3d &, const Eigen::Vector3d &, const Eigen::Vector3d &, const double, const double, const double)
standard match function
void SetMatchFunction(T *object, bool(T::*fkt)(Bead *, Bead *, Bead *, const Eigen::Vector3d &, const Eigen::Vector3d &, const Eigen::Vector3d &, const double dist12, const double dist13, const double dist23))
match function for class member functions
static BeadTriple * beadtriple_create_policy(Bead *bead1, Bead *bead2, Bead *bead3, const Eigen::Vector3d &r12, const Eigen::Vector3d &r13, const Eigen::Vector3d &r23)
policy function to create new bead types
triple_creator_t triple_creator_
the current bead pair creator function
std::unique_ptr< Functor > match_function_
virtual void Generate(BeadList &list1, BeadList &list2, bool do_exclusions=true)
BeadTriple *(*)(Bead *, Bead *, Bead *, const Eigen::Vector3d &, const Eigen::Vector3d &, const Eigen::Vector3d &) triple_creator_t
virtual void Generate(BeadList &list1, BeadList &list2, BeadList &list3, bool do_exclusions=true)
void setTripleType()
function to use a user defined triple type
double cutoff_
cutoff (at the moment use only one cutoff value)
base class for all analysis tools
Definition basebead.h:33