Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tf_dpd_eval.h
1/*******************************************************************************
2 * This file is part of mdcore.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20#ifndef _MDCORE_SOURCE_TF_DPD_EVAL_H_
21#define _MDCORE_SOURCE_TF_DPD_EVAL_H_
22
23#include <tfPotential.h>
24#include <tfDPDPotential.h>
25#include "tf_smoothing_kernel.h"
26#include <random>
27
28
29namespace TissueForge {
30
31
32 TF_ALWAYS_INLINE bool dpd_eval(DPDPotential *p, FPTYPE gaussian,
33 Particle *pi, Particle *pj, FPTYPE* dx, FPTYPE r2, FPTYPE *energy)
34 {
35
36 static const FPTYPE delta = 1.f / std::sqrt(_Engine.dt);
37 static const FPTYPE epsilon = std::numeric_limits<FPTYPE>::epsilon();
38
39 FPTYPE r = std::sqrt(r2);
40 FPTYPE ro = r < epsilon ? epsilon : r;
41
42 r = p->flags & POTENTIAL_SHIFTED ? r - (pi->radius + pj->radius) : r;
43
44 if(r > p->b) {
45 return false;
46 }
47 r = r >= p->a ? r : p->a;
48
49 // unit vector
50 FVector3 e = {dx[0] / ro, dx[1] / ro, dx[2] / ro};
51
52 FVector3 v = pi->velocity - pj->velocity;
53
54 // conservative force
55 FPTYPE omega_c = r < 0.f ? 1.f : (1 - r / p->b);
56
57 FPTYPE fc = p->alpha * omega_c;
58
59 // dissapative force
60 FPTYPE omega_d = omega_c * omega_c;
61
62 FPTYPE fd = -p->gamma * omega_d * e.dot(v);
63
64 FPTYPE fr = p->sigma * omega_c * delta;
65
66 FPTYPE f = fc + fd + fr;
67
68 pj->force = {pj->f[0] - f * e[0], pj->f[1] - f * e[1], pj->f[2] - f * e[2] };
69
70 pi->force = {pi->f[0] + f * e[0], pi->f[1] + f * e[1], pi->f[2] + f * e[2] };
71
72 // TODO: correct energy
73 *energy = 0;
74
75 return true;
76 }
77
78 TF_ALWAYS_INLINE bool dpd_boundary_eval(DPDPotential *p, FPTYPE gaussian,
79 Particle *pi, FPTYPE &rj, const FPTYPE *velocity, const FPTYPE* dx, FPTYPE r2, FPTYPE *energy)
80 {
81
82 static const FPTYPE delta = 1.f / std::sqrt(_Engine.dt);
83 static const FPTYPE epsilon = std::numeric_limits<FPTYPE>::epsilon();
84
85 FPTYPE r = std::sqrt(r2);
86 FPTYPE ro = r < epsilon ? epsilon : r;
87
88 r = p->flags & POTENTIAL_SHIFTED ? r - (pi->radius + rj) : r;
89
90 if(r > p->b) {
91 return false;
92 }
93 r = r >= p->a ? r : p->a;
94
95 // unit vector
96 FVector3 e = {dx[0] / ro, dx[1] / ro, dx[2] / ro};
97
98 FVector3 v = {pi->velocity[0] - velocity[0], pi->velocity[1] - velocity[1], pi->velocity[2] - velocity[2]};
99
100 // conservative force
101 FPTYPE omega_c = r < 0.f ? 1.f : (1 - r / p->b);
102
103 FPTYPE fc = p->alpha * omega_c;
104
105 // dissapative force
106 FPTYPE omega_d = omega_c * omega_c;
107
108 FPTYPE fd = -p->gamma * omega_d * e.dot(v);
109
110 FPTYPE fr = p->sigma * omega_c * delta;
111
112 FPTYPE f = fc + fd + fr;
113
114 pi->force = {pi->f[0] + f * e[0], pi->f[1] + f * e[1], pi->f[2] + f * e[2] };
115
116 // TODO: correct energy
117 *energy = 0;
118
119 return true;
120 }
121
122};
123
124#endif // _MDCORE_SOURCE_TF_DPD_EVAL_H_
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
engine _Engine
@ POTENTIAL_SHIFTED
Definition tfPotential.h:92
Definition tfDPDPotential.h:36
Definition tfParticle.h:101