KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Model_MD1D.h
Go to the documentation of this file.
1#ifndef MODEL_MD1D_H
2#define MODEL_MD1D_H
3
4#include "kids/Kernel.h"
6#include "kids/hash_fnv1a.h"
7#include "kids/macro_utils.h"
8
9namespace PROJECT_NS {
10
11
12class Model_HO final : public Kernel {
13 public:
14 virtual const std::string getName() { return "Model_HO"; }
15
16 virtual int getType() const { return utils::hash(FUNCTION_NAME); }
17
18 private:
19 int size;
20 double *x, *p;
21 double *x_init, *p_init;
22 double *f;
23 double *m, *w;
24
25 double beta;
26
27 virtual void setInputParam_impl(Param *PM) {
28 size = PM->get_int("N", LOC()); //
29 beta = PM->get_double("beta", LOC(), 1.0); //
30 }
31
32 virtual void setInputDataSet_impl(DataSet *DS) {
33 // external
34 x = DS->def_real("integrator.x", size);
35 p = DS->def_real("integrator.p", size);
36 f = DS->def_real("integrator.f", size);
37
38 x_init = DS->def_real("init.x", size);
39 p_init = DS->def_real("init.p", size);
40
41 // shared
42 w = DS->def_real("model.w", size);
43 m = DS->def_real("model.mass", size);
44 for (int i = 0; i < size; ++i) m[i] = 1, w[i] = 1;
45 }
46
48 for (int i = 0; i < size; ++i) {
49 double Qi_div_beta = 0.5f * w[i] / std::tanh(0.5f * beta * w[i]);
50 double xi_sigma = std::sqrt(Qi_div_beta / (m[i] * w[i] * w[i]));
51 double pi_sigma = std::sqrt(Qi_div_beta * m[i]);
52
53 double u1, u2;
56 x_init[i] = u1 * xi_sigma;
57 p_init[i] = u2 * pi_sigma;
58 }
59 // copy to external
60 for (int i = 0; i < size; ++i) {
61 x[i] = x_init[i];
62 p[i] = p_init[i];
63 }
64 return stat;
65 }
66
68 for (int i = 0; i < size; ++i) f[i] = m[i] * w[i] * w[i] * x[i];
69 return stat;
70 }
71};
72
73class MODEL_MD1D final : public Kernel {
74 public:
75 virtual const std::string getName() { return "Model_HO"; }
76
77 virtual int getType() const { return utils::hash(FUNCTION_NAME); }
78
79 private:
80 int size;
81 double *x, *f;
82 double *m, *w;
83
84 virtual void setInputParam_impl(Param *PM) {
85 size = PM->get_int("N", LOC()); //
86 }
87
88 virtual void setInputDataSet_impl(DataSet *DS) {
89 // external
90 x = DS->def_real("integrator.x", size);
91 f = DS->def_real("integrator.f", size);
92 // shared
93 w = DS->def_real("model.w", size);
94 m = DS->def_real("model.mass", size);
95 for (int i = 0; i < size; ++i) m[i] = 1, w[i] = 1;
96 }
97
99 for (int i = 0; i < size; ++i) f[i] = m[i] * w[i] * w[i] * x[i];
100 return stat;
101 }
102};
103}; // namespace PROJECT_NS
104
105#endif // MODEL_MD1D_H
this file provide Kernel class
DataSet class is a tree-structured container for storage of Tensor and other DataSet.
Definition DataSet.h:74
kids_real * def_real(const std::string &key, Shape S=1, const std::string &info="")
Define a real variable with a specified key, shape, and info.
Definition DataSet.cpp:79
static int rand_gaussian(kids_real *res_arr, int N=1, kids_real sigma=1.0, kids_real mu=0.0)
this class provides the container and implementation of algorithms
Definition Kernel.h:60
virtual void setInputParam_impl(Param *PM)
Definition Model_MD1D.h:84
virtual int getType() const
Get the type of the kernel.
Definition Model_MD1D.h:77
virtual void setInputDataSet_impl(DataSet *DS)
Definition Model_MD1D.h:88
virtual Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
Definition Model_MD1D.h:98
virtual const std::string getName()
Get the name of the kernel.
Definition Model_MD1D.h:75
virtual int getType() const
Get the type of the kernel.
Definition Model_MD1D.h:16
virtual void setInputParam_impl(Param *PM)
Definition Model_MD1D.h:27
virtual void setInputDataSet_impl(DataSet *DS)
Definition Model_MD1D.h:32
virtual Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
Definition Model_MD1D.h:67
virtual const std::string getName()
Get the name of the kernel.
Definition Model_MD1D.h:14
virtual Status & initializeKernel_impl(Status &stat)
Virtual function to initialize the kernel implementation.
Definition Model_MD1D.h:47
this class provides an interface wrapper for the parameter data.
Definition Param.h:82
double get_double(const std::string &key, const std::string &loc, const phys::dimension7 &qdim, const double &default_value=double())
Definition Param.cpp:150
int get_int(const std::string &key, const std::string &loc, const int &default_value)
Definition Param.cpp:136
#define LOC()
show the location information for debug
Definition fmt.h:49
#define FUNCTION_NAME
Definition macro_utils.h:9
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39
constexpr uint32_t hash(const char *str)
Definition hash_fnv1a.h:12