flippy
a c++20 package for dynamically triangulated membrane simulations.
Loading...
Searching...
No Matches
sim_utils.hpp
1#ifndef FLIPPY_SIM_UTILS_H
2#define FLIPPY_SIM_UTILS_H
3#include <custom_concepts.hpp>
4#include <random>
5#include <optional>
6#include <Nodes.hpp>
7#include <vec3.hpp>
8
9namespace fp{
10
11 [[maybe_unused]] [[nodiscard]] static Real sphere_vol(Real R){return (4._r/3._r)* PI *R*R*R;}
12 [[maybe_unused]] [[nodiscard]] static Real sphere_area(Real R){return 4._r * PI *R*R;}
13
14 [[maybe_unused]] [[nodiscard]] static Real linear_adaptation(Real x, Real x_init, Real x_fin,
15 Real val_init, Real val_fin)
16 {
17 if (x <= x_init) { return val_init; }
18 if (x > x_fin) { return val_fin; }
19// if (std::abs(x_fin-x_init)<0.001){return val_init;}
20 return val_init + (val_fin-val_init)/(x_fin-x_init)*(x-x_init);
21 }
22
23 [[maybe_unused]] [[nodiscard]] static Index steps_for_fixed_speed_adaptation(Real x_init, Real val_init, Real val_fin, Real delta_val)
24 {
25 return static_cast<Index>(std::ceil((val_fin-val_init)/delta_val + x_init));
26 }
27
29 [[maybe_unused]] [[nodiscard]] static Real min_radius_with_non_overlapping_beads(Real min_allowed_distance_between_bead_centers, Index sub_triangulation_iteration_count){
30 Real l_min = min_allowed_distance_between_bead_centers;
31 Real n = static_cast<Real>(sub_triangulation_iteration_count);
32
33 return l_min / (2_r * std::sin(std::asin(1_r / (2_r * std::sin(2_r * PI / 5_r ))) / (n + 1_r)));
34 }
35
37 Real d0_;
38 Real delta_d_;
39 Real p_target_;
40 Real p_accum_{static_cast<Real>(0.f)};
41 Real p_count_{static_cast<Real>(1.f)};
42
43 Real prob(std::optional<Real> e_diff, Real kBT){ return (e_diff.has_value()?std::min(std::exp(e_diff.value()/kBT),1_r):0_r); }
44
45 public:
46 DynamicDisplacementUpdater(Real initial_displacement, Real displacement_adaptation_step_size, Real p_target)
47 : d0_(initial_displacement), delta_d_(displacement_adaptation_step_size), p_target_(p_target) { }
48
49 Real new_displacement_magnitude(){
50 Real p = p_accum_/p_count_;
51 p_accum_ = static_cast<Real>(0.f);
52 p_count_ = static_cast<Real>(1.f);
53 Real dp = p - p_target_;
54 d0_ = d0_ + 0.5f*dp*delta_d_*d0_;
55 return d0_;
56 }
57
58 std::uniform_real_distribution<Real> new_displ_distr(){
59 Real linear_displ = new_displacement_magnitude();
60 return std::uniform_real_distribution<Real>(-linear_displ, linear_displ);
61 }
62
63 void probability_aggregator(std::optional<Real> e_diff, Real kBt){
64 p_accum_ += prob(e_diff, kBt);
65 p_count_ += static_cast<Real>(1.);
66 }
67
68 void reset_target_acceptance_probability(Real p_target){ p_target_ = p_target; }
69 [[nodiscard]] Real target_acceptance_probability() const { return p_target_; }
70
71
72 };
73
74 [[maybe_unused]] [[nodiscard]] static Real node_curvature_squared(Node const& node){
76
87 const vec3<Real> K = node.curvature_vec;
88 const Real C2 = K.norm_square();
89
90 return C2;
91 }
92
93 [[maybe_unused]] [[nodiscard]] static Real node_unit_bending_energy(Node const& node){
95
106 const vec3<Real> K = node.curvature_vec;
107 const Real A = node.area;
108 const Real e = static_cast<Real>(0.5)*A*K.norm_square();
109
110 return e;
111 }
112
113 [[maybe_unused]] [[nodiscard]] static Real changed_neighborhood_bending_energy(Node const& node,
114 fp::Nodes const& nodes,
115 std::vector<Index>const& changed_neighborhood) {
116 fp::Real eb = fp::node_unit_bending_energy(node);
117
118 for (auto node_id: changed_neighborhood) { eb += fp::node_unit_bending_energy(nodes[node_id]); }
119 return eb;
120 }
121
122 namespace TrgMath{
123
124
125 [[maybe_unused]] static Real cot_between_vectors(vec3<Real> const& v1, vec3<Real> const& v2)
126 {
127 return v1.dot(v2)/(v1.cross(v2).norm());
128 };
129
130//
131// /**
132// * given a node `i` and its neighbor `j`, they will share two common neighbor nodes, `p` and `m`.
133// * This function finds the angles at `p` & `m` opposite of `i-j` link.
134// * This function implements the cot(alpha_ij) + cot(beta_ij) from fig. (6c) from [.
135// * The order of these neighbors does not matter for the correct sign of the angles.
136// * @param node_id @NodeIDStub
137// * @param nn_id @NNIDStub
138// * @param cnn_0 common neighbor node 0
139// * @param cnn_1 common neighbor node 1
140// * @return cot(alpha_ij_jm1) + cot(alpha_ij_jp1)
141// */
142// static Real cot_alphas_sum(Node const& node, Node const& nn, Node const& cnn_0, Node const& cnn_1)
143// {
144//
145// vec3<Real> l0_ = node.pos - cnn_0.pos;
146// vec3<Real> l1_ = nn.pos - cnn_0.pos;
147//
148// Real cot_sum = cot_between_vectors(l0_, l1_);
149// l0_ = node.pos - cnn_1.pos;
150// l1_ = nn.pos - cnn_1.pos;
151//
152// cot_sum += cot_between_vectors(l0_, l1_);
153// return cot_sum;
154// }
155 }
156}
157
158
159#endif
This file contains the fp::Node and fp::Nodes classes, data structures that represent a single node o...
Definition sim_utils.hpp:36
Internal implementation of a 3D vector.
Definition vec3.hpp:43
Real norm_square() const
Returns the square of the norm of the vector.
Definition vec3.hpp:175
This file contains the concepts that are costomly defined for the flippy class templates.
Definition custom_concepts.hpp:8
static Real min_radius_with_non_overlapping_beads(Real min_allowed_distance_between_bead_centers, Index sub_triangulation_iteration_count)
N_node=12+30*n+20*n*(n-1)/2 where n is the same as sub_triangulation_iteration_count.
Definition sim_utils.hpp:29
static Real node_curvature_squared(Node const &node)
Definition sim_utils.hpp:74
static Real node_unit_bending_energy(Node const &node)
Definition sim_utils.hpp:93
A data structure containing all geometric and topological information associated with a node.
Definition Nodes.hpp:30
Real area
Voronoi area associated with the node.
Definition Nodes.hpp:45
vec3< Real > curvature_vec
Curvature vector of the node.
Definition Nodes.hpp:71
Data structure containing all nodes of the Triangulation.
Definition Nodes.hpp:225
Header file containing the definition and implementation a 3 dimensional vector class,...