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"
24#include "ibm_common.hpp"
25
26#include <utils/Vector.hpp>
27
28#include <algorithm>
29#include <cmath>
30#include <numbers>
31#include <tuple>
32
33std::tuple<Utils::Vector3d, Utils::Vector3d, Utils::Vector3d, Utils::Vector3d>
35 Particle const &p2, Particle const &p3,
36 Particle const &p4) const {
37
38 // Get vectors making up the two triangles
39 auto const dx1 = box_geo.get_mi_vector(p1.pos(), p3.pos());
40 auto const dx2 = box_geo.get_mi_vector(p2.pos(), p3.pos());
41 auto const dx3 = box_geo.get_mi_vector(p4.pos(), p3.pos());
42
43 // Get normals on triangle; pointing outwards by definition of indices
44 // sequence
45 auto n1 = vector_product(dx1, dx2);
46 auto n2 = vector_product(dx3, dx1);
47
48 // Get 2*area of triangles out of the magnitude of the resulting normals and
49 // make the latter unity
50 auto const Ai = n1.norm();
51 n1 /= Ai;
52
53 auto const Aj = n2.norm();
54 n2 /= Aj;
55
56 // Get the prefactor for the force term
57 auto const sc = std::min(1.0, n1 * n2);
58
59 // Get theta as angle between normals
60 auto theta = acos(sc);
61
62 auto const direc = vector_product(n1, n2);
63 auto const desc = (dx1 * direc);
64
65 if (desc < 0)
66 theta *= -1;
67
68 auto const DTh = theta - theta0;
69
70 auto Pre = kb * DTh;
71 // Correct version with linearized sin
72 if (theta < 0)
73 Pre *= -1;
74
75 auto const v1 = (n2 - sc * n1).normalize();
76 auto const v2 = (n1 - sc * n2).normalize();
77
78 // Force on particles: eq. (C.28-C.31)
79 auto const force1 =
80 Pre *
81 (vector_product(box_geo.get_mi_vector(p2.pos(), p3.pos()), v1) / Ai +
82 vector_product(box_geo.get_mi_vector(p3.pos(), p4.pos()), v2) / Aj);
83 auto const force2 =
84 Pre *
85 (vector_product(box_geo.get_mi_vector(p3.pos(), p1.pos()), v1) / Ai);
86 auto const force3 =
87 Pre *
88 (vector_product(box_geo.get_mi_vector(p1.pos(), p2.pos()), v1) / Ai +
89 vector_product(box_geo.get_mi_vector(p4.pos(), p1.pos()), v2) / Aj);
90 auto const force4 =
91 Pre *
92 (vector_product(box_geo.get_mi_vector(p1.pos(), p3.pos()), v2) / Aj);
93 return std::make_tuple(force1, force2, force3, force4);
94}
95
97 CellStructure const &cell_structure) {
98 if (is_initialized) {
99 return;
100 }
101 // Compute theta0
102 if (flat) {
103 theta0 = 0.;
104 } else {
105 // Get particles
106 auto const [ind1, ind2, ind3, ind4] = p_ids;
107 auto const pos1 = get_ibm_particle_position(cell_structure, ind1);
108 auto const pos2 = get_ibm_particle_position(cell_structure, ind2);
109 auto const pos3 = get_ibm_particle_position(cell_structure, ind3);
110 auto const pos4 = get_ibm_particle_position(cell_structure, ind4);
111
112 // Get vectors of triangles
113 auto const dx1 = box_geo.get_mi_vector(pos1, pos3);
114 auto const dx2 = box_geo.get_mi_vector(pos2, pos3);
115 auto const dx3 = box_geo.get_mi_vector(pos4, pos3);
116
117 // Get normals on triangle; pointing outwards by definition of indices
118 // sequence
119 auto const n1l = vector_product(dx1, dx2);
120 auto const n2l = -vector_product(dx1, dx3);
121
122 auto const n1 = n1l / n1l.norm();
123 auto const n2 = n2l / n2l.norm();
124
125 // calculate theta0 by taking the acos of the scalar n1*n2
126 auto const sc = std::min(1., n1 * n2);
127
128 theta0 = acos(sc);
129
130 auto const desc = dx1 * vector_product(n1, n2);
131 if (desc < 0.)
132 theta0 = 2. * std::numbers::pi - theta0;
133 }
134 is_initialized = true;
135}
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.
__device__ void vector_product(float const *a, float const *b, float *out)
Utils::Vector3d get_ibm_particle_position(CellStructure const &cell_structure, int pid)
Returns the position of a given particle.
Describes a cell structure / cell system.
std::tuple< int, int, int, int > p_ids
Particle ids.
double theta0
Reference angle.
double kb
Bare bending modulus.
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 .
void initialize(BoxGeometry const &box_geo, CellStructure const &cell_structure)
Set the IBM Tribend parameters.
bool is_initialized
Struct holding all information for one particle.
Definition Particle.hpp:395
auto const & pos() const
Definition Particle.hpp:431