CellModules
springbody.hpp
Go to the documentation of this file.
1#ifndef SPRINGBODY_HPP
2#define SPRINGBODY_HPP
5#include "integrators.hpp"
6#include "orientable.h"
7#include "spring.hpp"
13
14namespace MecaCell {
15template <typename Cell> class SpringBody : public OrientedParticle {
17
18 Cell *cell = nullptr;
19
20 public:
21 double radius = Config::DEFAULT_CELL_RADIUS; // radius of the cell when at rest
22 double stiffness = Config::DEFAULT_CELL_STIFFNESS; // cell's body stiffness
23
27 void setRadius(double r) { radius = r; }
28 double getRadius() { return radius; }
29 double getBoundingBoxRadius() const { return radius; };
30 double getStiffness() const { return stiffness; }
31 void setStiffness(double k) { stiffness = k; }
32 double getMomentOfInertia() const { return 0.4 * this->mass * radius * radius; }
33 template <typename Integrator = Euler> void updatePositionsAndOrientations(double dt) {
34 Integrator::updatePosition(*this, dt);
35 Integrator::updateOrientation(*this, getMomentOfInertia(), dt);
36 }
37
38 std::tuple<Cell *, double> getConnectedCellAndMembraneDistance(const Vec &d) const {
39 // /!\ assumes that d is normalized
40 Cell *closestCell = nullptr;
41 double closestDist = radius;
42 for (auto &con : cellConnections) {
43 auto normal = cell == con->cells.first ? -con->direction : con->direction;
44 double dot = normal.dot(d);
45 if (dot < 0) {
46 const auto &midpoint =
47 cell == con->cells.first ? con->midpoint.first : con->midpoint.second;
48 double l = -midpoint / dot;
49 if (l < closestDist) {
50 closestDist = l;
51 closestCell = con->cells.first == cell ? con->cells.second : con->cells.first;
52 }
53 }
54 }
55 return std::make_tuple(closestCell, closestDist);
56 }
57
58 inline Cell *getConnectedCell(const Vec &d) const {
60 }
61
62 // required by GenericConnection Plugin
63 inline double getPreciseMembraneDistance(const Vec &d) const {
65 }
66
67 void moveTo(Vector3D newpos) { this->setPosition(newpos); }
68 void updateInternals(double) {}
69
71};
72} // namespace MecaCell
73#endif
MecaCell::Vec pos
Definition: CellBody.hpp:34
void setPosition(const Vec &p)
Definition: movable.h:31
void moveTo(Vector3D newpos)
Definition: springbody.hpp:67
EXPORTABLE(SpringBody, KV(radius), KV(position))
void setStiffness(double k)
Definition: springbody.hpp:31
Cell * getConnectedCell(const Vec &d) const
Definition: springbody.hpp:58
SpringBody(Cell *c, Vector3D pos=Vector3D::zero())
Definition: springbody.hpp:26
double getStiffness() const
Definition: springbody.hpp:30
void updatePositionsAndOrientations(double dt)
Definition: springbody.hpp:33
double getPreciseMembraneDistance(const Vec &d) const
Definition: springbody.hpp:63
double getMomentOfInertia() const
Definition: springbody.hpp:32
std::vector< SpringConnection< Cell > * > cellConnections
Definition: springbody.hpp:24
double getBoundingBoxRadius() const
Definition: springbody.hpp:29
void updateInternals(double)
Definition: springbody.hpp:68
std::tuple< Cell *, double > getConnectedCellAndMembraneDistance(const Vec &d) const
Definition: springbody.hpp:38
void setRadius(double r)
Definition: springbody.hpp:27
general purpose 3D vector/point class.
Definition: vector3D.h:20
static Vector3D zero()
constructs a zero vector
Definition: vector3D.h:170
Represents a cell in the simulation.
Definition: PrimoCell.hpp:53
A simple vector class template.
Definition: std.hpp:290
#define KV(p)
Definition: exportable.hpp:30
this file contains various miscellanious utility functions & helpers *
static constexpr double DEFAULT_CELL_RADIUS
Definition: config.hpp:12
static constexpr double DEFAULT_CELL_STIFFNESS
Definition: config.hpp:14
A Spring Connection is a connection between two cells that aims to models both attractive (for adhesi...