Skip to content

Commit aab3816

Browse files
author
contuandrea
committed
iterators instead of raw pointers
1 parent b0d8711 commit aab3816

File tree

9 files changed

+711
-883
lines changed

9 files changed

+711
-883
lines changed

include/Evolve.h

Lines changed: 581 additions & 821 deletions
Large diffs are not rendered by default.

include/HydraSim.h

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
4949
TH3D* h3=NULL;
5050

5151
VecDev_t<double> _xvec, _yvec, _zvec;
52+
hydra::multiarray<double,8,hydra::host::sys_t> _vec_map;
53+
5254
//efield vecs
5355
VecDev_t<double> _xvec_ef, _yvec_ef, _zvec_ef;
56+
57+
hydra::multiarray<double,3,hydra::host::sys_t> _vec_ef;
5458
VecDev_t<double> efieldvecx, efieldvecy, efieldvecz;
5559
//wfield vecs
60+
61+
hydra::multiarray<double,3,hydra::host::sys_t> _vec_wf;
5662
VecDev_t<double> _xvec_wf, _yvec_wf, _zvec_wf;
5763
VecDev_t<double> wfieldvecx, wfieldvecy, wfieldvecz;
5864

@@ -67,7 +73,6 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
6773
double _xmin=0, _xmax=0, _ymin=0, _ymax=0, _zmin=0, _zmax=0;
6874
//load physics maps
6975

