Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
moldynamics.h
Go to the documentation of this file.
1 #ifndef __MOLDYNAMICS_H__
2 #define __MOLDYNAMICS_H__
3 
4 class force {
5  public:
6  double fx;
7  double fy;
8 
9  force operator-() const {
10  force fnew;
11  fnew.fx = -fx;
12  fnew.fy = -fy;
13  return fnew;
14  }
15 
16  force operator+(force const & fother) const {
17  force fnew;
18  fnew.fx = fx+fother.fx;
19  fnew.fy = fy+fother.fy;
20  return fnew;
21  }
22 
23  force(){
24  fx = 0.0;
25  fy = 0.0;
26  }
27 
28  // additive identity
29  force(int){
30  fx = 0.0;
31  fy = 0.0;
32  }
33 };
34 
35 class particle {
36  public:
37  double dx;
38  double dy;
39  double coeff;
40  int id;
41 
43  dx = 0.0;
44  dy = 0.0;
45  coeff = 0.0;
46  id = 0;
47  }
48 };
49 
50 void acc_force(force f, particle & p){
51  p.dx += f.fx*p.coeff;
52  p.dy += f.fy*p.coeff;
53 }
54 
55 #ifdef __CUDACC__
56 __device__ __host__
57 #endif
58 double get_distance(particle const & p, particle const & q){
59  return sqrt((p.dx-q.dx)*(p.dx-q.dx)+(p.dy-q.dy)*(p.dy-q.dy));
60 }
61 
62 #ifdef __CUDACC__
63 __device__ __host__
64 #endif
65 force get_force(particle const p, particle const q){
66  force f;
67  f.fx = (p.dx-q.dx)/std::pow(get_distance(p,q)+.01,3);
68  f.fy = (p.dy-q.dy)/std::pow(get_distance(p,q)+.01,3);
69  return f;
70 }
71 namespace CTF {
72  template <>
73  inline void Set<particle>::print(char const * a, FILE * fp) const {
74  fprintf(fp,"(dx=%lf dy=%lf coeff=%lf id=%d)",((particle*)a)[0].dx,((particle*)a)[0].dy,((particle*)a)[0].coeff,((particle*)a)[0].id);
75  }
76  template <>
77  inline void Set<force>::print(char const * a, FILE * fp) const {
78  fprintf(fp,"(fx=%lf fy=%lf)",((force*)a)[0].fx,((force*)a)[0].fy);
79  }
80 
81 }
82 
83 
84 #endif
85 
Set class defined by a datatype and a min/max function (if it is partially ordered i...
Definition: set.h:280
force operator-() const
Definition: moldynamics.h:9
double dy
Definition: moldynamics.h:38
double fy
Definition: moldynamics.h:7
force operator+(force const &fother) const
Definition: moldynamics.h:16
void acc_force(force f, particle &p)
Definition: moldynamics.h:50
double get_distance(particle const &p, particle const &q)
Definition: moldynamics.h:58
double coeff
Definition: moldynamics.h:39
force(int)
Definition: moldynamics.h:29
force()
Definition: moldynamics.h:23
force get_force(particle const p, particle const q)
Definition: moldynamics.h:65
Definition: apsp.cxx:17
double dx
Definition: moldynamics.h:37
double fx
Definition: moldynamics.h:6