Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfForce.h
Go to the documentation of this file.
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
24
25#ifndef _MDCORE_INCLUDE_TFFORCE_H_
26#define _MDCORE_INCLUDE_TFFORCE_H_
27
28#include "tf_platform.h"
29#include "tf_fptype.h"
30#include <types/tf_types.h>
31#include <io/tf_io.h>
32
33#include <limits>
34
35
36namespace TissueForge {
37
38
39 enum FORCE_KIND {
40 FORCE_ONEBODY,
41 FORCE_PAIRWISE
42 };
43
44 enum FORCE_TYPE {
45 FORCE_FORCE = 0,
46 FORCE_BERENDSEN = 1 << 0,
47 FORCE_GAUSSIAN = 1 << 1,
48 FORCE_FRICTION = 1 << 2,
49 FORCE_SUM = 1 << 3,
50 FORCE_CUSTOM = 1 << 4
51 };
52
56 typedef void (*Force_EvalFcn)(struct Force*, struct Particle*, FPTYPE*);
57
58 struct Berendsen;
59 struct Gaussian;
60 struct Friction;
61
69 struct CAPI_EXPORT Force {
70 FORCE_TYPE type = FORCE_FORCE;
71
72 Force_EvalFcn func;
73
74 int stateVectorIndex = -1;
75
81 virtual bool isCustom() { return false; }
82
92 HRESULT bind_species(struct ParticleType *a_type, const std::string &coupling_symbol);
93
122 static Berendsen* berendsen_tstat(const FPTYPE &tau);
123
138 static Gaussian* random(const FPTYPE &std, const FPTYPE &mean, const FPTYPE &duration=0.01);
139
156 static Friction* friction(const FPTYPE &coef);
157
158 Force& operator+(const Force& rhs);
159
165 virtual std::string toString();
166
173 static Force *fromString(const std::string &str);
174 };
175
176 struct CAPI_EXPORT ForceSum : Force {
177 Force *f1, *f2;
178
188 };
189
190 CAPI_FUNC(Force*) Force_add(Force *f1, Force *f2);
191
192 struct CustomForce;
193 using UserForceFuncType = FVector3(*)(CustomForce*);
194
200 struct CAPI_EXPORT CustomForce : Force {
201 UserForceFuncType *userFunc;
202 FPTYPE updateInterval;
203 FPTYPE lastUpdate;
204
205 FVector3 force;
206
214 virtual void onTime(FPTYPE time);
215
216 virtual FVector3 getValue();
217
223 void setValue(const FVector3 &f);
224
231 void setValue(UserForceFuncType *_userFunc=NULL);
232
233 FPTYPE getPeriod();
234 void setPeriod(const FPTYPE &period);
235
236 bool isCustom() { return true; }
237
238 CustomForce();
239 CustomForce(const FVector3 &f, const FPTYPE &period=std::numeric_limits<FPTYPE>::max());
240 CustomForce(UserForceFuncType *f, const FPTYPE &period=std::numeric_limits<FPTYPE>::max());
241 virtual ~CustomForce(){}
242
251 static CustomForce *fromForce(Force *f);
252 };
253
259 struct CAPI_EXPORT Berendsen : Force {
263 FPTYPE itau;
264
274 };
275
281 struct CAPI_EXPORT Gaussian : Force {
285 FPTYPE std;
286
290 FPTYPE mean;
291
296
306 };
307
313 struct CAPI_EXPORT Friction : Force {
317 FPTYPE coef;
318
328 };
329
330
331 CPPAPI_FUNC(ForceSum*) ForceSum_fromStr(const std::string &str);
332 CPPAPI_FUNC(Berendsen*) Berendsen_fromStr(const std::string &str);
333 CPPAPI_FUNC(Gaussian*) Gaussian_fromStr(const std::string &str);
334 CPPAPI_FUNC(Friction*) Friction_fromStr(const std::string &str);
335
336};
337
338#endif // _MDCORE_INCLUDE_TFFORCE_H_
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
void(* Force_EvalFcn)(struct Force *, struct Particle *, FPTYPE *)
Definition tfForce.h:56
Berendsen force.
Definition tfForce.h:259
FPTYPE itau
time constant
Definition tfForce.h:263
static Berendsen * fromForce(Force *f)
Convert basic force to Berendsen.
A custom force function.
Definition tfForce.h:200
void setValue(const FVector3 &f)
void setValue(UserForceFuncType *_userFunc=NULL)
static CustomForce * fromForce(Force *f)
Convert basic force to CustomForce.
bool isCustom()
Tests whether this object is a custom force type.
Definition tfForce.h:236
virtual void onTime(FPTYPE time)
Force is a metatype, in that Tissue Forge has lots of different instances of force functions,...
Definition tfForce.h:69
static Berendsen * berendsen_tstat(const FPTYPE &tau)
Creates a Berendsen thermostat.
static Gaussian * random(const FPTYPE &std, const FPTYPE &mean, const FPTYPE &duration=0.01)
Creates a random force.
HRESULT bind_species(struct ParticleType *a_type, const std::string &coupling_symbol)
Bind a force to a species.
virtual std::string toString()
Get a JSON string representation.
virtual bool isCustom()
Tests whether this object is a custom force type.
Definition tfForce.h:81
static Force * fromString(const std::string &str)
Create from a JSON string representation.
static Friction * friction(const FPTYPE &coef)
Creates a friction force.
Definition tfForce.h:176
static ForceSum * fromForce(Force *f)
Convert basic force to force sum.
Friction force.
Definition tfForce.h:313
static Friction * fromForce(Force *f)
Convert basic force to Friction.
FPTYPE coef
time constant
Definition tfForce.h:317
Random force.
Definition tfForce.h:281
FPTYPE std
standard deviation of magnitude
Definition tfForce.h:285
FPTYPE mean
mean of magnitude
Definition tfForce.h:290
unsigned durration_steps
duration of force.
Definition tfForce.h:295
static Gaussian * fromForce(Force *f)
Convert basic force to Gaussian.
Definition tfParticle.h:101
Structure containing information on each particle type.
Definition tfParticle.h:768
int32_t HRESULT
Definition tf_port.h:255