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 const direc = vector_product(n1, n2);
61 auto const desc = (dx1 * direc);
62 auto const theta = std::acos(sc) * std::copysign(1., desc);
63
64 auto const DTh = theta - theta0;
65 auto const Pre = kb * DTh * std::copysign(1., theta);
66
67 auto const v1 = (n2 - sc * n1).normalize();
68 auto const v2 = (n1 - sc * n2).normalize();
69
70 // Force on particles: eq. (C.28-C.31)
71 auto const force1 =
72 Pre *
73 (vector_product(box_geo.get_mi_vector(p2.pos(), p3.pos()), v1) / Ai +
74 vector_product(box_geo.get_mi_vector(p3.pos(), p4.pos()), v2) / Aj);
75 auto const force2 =
76 Pre *
77 (vector_product(box_geo.get_mi_vector(p3.pos(), p1.pos()), v1) / Ai);
78 auto const force3 =
79 Pre *
80 (vector_product(box_geo.get_mi_vector(p1.pos(), p2.pos()), v1) / Ai +
81 vector_product(box_geo.get_mi_vector(p4.pos(), p1.pos()), v2) / Aj);
82 auto const force4 =
83 Pre *
84 (vector_product(box_geo.get_mi_vector(p1.pos(), p3.pos()), v2) / Aj);
85 return std::make_tuple(force1, force2, force3, force4);
86}
87
89 CellStructure const &cell_structure) {
90 if (is_initialized) {
91 return;
92 }
93 // Compute theta0
94 if (flat) {
95 theta0 = 0.;
96 } else {
97 // Get particles
98 auto const [ind1, ind2, ind3, ind4] = p_ids;
99 auto const pos1 = get_ibm_particle_position(cell_structure, ind1);
100 auto const pos2 = get_ibm_particle_position(cell_structure, ind2);
101 auto const pos3 = get_ibm_particle_position(cell_structure, ind3);
102 auto const pos4 = get_ibm_particle_position(cell_structure, ind4);
103
104 // Get vectors of triangles
105 auto const dx1 = box_geo.get_mi_vector(pos1, pos3);
106 auto const dx2 = box_geo.get_mi_vector(pos2, pos3);
107 auto const dx3 = box_geo.get_mi_vector(pos4, pos3);
108
109 // Get normals on triangle; pointing outwards by definition of indices
110 // sequence
111 auto const n1l = vector_product(dx1, dx2);
112 auto const n2l = -vector_product(dx1, dx3);
113
114 auto const n1 = n1l / n1l.norm();
115 auto const n2 = n2l / n2l.norm();
116
117 // calculate theta0 by taking the acos of the scalar n1*n2
118 auto const sc = std::min(1., n1 * n2);
119
120 theta0 = std::acos(sc);
121
122 auto const desc = dx1 * vector_product(n1, n2);
123 theta0 = (desc < 0.) ? 2. * std::numbers::pi - theta0 : theta0;
124 }
125 is_initialized = true;
126}
Vector implementation and trait types for boost qvm interoperability.
ESPRESSO_ATTR_ALWAYS_INLINE 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.
Describes a cell structure / cell system.
__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.
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:450
auto const & pos() const
Definition Particle.hpp:486