ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ibm_tribend.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include "BoxGeometry.hpp"
23#include "ibm_common.hpp"
24#include "system/System.hpp"
25
26#include <utils/Vector.hpp>
27
28#include <algorithm>
29#include <cmath>
30#include <tuple>
31
32std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
34 Particle const &p2, Particle const &p3,
35 Particle const &p4) const {
36
37 // Get vectors making up the two triangles
38 auto const dx1 = box_geo.get_mi_vector(p1.pos(), p3.pos());
39 auto const dx2 = box_geo.get_mi_vector(p2.pos(), p3.pos());
40 auto const dx3 = box_geo.get_mi_vector(p4.pos(), p3.pos());
41
42 // Get normals on triangle; pointing outwards by definition of indices
43 // sequence
44 auto n1 = vector_product(dx1, dx2);
45 auto n2 = vector_product(dx3, dx1);
46
47 // Get 2*area of triangles out of the magnitude of the resulting normals and
48 // make the latter unity
49 auto const Ai = n1.norm();
50 n1 /= Ai;
51
52 auto const Aj = n2.norm();
53 n2 /= Aj;
54
55 // Get the prefactor for the force term
56 auto const sc = std::min(1.0, n1 * n2);
57
58 // Get theta as angle between normals
59 auto theta = acos(sc);
60
61 auto const direc = vector_product(n1, n2);
62 auto const desc = (dx1 * direc);
63
64 if (desc < 0)
65 theta *= -1;
66
67 auto const DTh = theta - theta0;
68
69 auto Pre = kb * DTh;
70 // Correct version with linearized sin
71 if (theta < 0)
72 Pre *= -1;
73
74 auto const v1 = (n2 - sc * n1).normalize();
75 auto const v2 = (n1 - sc * n2).normalize();
76
77 // Force on particles: eq. (C.28-C.31)
78 auto const force1 =
79 Pre *
80 (vector_product(box_geo.get_mi_vector(p2.pos(), p3.pos()), v1) / Ai +
81 vector_product(box_geo.get_mi_vector(p3.pos(), p4.pos()), v2) / Aj);
82 auto const force2 =
83 Pre *
84 (vector_product(box_geo.get_mi_vector(p3.pos(), p1.pos()), v1) / Ai);
85 auto const force3 =
86 Pre *
87 (vector_product(box_geo.get_mi_vector(p1.pos(), p2.pos()), v1) / Ai +
88 vector_product(box_geo.get_mi_vector(p4.pos(), p1.pos()), v2) / Aj);
89 auto const force4 =
90 Pre *
91 (vector_product(box_geo.get_mi_vector(p1.pos(), p3.pos()), v2) / Aj);
92 return std::make_tuple(force1, force2, force3, force4);
93}
94
95IBMTribend::IBMTribend(const int ind1, const int ind2, const int ind3,
96 const int ind4, const double kb, const bool flat) {
97
98 auto const &box_geo = *System::get_system().box_geo;
99
100 // Compute theta0
101 if (flat) {
102 theta0 = 0;
103 } else {
104 // Get particles
105 auto const pos1 = get_ibm_particle_position(ind1);
106 auto const pos2 = get_ibm_particle_position(ind2);
107 auto const pos3 = get_ibm_particle_position(ind3);
108 auto const pos4 = get_ibm_particle_position(ind4);
109
110 // Get vectors of triangles
111 auto const dx1 = box_geo.get_mi_vector(pos1, pos3);
112 auto const dx2 = box_geo.get_mi_vector(pos2, pos3);
113 auto const dx3 = box_geo.get_mi_vector(pos4, pos3);
114
115 // Get normals on triangle; pointing outwards by definition of indices
116 // sequence
117 auto const n1l = vector_product(dx1, dx2);
118 auto const n2l = -vector_product(dx1, dx3);
119
120 auto const n1 = n1l / n1l.norm();
121 auto const n2 = n2l / n2l.norm();
122
123 // calculate theta0 by taking the acos of the scalar n1*n2
124 auto const sc = std::min(1.0, n1 * n2);
125
126 theta0 = acos(sc);
127
128 auto const desc = dx1 * vector_product(n1, n2);
129 if (desc < 0)
130 theta0 = 2.0 * Utils::pi() - theta0;
131 }
132
133 // NOTE: This is the bare bending modulus used by the program.
134 // If triangle pairs appear only once, the total bending force should get a
135 // factor 2. For the numerical model, a factor sqrt(3) should be added, see
136 // @cite gompper96a and @cite kruger12a. This is an approximation,
137 // it holds strictly only for a sphere
138 this->kb = kb;
139}
Vector implementation and trait types for boost qvm interoperability.
Utils::Vector< T, 3 > get_mi_vector(const Utils::Vector< T, 3 > &a, const Utils::Vector< T, 3 > &b) const
Get the minimum-image vector between two coordinates.
std::shared_ptr< BoxGeometry > box_geo
__device__ void vector_product(float const *a, float const *b, float *out)
Utils::Vector3d get_ibm_particle_position(int pid)
Returns the position of a given particle.
System & get_system()
DEVICE_QUALIFIER constexpr T pi()
Ratio of diameter and circumference of a circle.
Definition constants.hpp:36
double theta0
Reference angle.
IBMTribend(int ind1, int ind2, int ind3, int ind4, double kb, bool flat)
Set the IBM Tribend parameters.
double kb
Interaction data.
std::tuple< Utils::Vector3d, Utils::Vector3d, Utils::Vector3d, Utils::Vector3d > calc_forces(BoxGeometry const &box_geo, Particle const &p1, Particle const &p2, Particle const &p3, Particle const &p4) const
Calculate the forces The equations can be found in Appendix C of .
Struct holding all information for one particle.
Definition Particle.hpp:393
auto const & pos() const
Definition Particle.hpp:429