Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfPotential.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of mdcore.
3 * Coypright (c) 2010 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
4 * Coypright (c) 2017 Andy Somogyi (somogyie at indiana dot edu)
5 * Copyright (c) 2022-2024 T.J. Sego
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ******************************************************************************/
21
26
27#ifndef _MDCORE_INCLUDE_TFPOTENTIAL_H_
28#define _MDCORE_INCLUDE_TFPOTENTIAL_H_
29
30#include "tf_platform.h"
31#include "tf_fptype.h"
32#include <io/tf_io.h>
33
34#include <limits>
35#include <utility>
36#include <vector>
37
38/* some constants */
39#define potential_degree 5
40#define potential_chunk (potential_degree+3)
41#define potential_ivalsa 1
42#define potential_ivalsb 10
43#define potential_N 100
44#define potential_align 64
45#define potential_ivalsmax 3048
46
47#define potential_escale (0.079577471545947667882)
48// #define potential_escale 1.0
49
50
51namespace TissueForge {
52
53
54 /* potential flags */
55
57 POTENTIAL_NONE = 0,
58 POTENTIAL_LJ126 = 1 << 0,
59 POTENTIAL_EWALD = 1 << 1,
60 POTENTIAL_COULOMB = 1 << 2,
61 POTENTIAL_SINGLE = 1 << 3,
62
64 POTENTIAL_R2 = 1 << 4,
65
67 POTENTIAL_R = 1 << 5,
68
71
74
75 POTENTIAL_DIHEDRAL = 1 << 8,
76
79
80 POTENTIAL_REACTIVE = 1 << 10,
81
88
93
98 POTENTIAL_BOUND = 1 << 13,
99
100 // sum of constituent potentials
101 POTENTIAL_SUM = 1 << 14,
102
105
106 /* Coulomb reciprocated */
107 POTENTIAL_COULOMBR = 1 << 16
108 };
109
110 enum PotentialKind {
111 // standard interpolated potential kind
112 POTENTIAL_KIND_POTENTIAL,
113
114 // dissipative particle dynamics kind
115 POTENTIAL_KIND_DPD,
116
117 // explicit potential by particles
118 POTENTIAL_KIND_BYPARTICLES,
119
120 // combination of two constituent potentials
121 POTENTIAL_KIND_COMBINATION
122 };
123
124
133 typedef void (*PotentialEval_ByParticle) (
134 struct Potential *p,
135 struct Particle *part_i,
136 FPTYPE *dx,
137 FPTYPE r2,
138 FPTYPE *e,
139 FPTYPE *f
140 );
141
151 struct Potential *p,
152 struct Particle *part_i,
153 struct Particle *part_j,
154 FPTYPE *dx,
155 FPTYPE r2,
156 FPTYPE *e,
157 FPTYPE *f
158 );
159
165 struct Potential *p,
166 struct Particle *part_i,
167 struct Particle *part_j,
168 struct Particle *part_k,
169 FPTYPE ctheta,
170 FPTYPE *e,
171 FPTYPE *fi,
172 FPTYPE *fk
173 );
174
180 struct Potential *p,
181 struct Particle *part_i,
182 struct Particle *part_j,
183 struct Particle *part_k,
184 struct Particle *part_l,
185 FPTYPE cphi,
186 FPTYPE *e,
187 FPTYPE *fi,
188 FPTYPE *fl
189 );
190
191 typedef struct Potential* (*PotentialCreate) (
192 struct Potential *partial_potential,
193 struct ParticleType *a,
194 struct ParticleType *b
195 );
196
201 typedef void (*PotentialClear) (struct Potential* p);
202
203
213 struct CAPI_EXPORT Potential {
214 uint32_t kind;
215
217 uint32_t flags;
218
219
221 FPTYPE alpha[4];
222
224 FPTYPE *c;
225
226 FPTYPE r0_plusone;
227
229 FPTYPE a, b;
230
232 FPTYPE mu;
233
235 FPTYPE offset[3];
236
238 int n;
239
240 PotentialCreate create_func;
241 PotentialClear clear_func;
242
243 PotentialEval_ByParticle eval_bypart;
244 PotentialEval_ByParticles eval_byparts;
245 PotentialEval_ByParticles3 eval_byparts3;
246 PotentialEval_ByParticles4 eval_byparts4;
247
248 Potential *pca, *pcb;
249
253 const char* name;
254
255 Potential();
256
257 FPTYPE operator()(const FPTYPE &r, const FPTYPE &r0=-1.0);
258 FPTYPE operator()(const std::vector<FPTYPE>& r);
259 FPTYPE operator()(struct ParticleHandle* pi, const FVector3 &pt);
260 FPTYPE operator()(struct ParticleHandle* pi, struct ParticleHandle* pj);
261 FPTYPE operator()(struct ParticleHandle* pi, struct ParticleHandle* pj, struct ParticleHandle* pk);
262 FPTYPE operator()(struct ParticleHandle* pi, struct ParticleHandle* pj, struct ParticleHandle* pk, struct ParticleHandle* pl);
263 FPTYPE force(FPTYPE r, FPTYPE ri=-1.0, FPTYPE rj=-1.0);
264 std::vector<FPTYPE> force(const std::vector<FPTYPE>& r);
265 std::vector<FPTYPE> force(struct ParticleHandle* pi, const FVector3 &pt);
266 std::vector<FPTYPE> force(struct ParticleHandle* pi, struct ParticleHandle* pj);
267 std::pair<std::vector<FPTYPE>, std::vector<FPTYPE> > force(struct ParticleHandle* pi, struct ParticleHandle* pj, struct ParticleHandle* pk);
268 std::pair<std::vector<FPTYPE>, std::vector<FPTYPE> > force(struct ParticleHandle* pi, struct ParticleHandle* pj, struct ParticleHandle* pk, struct ParticleHandle* pl);
269
270 std::vector<Potential*> constituents();
271
272 Potential& operator+(const Potential& rhs);
273
279 virtual std::string toString();
280
287 static Potential *fromString(const std::string &str);
288
307 static Potential *lennard_jones_12_6(FPTYPE min, FPTYPE max, FPTYPE A, FPTYPE B, FPTYPE *tol=NULL);
308
328 static Potential *lennard_jones_12_6_coulomb(FPTYPE min, FPTYPE max, FPTYPE A, FPTYPE B, FPTYPE q, FPTYPE *tol=NULL);
329
349 static Potential *ewald(FPTYPE min, FPTYPE max, FPTYPE q, FPTYPE kappa, FPTYPE *tol=NULL, unsigned int *periodicOrder=NULL);
350
369 static Potential *coulomb(FPTYPE q, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL, unsigned int *periodicOrder=NULL);
370
391 static Potential* coulombR(FPTYPE q, FPTYPE kappa, FPTYPE min, FPTYPE max, unsigned int* modes=NULL);
392
411 static Potential *harmonic(FPTYPE k, FPTYPE r0, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL);
412
430 static Potential *linear(FPTYPE k, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL);
431
450 static Potential *harmonic_angle(FPTYPE k, FPTYPE theta0, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL);
451
470 static Potential *harmonic_dihedral(FPTYPE k, FPTYPE delta, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL);
471
489 static Potential *cosine_dihedral(FPTYPE k, int n, FPTYPE delta, FPTYPE *tol=NULL);
490
512 static Potential *well(FPTYPE k, FPTYPE n, FPTYPE r0, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL);
513
536 static Potential *glj(FPTYPE e, FPTYPE *m=NULL, FPTYPE *n=NULL, FPTYPE *k=NULL, FPTYPE *r0=NULL, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL, bool *shifted=NULL);
537
558 static Potential *morse(FPTYPE *d=NULL, FPTYPE *a=NULL, FPTYPE *r0=NULL, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL, bool *shifted=NULL);
559
597 static Potential *overlapping_sphere(FPTYPE *mu=NULL, FPTYPE *kc=NULL, FPTYPE *kh=NULL, FPTYPE *r0=NULL, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL);
598
619 static Potential *power(FPTYPE *k=NULL, FPTYPE *r0=NULL, FPTYPE *alpha=NULL, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL);
620
663 static Potential *dpd(FPTYPE *alpha=NULL, FPTYPE *gamma=NULL, FPTYPE *sigma=NULL, FPTYPE *cutoff=NULL, bool *shifted=NULL);
664
676 static Potential *custom(
677 FPTYPE min,
678 FPTYPE max,
679 FPTYPE (*f)(FPTYPE),
680 FPTYPE (*fp)(FPTYPE),
681 FPTYPE (*f6p)(FPTYPE),
682 FPTYPE *tol=NULL,
683 uint32_t *flags=NULL
684 );
685
686 FPTYPE getMin();
687 FPTYPE getMax();
688 FPTYPE getCutoff();
689 std::pair<FPTYPE, FPTYPE> getDomain();
690 int getIntervals();
691 bool getBound();
692 void setBound(const bool &_bound);
693 FPTYPE getR0();
694 void setR0(const FPTYPE &_r0);
695 bool getShifted();
696 bool getPeriodic();
697 bool getRSquare();
698
699 };
700
701
703 CAPI_DATA(struct Potential) potential_null;
704
705
706 /* associated functions */
707
713 CAPI_FUNC(void) potential_clear(struct Potential *p);
714
737 struct Potential *p,
738 FPTYPE (*f)(FPTYPE),
739 FPTYPE (*fp)(FPTYPE),
740 FPTYPE (*f6p)(FPTYPE),
741 FPTYPE a,
742 FPTYPE b,
743 FPTYPE tol
744 );
745
746 CAPI_FUNC(HRESULT) potential_getcoeffs(
747 FPTYPE (*f)(FPTYPE),
748 FPTYPE (*fp)(FPTYPE),
749 FPTYPE *xi,
750 int n,
751 FPTYPE *c,
752 FPTYPE *err
753 );
754
755 CAPI_FUNC(FPTYPE) potential_getalpha(FPTYPE (*f6p)(FPTYPE), FPTYPE a, FPTYPE b);
756
757};
758
759#endif // _MDCORE_INCLUDE_TFPOTENTIAL_H_
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
HRESULT potential_init(struct Potential *p, FPTYPE(*f)(FPTYPE), FPTYPE(*fp)(FPTYPE), FPTYPE(*f6p)(FPTYPE), FPTYPE a, FPTYPE b, FPTYPE tol)
Construct a #potential from the given function.
void(* PotentialEval_ByParticle)(struct Potential *p, struct Particle *part_i, FPTYPE *dx, FPTYPE r2, FPTYPE *e, FPTYPE *f)
Potential function on a particle.
Definition tfPotential.h:133
void(* PotentialClear)(struct Potential *p)
Callback issues when potential is cleared.
Definition tfPotential.h:201
void potential_clear(struct Potential *p)
Free the memory associated with the given potential.
void(* PotentialEval_ByParticles)(struct Potential *p, struct Particle *part_i, struct Particle *part_j, FPTYPE *dx, FPTYPE r2, FPTYPE *e, FPTYPE *f)
Pair potential function.
Definition tfPotential.h:150
PotentialFlags
Definition tfPotential.h:56
@ POTENTIAL_SHIFTED
Definition tfPotential.h:92
@ POTENTIAL_ANGLE
Definition tfPotential.h:70
@ POTENTIAL_R2
Definition tfPotential.h:64
@ POTENTIAL_R
Definition tfPotential.h:67
@ POTENTIAL_SCALED
Definition tfPotential.h:87
@ POTENTIAL_HARMONIC
Definition tfPotential.h:73
@ POTENTIAL_SWITCH
Definition tfPotential.h:78
@ POTENTIAL_BOUND
Definition tfPotential.h:98
@ POTENTIAL_PERIODIC
Definition tfPotential.h:104
struct Potential potential_null
Definition tfPotential.h:703
void(* PotentialEval_ByParticles4)(struct Potential *p, struct Particle *part_i, struct Particle *part_j, struct Particle *part_k, struct Particle *part_l, FPTYPE cphi, FPTYPE *e, FPTYPE *fi, FPTYPE *fl)
Like PotentialEval_ByParticles, but with four particles.
Definition tfPotential.h:179
void(* PotentialEval_ByParticles3)(struct Potential *p, struct Particle *part_i, struct Particle *part_j, struct Particle *part_k, FPTYPE ctheta, FPTYPE *e, FPTYPE *fi, FPTYPE *fk)
Like PotentialEval_ByParticles, but with three particles.
Definition tfPotential.h:164
A handle to a particle.
Definition tfParticle.h:313
Definition tfParticle.h:101
Structure containing information on each particle type.
Definition tfParticle.h:768
A Potential object is a compiled interpolation of a given function. The Universe applies potentials t...
Definition tfPotential.h:213
static Potential * lennard_jones_12_6(FPTYPE min, FPTYPE max, FPTYPE A, FPTYPE B, FPTYPE *tol=NULL)
Creates a 12-6 Lennard-Jones potential.
static Potential * ewald(FPTYPE min, FPTYPE max, FPTYPE q, FPTYPE kappa, FPTYPE *tol=NULL, unsigned int *periodicOrder=NULL)
Creates a real-space Ewald potential.
static Potential * glj(FPTYPE e, FPTYPE *m=NULL, FPTYPE *n=NULL, FPTYPE *k=NULL, FPTYPE *r0=NULL, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL, bool *shifted=NULL)
Creates a generalized Lennard-Jones potential.
static Potential * dpd(FPTYPE *alpha=NULL, FPTYPE *gamma=NULL, FPTYPE *sigma=NULL, FPTYPE *cutoff=NULL, bool *shifted=NULL)
Creates a Dissipative Particle Dynamics potential.
uint32_t flags
Definition tfPotential.h:217
static Potential * power(FPTYPE *k=NULL, FPTYPE *r0=NULL, FPTYPE *alpha=NULL, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL)
Creates a power potential.
static Potential * coulomb(FPTYPE q, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL, unsigned int *periodicOrder=NULL)
Creates a Coulomb potential.
static Potential * morse(FPTYPE *d=NULL, FPTYPE *a=NULL, FPTYPE *r0=NULL, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL, bool *shifted=NULL)
Creates a Morse potential.
static Potential * cosine_dihedral(FPTYPE k, int n, FPTYPE delta, FPTYPE *tol=NULL)
Creates a cosine dihedral potential.
FPTYPE * c
Definition tfPotential.h:224
FPTYPE alpha[4]
Definition tfPotential.h:221
FPTYPE mu
Definition tfPotential.h:232
static Potential * well(FPTYPE k, FPTYPE n, FPTYPE r0, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL)
Creates a well potential.
const char * name
Definition tfPotential.h:253
virtual std::string toString()
Get a JSON string representation.
static Potential * lennard_jones_12_6_coulomb(FPTYPE min, FPTYPE max, FPTYPE A, FPTYPE B, FPTYPE q, FPTYPE *tol=NULL)
Creates a potential of the sum of a 12-6 Lennard-Jones potential and a shifted Coulomb potential.
static Potential * fromString(const std::string &str)
Create from a JSON string representation.
static Potential * custom(FPTYPE min, FPTYPE max, FPTYPE(*f)(FPTYPE), FPTYPE(*fp)(FPTYPE), FPTYPE(*f6p)(FPTYPE), FPTYPE *tol=NULL, uint32_t *flags=NULL)
Creates a custom potential.
int n
Definition tfPotential.h:238
static Potential * linear(FPTYPE k, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL)
Creates a linear potential.
static Potential * overlapping_sphere(FPTYPE *mu=NULL, FPTYPE *kc=NULL, FPTYPE *kh=NULL, FPTYPE *r0=NULL, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL)
Creates an overlapping-sphere potential from :cite:Osborne:2017hk.
static Potential * harmonic_angle(FPTYPE k, FPTYPE theta0, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL)
Creates a harmonic angle potential.
FPTYPE a
Definition tfPotential.h:229
FPTYPE offset[3]
Definition tfPotential.h:235
static Potential * harmonic_dihedral(FPTYPE k, FPTYPE delta, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL)
Creates a harmonic dihedral potential.
static Potential * coulombR(FPTYPE q, FPTYPE kappa, FPTYPE min, FPTYPE max, unsigned int *modes=NULL)
Creates a Coulomb reciprocal potential.
static Potential * harmonic(FPTYPE k, FPTYPE r0, FPTYPE *min=NULL, FPTYPE *max=NULL, FPTYPE *tol=NULL)
Creates a harmonic bond potential.
int32_t HRESULT
Definition tf_port.h:255