70-
7176
bool multimap=true;
7277
//get physicsmap path
7378
if(root["PhysicsMaps"].exists("map")){
@@ -81,6 +86,7 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
8186

8287
pm.fillspacepoints<VecDev_t<double> >(_xvec,_yvec,_zvec);
8388
pm.fillallquantities<VecDev_t<double> >(efieldvecx,efieldvecy,efieldvecz,emobvec,hmobvec,wfieldvecx,wfieldvecy,wfieldvecz);
89+
pm.fillallquantities<hydra::multiarray<double,8,hydra::host::sys_t> >(_vec_map);
8490

8591
_xmin = *(pm.getx().begin());
8692
_xmax = *(pm.getx().rbegin());
@@ -110,6 +116,7 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
110116

111117
efieldm.fillspacepoints<VecDev_t<double> >(_xvec_ef,_yvec_ef,_zvec_ef);
112118
efieldm.fillvector<VecDev_t<double> >(efieldvecx,efieldvecy,efieldvecz);
119+
efieldm.fillvector< hydra::multiarray<double,3,hydra::host::sys_t> >(_vec_ef);
113120

114121
for(auto cf:configlist){
115122
if(std::get<bool>(cf.get("plot"))){
@@ -126,6 +133,7 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
126133
wfieldm.prepare();
127134
wfieldm.fillspacepoints<VecDev_t<double> >(_xvec_wf,_yvec_wf,_zvec_wf);
128135
wfieldm.fillvector<VecDev_t<double> >(wfieldvecx,wfieldvecy,wfieldvecz);
136+
wfieldm.fillvector< hydra::multiarray<double,3,hydra::host::sys_t> >(_vec_wf);
129137

130138
std::string emobmap_path=root["PhysicsMaps"]["emob"];
131139
maps::physmap<double,4> emobm(emobmap_path); // Electron mobility is a scalar
@@ -165,7 +173,7 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
165173

166174
RunningStateHost_t data_dinit;
167175
if(tmpfile==DEFAULT_PATH) data_dinit = loaddata::getDummy( std::get<size_t>(configlist[0].get("nparticles")),
168-
std::get<double>(configlist[0].get("length")));
176+
std::get<double>(configlist[0].get("length")),std::get<size_t>(configlist[0].get("group")));
169177
else data_dinit=loaddata::loadfile(tmpfile);
170178

171179

@@ -178,6 +186,7 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
178186
auto bunchsize = std::get<size_t>(cf.get("bunchsize"));
179187
auto nparticles = std::get<size_t>(cf.get("nparticles"));
180188
auto nsteps = std::get<size_t>(cf.get("nsteps"));
189+
auto group = std::get<size_t>(cf.get("group"));
181190
auto path = std::get<std::string>(cf.get("path"));
182191
auto nickname = std::get<std::string>(cf.get("nickname"));
183192
auto plot = std::get<bool>(cf.get("plot"));
@@ -191,13 +200,11 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
191200
auto amp = std::get<double>(cf.get("amp"));
192201
auto length = std::get<double>(cf.get("length"));
193202

194-
// cf.Print();
195-
196203
auto start = std::chrono::high_resolution_clock::now();
197204
if(path!=tmpfile){
198205
tmpfile=path;
199-
if(tmpfile==DEFAULT_PATH) data_dinit=loaddata::getDummy(nparticles,length);
200-
else data_dinit=loaddata::loadfile(tmpfile);
206+
if(tmpfile==DEFAULT_PATH) data_dinit=loaddata::getDummy(nparticles,length,group);
207+
else data_dinit=loaddata::loadfile(tmpfile,group);
201208
}
202209

203210
//create running state
@@ -231,7 +238,8 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
231238
size_t rest = nsteps%bunchsize;
232239

233240
INFO_LINE("Simulation "<<sim<<" ("<<nickname<<")")
234-
INFO_LINE("Nparticles(dep. charge): "<<nparticles<<"("<< (double)(nparticles)*HCHARGE/2. <<" C)"<< ", Temperature "<< temperature << ", timestep "<<timestep)
241+
if(group>1) INFO_LINE("Particles are grouped in "<< nparticles <<" bunches of "<<group);
242+
INFO_LINE("Nparticles(dep. charge): "<<nparticles*group<<"("<< (double)(nparticles*group)*HCHARGE/2. <<" C)"<< ", Temperature "<< temperature << ", timestep "<<timestep)
235243
INFO_LINE("Nsteps: "<<nsteps)
236244
// if(ampexp[sim]!=0.0) INFO_LINE("Amp_exp "<< cf.get("amp").getd() << ", Sigma_exp "<<cf.get("sig").getd())
237245
if(xshift!=0.0) INFO_LINE("shifted in x by "<<xshift<< " micron")
@@ -271,13 +279,13 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
271279
Generator.Uniform(0.0, PI, data_d.begin(_tc_angle_2), data_d.end(_tc_angle_2));
272280

273281

274-
hydra::for_each(data_d, evolve::ApplyRamo_multi(niter,
282+
hydra::for_each(data_d, evolve::make_RamoCurrent(niter,
275283
timestep,
276284
temperature_nmob,
277-
_xvec_ef, _yvec_ef, _zvec_ef, efieldvecx, efieldvecy, efieldvecz,
285+
_xvec_ef, _yvec_ef, _zvec_ef, _vec_ef,
278286
_xvec_emob, _yvec_emob, _zvec_emob, emobvec,
279287
_xvec_hmob, _yvec_hmob, _zvec_hmob, hmobvec,
280-
_xvec_wf, _yvec_wf, _zvec_wf, wfieldvecx, wfieldvecy, wfieldvecz));
288+
_xvec_wf, _yvec_wf, _zvec_wf, _vec_wf));
281289

282290
//reducing data
283291
auto int_curr=HYDRA_EXTERNAL_NS::thrust::transform_reduce(data_d.begin(_tc_charge,_tc_isin,_tc_curr,_tc_issec),data_d.end(_tc_charge,_tc_isin,_tc_curr,_tc_issec),analysis::SelectChargeAndSec(), ReducedTuple_init,analysis::SumTuples());
@@ -295,13 +303,14 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
295303

296304

297305
if(niter==nsteps-1) break;
298-
299-
hydra::for_each(data_d, evolve::Evolve_multi(niter,
300-
timestep,
301-
_xvec_ef, _yvec_ef, _zvec_ef, efieldvecx, efieldvecy, efieldvecz,
302-
_xvec_emob, _yvec_emob, _zvec_emob, emobvec,
303-
_xvec_hmob, _yvec_hmob, _zvec_hmob, hmobvec,
304-
_xmin,_xmax,_ymin,_ymax,_zmin,_zmax));
306+
307+
hydra::for_each(data_d, evolve::make_Evolution(niter,
308+
timestep,
309+
_xvec_ef, _yvec_ef, _zvec_ef, _vec_ef,
310+
_xvec_emob, _yvec_emob, _zvec_emob, emobvec,
311+
_xvec_hmob, _yvec_hmob, _zvec_hmob, hmobvec,
312+
_xmin,_xmax,_ymin,_ymax,_zmin,_zmax));
313+
305314
niter++;
306315

307316

@@ -320,13 +329,10 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
320329
Generator.Uniform(0.0, PI, data_d.begin(_tc_angle_2), data_d.end(_tc_angle_2));
321330

322331

323-
hydra::for_each(data_d, evolve::ApplyRamo(niter,
332+
hydra::for_each(data_d, evolve::make_RamoCurrent(niter,
324333
timestep,
325334
temperature_nmob,
326-
_xvec, _yvec, _zvec,
327-
efieldvecx, efieldvecy, efieldvecz,
328-
emobvec,hmobvec,
329-
wfieldvecx, wfieldvecy, wfieldvecz));
335+
_xvec, _yvec, _zvec, _vec_map));
330336

331337
//reducing data
332338
auto int_curr=HYDRA_EXTERNAL_NS::thrust::transform_reduce(data_d.begin(_tc_charge,_tc_isin,_tc_curr,_tc_issec),data_d.end(_tc_charge,_tc_isin,_tc_curr,_tc_issec),analysis::SelectChargeAndSec(), ReducedTuple_init,analysis::SumTuples());
@@ -345,11 +351,10 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
345351

346352
if(niter==nsteps-1) break;
347353

348-
hydra::for_each(data_d, evolve::Evolve(niter,
349-
timestep,
350-
_xvec, _yvec, _zvec,
351-
efieldvecx, efieldvecy, efieldvecz,
352-
emobvec,hmobvec));
354+
hydra::for_each(data_d, evolve::make_Evolution(niter,
355+
timestep,
356+
_xvec, _yvec, _zvec, _vec_map));
357+
353358
niter++;
354359

355360

include/datatypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ using VecDev_t = hydra::device::vector<T>; //vector container dou
6060
//currents vector
6161
using CurrentVec_t = std::vector<ReducedTuple_t>;
6262

63+
//index for search 8 points in physics maps
64+
using mapindices_t = hydra::tuple<size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t>;
65+
using mapentry_t = hydra::tuple<double, double, double, double, double, double, double, double>;
66+
6367
//defining particle state columns meaning
6468
auto _tc_charge = hydra::placeholders::_0;
6569
auto _tc_x = hydra::placeholders::_1;

include/defaults.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@
6464
#define DEFAULT_X 0. //default deposit shift in x direction
6565
#define DEFAULT_Y 0. //default deposit shift in y direction
6666
#define DEFAULT_Z 0. //default deposit shift in z direction
67+
#define DEFAULT_GROUP 1 //default carrier grouping factor
6768

6869
#endif

include/deposit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ namespace deposit{
4646
double _length=1.;
4747

4848
public:
49-
owndeposit(std::string path, size_t nparticles, double length){
49+
owndeposit(std::string path, size_t nparticles, double length, size_t group=DEFAULT_GROUP){
5050
this->init(path, nparticles, length);
5151
}
5252

5353
owndeposit(singleconf cf){
5454
this->init(std::get<std::string>(cf.get("path")), std::get<size_t>(cf.get("nparticles")),std::get<double>(cf.get("length")));
5555
}
5656
//initialise
57-
void init(std::string path, size_t nparticles, double length){
57+
void init(std::string path, size_t nparticles, double length, size_t group=DEFAULT_GROUP){
5858
if(_path==DEFAULT_PATH){
5959
if(nparticles!=_static_nparticles || length!=_static_length){
6060
_data = this->gendummy(nparticles,length);
@@ -87,7 +87,7 @@ namespace deposit{
8787
double getnparticles(){return _nparticles;}
8888

8989
//generate dummy deposit
90-
RunningStateHost_t gendummy(size_t nparticles, double length){
90+
RunningStateHost_t gendummy(size_t nparticles, double length, size_t group=DEFAULT_GROUP){
9191
INFO_LINE("Generating deposit")
9292
hydra::Random<> Generator( std::chrono::system_clock::now().time_since_epoch().count());
9393
size_t np=(nparticles<=0) ? MAXPARTICLES : nparticles;
@@ -119,7 +119,7 @@ namespace deposit{
119119
RunningStateHost_t* getdata(){return &_data;}
120120

121121
//get deposit and change if different
122-
RunningStateHost_t* getdata(std::string newfile, size_t nparticles, double length=1.){
122+
RunningStateHost_t* getdata(std::string newfile, size_t nparticles, double length=1., size_t group=DEFAULT_GROUP){
123123
if(_path!=newfile){
124124
_path=newfile;
125125
if(newfile==DEFAULT_PATH) _data = loaddata::getDummy(nparticles,length);

include/loadfiles.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,22 @@ using namespace hydra::placeholders;
3232

3333
namespace loaddata{
3434

35-
RunningStateHost_t getDummy(size_t nparticles, double length){
35+
RunningStateHost_t getDummy(size_t nparticles, double length, size_t group=DEFAULT_GROUP){
3636
INFO_LINE("Generating deposit")
3737
hydra::Random<> Generator( std::chrono::system_clock::now().time_since_epoch().count());
3838
size_t np=(nparticles<=0) ? MAXPARTICLES : nparticles;
39+
40+
if(np==0) ERROR_LINE("Number of particles is zero! Check your configuration.")
3941
if(np==1){
40-
auto data_d1=RunningStateHost_t(np,RunningTuple_t(std::copysign(1.,length),0.,0.,0., 0.,1.,0.,0.,0.,0.,0.,0.));
42+
if(group >1 && np/group==0) ERROR_LINE("Number of particles (or bunches of particles) is zero! Check your configuration.")
43+
auto data_d1=RunningStateHost_t(np,RunningTuple_t(std::copysign(1.,length)*group,0.,0.,0., 1.,0.,0.,0.,0.,0.,0.,0.));
4144
return data_d1;
4245
}
4346
size_t halfsize=np/2;
47+
if(group>1) halfsize/=group;
4448
RunningStateHost_t data_d(halfsize*2);
45-
auto data_de=RunningStateHost_t(halfsize,RunningTuple_t(-1.,0.,0.,0., 1.,0.,0.,0.,0.,0.,0.,0.));
46-
auto data_dh=RunningStateHost_t(halfsize,RunningTuple_t(1.,0.,0.,0., 1.,0.,0.,0.,0.,0.,0.,0.));
49+
auto data_de=RunningStateHost_t(halfsize,RunningTuple_t(-1.*group,0.,0.,0., 1.,0.,0.,0.,0.,0.,0.,0.));
50+
auto data_dh=RunningStateHost_t(halfsize,RunningTuple_t(1.*group,0.,0.,0., 1.,0.,0.,0.,0.,0.,0.,0.));
4751

4852

4953
//distribute them randomly in a line along Z
@@ -61,7 +65,7 @@ namespace loaddata{
6165
}
6266

6367

64-
RunningStateHost_t loadfile(std::string path){
68+
RunningStateHost_t loadfile(std::string path, size_t group=DEFAULT_GROUP){
6569
std::ifstream infile;
6670

6771
RunningStateHost_t data_d;
@@ -97,14 +101,16 @@ namespace loaddata{
97101
lineStream >> pix >> piy >> piz >> pfx >> pfy >> pfz >> deposit >> typ;
98102
// std::cout << line << std::endl;
99103
if(deposit<1) continue;
100-
unsigned int idep=deposit;
104+
105+
unsigned int idep=deposit/group;
106+
if(idep<1) continue;
101107
// std::cout << pix << "\t" << piy << "\t" << piz << "\t" << pfx << "\t" << pfy << "\t" << pfz << "\t" << deposit << std::endl;
102108
double d=sqrt((pfx-pix)*(pfx-pix)+(pfy-piy)*(pfy-piy)+(pfz-piz)*(pfz-piz));
103109

104110
if(d==0){
105111
for(unsigned int i=0;i<idep;i++){
106-
data_d.push_back(RunningTuple_t(-1.,pix, piy, piz, 1.,0.,0.,0.,0.,0.,0.,typ));
107-
data_d.push_back(RunningTuple_t(1.,pix, piy, piz, 1.,0.,0.,0.,0.,0.,0.,typ));
112+
data_d.push_back(RunningTuple_t(-1.*group,pix, piy, piz, 1.,0.,0.,0.,0.,0.,0.,typ));
113+
data_d.push_back(RunningTuple_t(1.*group,pix, piy, piz, 1.,0.,0.,0.,0.,0.,0.,typ));
108114
}
109115
}
110116
else{
@@ -117,8 +123,8 @@ namespace loaddata{
117123
std::uniform_real_distribution<double> dist(0.,d);
118124
for(unsigned int i=0;i<idep;i++){
119125
double vec=dist(mt);
120-
data_d.push_back(RunningTuple_t(-1.,a*vec+pix, b*vec+piy, c*vec+piz, 1.,0.,0.,0.,0.,0.,0.,typ));
121-
data_d.push_back(RunningTuple_t(1.,a*vec+pix, b*vec+piy, c*vec+piz, 1.,0.,0.,0.,0.,0.,0.,typ));
126+
data_d.push_back(RunningTuple_t(-1.*group,a*vec+pix, b*vec+piy, c*vec+piz, 1.,0.,0.,0.,0.,0.,0.,typ));
127+
data_d.push_back(RunningTuple_t(1.*group,a*vec+pix, b*vec+piy, c*vec+piz, 1.,0.,0.,0.,0.,0.,0.,typ));
122128
}
123129
}
124130

include/main.inl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ int main(int argv, char** argc){
5454
bool draw=DEFAULT_DRAW;
5555
bool extrainfo=DEFAULT_EXTRAINFO;
5656
size_t nparticles=DEFAULT_PARTICLES;
57+
size_t group=DEFAULT_GROUP;
5758
size_t nsteps=DEFAULT_STEPS;
5859
double temperature=DEFAULT_T;
5960
double timestep=DEFAULT_TIME;
@@ -125,6 +126,8 @@ int main(int argv, char** argc){
125126
cmd.add(Zshift_Arg);
126127
TCLAP::ValueArg<double> Length_Arg("l", "Length","Deposit length", false, DEFAULT_LENGTH, "double");
127128
cmd.add(Length_Arg);
129+
TCLAP::ValueArg<size_t> Ngroup_Arg("g", "group","Group particle", false, DEFAULT_GROUP, "size_t");
130+
cmd.add(Ngroup_Arg);
128131

129132

130133
// Parse the argv array.
@@ -148,6 +151,7 @@ int main(int argv, char** argc){
148151
xshift = Xshift_Arg.getValue();
149152
yshift = Yshift_Arg.getValue();
150153
zshift = Zshift_Arg.getValue();
154+
group = Ngroup_Arg.getValue();
151155
length = Length_Arg.getValue();
152156
outputdir = Odir_Arg.getValue();
153157
PHYSMAPfile = PMap_Arg.getValue();
@@ -242,7 +246,8 @@ int main(int argv, char** argc){
242246
root_line_inl.add("Yshift",cfg::Setting::TypeFloat) = (float)yshift;
243247
root_line_inl.add("Zshift",cfg::Setting::TypeFloat) = (float)zshift;
244248
root_line_inl.add("Length",cfg::Setting::TypeFloat) = (float)length;
245-
root_line_inl.add("BunchSize",cfg::Setting::TypeInt) = bunchsize;root.add("ef", cfg::Setting::TypeString) = EFfile;
249+
root_line_inl.add("BunchSize",cfg::Setting::TypeInt) = bunchsize;
250+
root_line_inl.add("group",cfg::Setting::TypeInt) = (int)group;
246251

247252

248253

0 commit comments

Comments
 (0)