|
47 | 47 | #include <hydra/multiarray.h> |
48 | 48 | #include <hydra/ForEach.h> |
49 | 49 |
|
| 50 | +#include "TCanvas.h" |
| 51 | +#include "TGraphTime.h" |
| 52 | +#include "TROOT.h" |
| 53 | +#include "TMarker.h" |
50 | 54 |
|
51 | 55 | struct Evolve |
52 | 56 | { |
53 | 57 | Evolve() = delete; |
54 | 58 |
|
55 | | - Evolve(double time, double step): |
56 | | - fTime(time), |
57 | | - fStep(step) |
| 59 | + Evolve(double ispeed, double time, double slope): |
| 60 | + fInitialSpeed(ispeed), |
| 61 | + fSlope(slope), |
| 62 | + fTime(time) |
58 | 63 | {} |
59 | 64 |
|
| 65 | + __hydra_dual__ |
60 | 66 | Evolve(Evolve const& other): |
61 | | - fTime(other.fTime), |
62 | | - fStep(other.fStep) |
| 67 | + fInitialSpeed(other.fInitialSpeed), |
| 68 | + fSlope(other.fSlope), |
| 69 | + fTime(other.fTime) |
63 | 70 | {} |
64 | 71 |
|
65 | | - __hydra_dual__ |
66 | 72 | template<typename Particle> |
| 73 | + __hydra_dual__ |
67 | 74 | inline void operator()(Particle p) { |
| 75 | + |
68 | 76 | double theta = hydra::get<3>(p); |
69 | | - hydra::get<0>(p) += delta_x(theta); |
70 | | - hydra::get<1>(p) += delta_y(theta); |
71 | | - hydra::get<2>(p) += delta_z(theta); |
| 77 | + double phi = hydra::get<4>(p); |
| 78 | + |
| 79 | + hydra::get<0>(p) += delta_x(theta, phi); |
| 80 | + hydra::get<1>(p) += delta_y(theta, phi); |
| 81 | + hydra::get<2>(p) += delta_z(theta, phi); |
72 | 82 | } |
73 | 83 |
|
74 | 84 | __hydra_dual__ |
75 | | - inline double delta_x(double theta){ |
76 | | - return ::exp(-fTime)*::cos(theta)*fStep; |
| 85 | + inline double delta_x(double theta, double phi){ |
| 86 | + return displacement()*::cos(theta)*sin(phi); |
77 | 87 | } |
78 | 88 |
|
79 | 89 | __hydra_dual__ |
80 | | - inline double delta_y(double theta){ |
81 | | - return ::exp(-fTime)*::sin(theta)*fStep; |
| 90 | + inline double delta_y(double theta, double phi){ |
| 91 | + return displacement()*::sin(theta)*sin(phi); |
82 | 92 | } |
83 | 93 |
|
84 | 94 | __hydra_dual__ |
85 | | - inline double delta_z(double theta) { |
86 | | - return ::exp(-fTime)*fStep; |
| 95 | + inline double delta_z(double theta, double phi) { |
| 96 | + return displacement()*sin(phi); |
87 | 97 | } |
88 | 98 |
|
| 99 | + |
| 100 | + __hydra_dual__ |
| 101 | + inline double displacement(){ |
| 102 | + return ::exp(-fSlope*fTime)*(fSlope*fTime*fTime + fInitialSpeed) ; |
| 103 | + } |
| 104 | + |
| 105 | + |
| 106 | + double fInitialSpeed; |
| 107 | + double fSlope; |
89 | 108 | double fTime; |
90 | | - double fStep; |
| 109 | + |
91 | 110 | }; |
92 | 111 |
|
93 | 112 |
|
94 | | -typedef hydra::multiarray<double, 4, hydra::device::sys_t> StateDevice_t; |
95 | | -typedef hydra::multiarray<double, 4, hydra::host::sys_t> StateHost_t; |
| 113 | +typedef hydra::multiarray<double, 5, hydra::device::sys_t> StateDevice_t; |
| 114 | +typedef hydra::multiarray<double, 5, hydra::host::sys_t> StateHost_t; |
96 | 115 | typedef std::vector<StateHost_t> Ensamble_t; |
97 | 116 |
|
98 | | -void particle_dispersion( size_t nparicles, size_t nsteps, double epsilon ){ |
| 117 | +void particle_dispersion( size_t nparicles, size_t nsteps, double initial_speed, double slope ){ |
99 | 118 |
|
100 | | - Ensamble_t ensamble(nsteps, StateHost_t(nparicles, hydra::make_tuple(0.0, 0.0, 0.0, 0.0) )); |
| 119 | + Ensamble_t ensamble(nsteps, StateHost_t(nparicles, hydra::make_tuple(0.0, 0.0, 0.0, 0.0, 0.0) )); |
101 | 120 |
|
102 | 121 |
|
103 | 122 | { |
104 | 123 | //initial state |
105 | | - StateDevice_t initial_state(nparicles, hydra::make_tuple(0.0, 0.0, 0.0, 0.0)); |
| 124 | + StateDevice_t initial_state(nparicles, hydra::make_tuple(0.0, 0.0, 0.0, 0.0, 0.0)); |
106 | 125 | //distribute particles in the surface |
107 | 126 | hydra::Random<> RND( std::chrono::system_clock::now().time_since_epoch().count()); |
108 | 127 | // set x-coordinate |
109 | 128 | RND.SetSeed(159); |
110 | | - RND.Uniform(-1.0, 1.0, initial_state.begin(0), initial_state.end(0)); |
| 129 | + RND.Uniform(-0.1, 0.1, initial_state.begin(0), initial_state.end(0)); |
111 | 130 | // set y-coordinate |
112 | 131 | RND.SetSeed(753); |
113 | | - RND.Uniform(-1.0, 1.0, initial_state.begin(1), initial_state.end(1)); |
| 132 | + RND.Uniform(-2.0, 2.0, initial_state.begin(1), initial_state.end(1)); |
114 | 133 |
|
115 | 134 | size_t i=1; |
116 | 135 |
|
117 | 136 | for(auto& final_state:ensamble){ |
118 | 137 |
|
119 | | - hydra::Random<> RND(std::rand()); |
| 138 | + RND.SetSeed(std::rand()); |
120 | 139 | RND.Uniform(0.0, 2.0*PI, initial_state.begin(3), initial_state.end(3)); |
121 | | - hydra::for_each( initial_state.begin(), initial_state.end(), Evolve(i*epsilon, 2.0) ); |
| 140 | + RND.SetSeed(std::rand()); |
| 141 | + RND.Uniform(0.0, 2.0*PI, initial_state.begin(4), initial_state.end(4)); |
| 142 | + hydra::for_each( initial_state.begin(), initial_state.end(), Evolve(initial_speed , double(i)/nsteps, slope) ); |
122 | 143 | hydra::copy(initial_state.begin(), initial_state.end(), final_state.begin()); |
123 | 144 | i++; |
124 | 145 | } |
125 | 146 |
|
126 | 147 | } |
127 | 148 |
|
128 | | - for(auto& state:ensamble){ |
129 | | - std::cout<< "=====================================" << std::endl; |
130 | | - std::cout<< "=====================================" << std::endl; |
131 | | - std::cout<< std::endl << std::endl << std::endl; |
132 | | - for(auto particle:state) |
133 | | - std::cout<< particle << std::endl; |
| 149 | + |
| 150 | + TCanvas canvas("canvas", "", 500, 500); |
| 151 | + TGraphTime *g = new TGraphTime(nsteps,-10.0, -10.0, 10.0, 10.0); |
| 152 | + |
| 153 | + int step=0; |
| 154 | + for(auto final_state:ensamble){ |
| 155 | + |
| 156 | + for( auto particle:final_state){ |
| 157 | + |
| 158 | + double x = hydra::get<0>(particle); |
| 159 | + double y = hydra::get<1>(particle); |
| 160 | + |
| 161 | + TMarker *m = new TMarker(x,y,20); |
| 162 | + m->SetMarkerColor(kBlack); |
| 163 | + m->SetMarkerSize(0.5); |
| 164 | + g->Add(m,step); |
| 165 | + } |
| 166 | + |
| 167 | + step++; |
134 | 168 | } |
135 | 169 |
|
| 170 | + |
| 171 | + g->Draw(); |
| 172 | + |
136 | 173 | } |
137 | 174 |
|
138 | 175 |
|
|
0 commit comments