CellModules
elasticconnection.hpp
Go to the documentation of this file.
1#ifndef MECACELL_ELASTICCONNECTION_HPP
2#define MECACELL_ELASTICCONNECTION_HPP
3#include <cmath>
4#include <utility>
5#include "spring.hpp"
8
9namespace MecaCell {
15template <typename Cell> struct ElasticConnection {
17 double area = 0; // area of the contact disk
18 double adhArea = 0; // connected area
19 double overlap = 0, adhOverlap = 0;
20 double bondBreakDist = 2.0;
21 std::pair<double, double>
22 midpoint; // contact disk's distance to center (viewed from each cell)
23 Vector3D direction; // normalized direction from cell 0 to cell 1
24 double prevDist; // distance btwn the two cells
25 double dist; // distance btwn the two cells
26 std::pair<Joint, Joint> flex, tors;
27 bool adhesionEnabled = false;
28 bool fixedAdhesion = false; // is this connection indestructible ?
29
32
34 direction = cells.second->getPosition() - cells.first->getPosition();
35 prevDist = dist;
37 if (dist > 0) direction /= dist;
39 }
40
41 std::pair<double, double> computeMidpoints() {
42 // return the current contact disk's center distance to each cells centers
43 if (dist <= Config::DOUBLE_EPSILON) return {0, 0};
44
45 auto biggestCell = cells.first->getBody().getBoundingBoxRadius() >=
46 cells.second->getBody().getBoundingBoxRadius() ?
47 cells.first :
48 cells.second;
49 auto smallestCell = biggestCell == cells.first ? cells.second : cells.first;
50
51 double biggestCellMidpoint =
52 0.5 * (dist +
53 (std::pow(biggestCell->getBody().getBoundingBoxRadius(), 2) -
54 std::pow(smallestCell->getBody().getBoundingBoxRadius(), 2)) /
55 dist);
56 double smallestCellMidpoint = dist - biggestCellMidpoint;
57 if (biggestCell == cells.first)
58 return {biggestCellMidpoint, smallestCellMidpoint};
59 else
60 return {smallestCellMidpoint, biggestCellMidpoint};
61 }
62
64 overlap = max(0.0, (cells.first->getBoundingBoxRadius() +
65 cells.second->getBoundingBoxRadius()) -
66 dist);
67 const auto &c0 = cells.first->getBody();
68 const auto &c1 = cells.first->getBody();
69 double invertRadii = 1.0 / (1.0 / cells.first->getBoundingBoxRadius() +
70 1.0 / cells.second->getBoundingBoxRadius());
71 double invertYoung =
72 1.0 / (((1.0 - pow(c0.getPoissonCoef(), 2)) / c0.getYoungModulus()) +
73 ((1.0 - pow(c1.getPoissonCoef(), 2)) / c1.getYoungModulus()));
74 double tempterm = sqrt(invertRadii) * pow(overlap, 3.0 / 2.0);
75 area = pow(cbrt(invertRadii * tempterm), 2) * M_PI;
76 auto F = direction * ((2.0 / 3.0) * invertYoung * tempterm);
77 cells.first->getBody().receiveForce(-F);
78 cells.second->getBody().receiveForce(F);
79 }
80
81 void updateAdhesionForces(double) {
82 /*
83 dir
84 x---->
85
86 * * * *
87 * pf1t2 * * pf2t1 *
88 * <--x * x--> *
89 * * *
90 * * * *
91 * * * *
92 c1 c2
93
94 */
95
96 //const double adhCoef = 0.1;
97 //double resistiveForce = area * adhCoef;
98
99 // first we compute the force's component parrallel to the collision axis
100 // and only the forces trying to separate the cells
101 double parallelForce1to2 =
102 std::max(-cells.first->getBody().getForce().dot(direction), 0.0);
103 double parallelForce2to1 =
104 std::max(cells.second->getBody().getForce().dot(direction), 0.0);
105 double sum = parallelForce2to1 + parallelForce1to2;
106 logger<DBG>("pf2t1 = ", parallelForce2to1);
107 logger<DBG>("pf1t2 = ", parallelForce1to2);
108 cells.first->getBody().receiveForce(parallelForce2to1 * direction);
109 cells.second->getBody().receiveForce(-parallelForce1to2 * direction);
110 logger<DBG>("sum = ", sum);
111 }
112
113 void init() {
115 prevDist = dist;
116 }
117 void update(double dt) {
120 if (adhesionEnabled) {
122 }
123 }
124};
125}
126#endif
general purpose 3D vector/point class.
Definition: vector3D.h:20
double length() const
compute the length of the vector
Definition: vector3D.h:257
this file contains various miscellanious utility functions & helpers *
double cbrt(double x)
Computes the cube root of a number.
Definition: std.hpp:215
double sqrt(double x)
Computes the square root of a number.
Definition: std.hpp:32
double pow(double base, double exponent)
Computes the power of a number.
Definition: std.hpp:43
static constexpr double DOUBLE_EPSILON
max distance for two doubles to be considered equals (only used for some geometric operations)
Definition: config.hpp:22
An Elastic Connection is a connection between two cells.
std::pair< double, double > midpoint
std::pair< Joint, Joint > flex
std::pair< double, double > computeMidpoints()
std::pair< Joint, Joint > tors
ElasticConnection(ordered_pair< Cell * > c)
ordered_pair< Cell * > cells