WaveBlocksND
hdf5writer.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 //need H5 Cpp header for HDF interface
4 #include "H5Cpp.h"
5 
6 #include <string>
7 #include <map>
8 #include <cstdio>
9 #include <vector>
10 
11 #include <Eigen/Core>
12 
15 #include "waveblocks/types.hpp"
17 
18 namespace waveblocks
19 {
20  namespace io
21  {
22 
23  //using namespaces for convenience
24  using namespace H5;
25 
34  struct ctype{
35  double real=0.;
36  double imag=0.;
37  }instanceof;
38 
46  template<int D>
47  class hdf5writer
48  {
49  //declare friend for easy use
50  friend struct ctype;
51  public:
60  hdf5writer(std::string name):filename_(name),mytype_(sizeof(instanceof)),file_(filename_,H5F_ACC_TRUNC)
61  {
62  //fixed writing type for easy overlap with python interface
63  mytype_.insertMember( "r", HOFFSET(ctype, real), PredType::NATIVE_DOUBLE);
64  mytype_.insertMember( "i", HOFFSET(ctype, imag), PredType::NATIVE_DOUBLE);
65 
66  hsize_t q1[]={1};
67  DataSpace s1(RANK1,q1);
68  aversion=file_.createAttribute("file_version",PredType::NATIVE_INT,s1);
69  aversion.write(PredType::NATIVE_INT,&version);
70  }
76  template<class MultiIndex>
78  {
79  Eigen::Matrix<complex_t, Eigen::Dynamic, 1> coeffs=utilities::PacketToCoefficients<wavepackets::ScalarHaWp<D,MultiIndex>>::to(packet);
80  int a=coeffs.rows();
81  int b=coeffs.cols();
82  csize=a*b;
83  }
89  template<class MultiIndex>
91  {
92  //get number of coefficients
93  set_coeff_dim(packet);
94 
95  //set group structure
96  set_group_structure(dt);
97 
98  //set up chunk dimension
99  set_chunk_dim();
100 
101  //set up space for file
102  set_file_dataspace();
103 
104  //allocate datasets needs to be after select writespace
105  allocate_datasets();
106 
107  //set up elementary spaces
108  set_elem_space();
109 
110  //select space within elemtary space
111  select_elem_hyperslabs();
112  }
117  void set_write_packet(bool flag)
118  {
119  wrlist["packet"]=flag;
120  }
125  void set_write_energies(bool flag)
126  {
127  wrlist["energy"]=flag;
128  }
133  void set_write_norm(bool flag)
134  {
135  wrlist["norm"]=flag;
136  }
141  void set_timestep_packet(int timestep)
142  {
143  timestepsize_packet=timestep;
144  }
149  void set_timestep_norm(int timestep)
150  {
151  timestepsize_norms=timestep;
152  }
157  void set_timestep_energies(int timestep)
158  {
159  timestepsize_epot=timestep;
160  timestepsize_ekin=timestep;
161  }
166  void set_timestep_epot(int timestep)
167  {
168  timestepsize_epot=timestep;
169  }
174  void set_timestep_ekin(int timestep)
175  {
176  timestepsize_ekin=timestep;
177  }
184  void set_chunk_dim(void)
185  {
186  constexpr int dim = D; //alias for D
187  //time chunk dimension the same for all
188  hsize_t chunk_dims6[]={1};
189  plist_time.setChunk(RANK1,chunk_dims6);
190  plist_time.setFillValue(PredType::NATIVE_INT,&iref);
191 
192  if(wrlist["packet"])
193  {
194  hsize_t chunk_dims1[]={1,dim,1};
195  plist_qp.setChunk(RANK3,chunk_dims1);
196  plist_qp.setFillValue(mytype_,&instanceof);
197 
198  hsize_t chunk_dims2[]={1,dim,dim};
199  plist_QP.setChunk(RANK3,chunk_dims2);
200  plist_QP.setFillValue(mytype_,&instanceof);
201 
202  hsize_t chunk_dims3[]={1,1,1};
203  plist_S.setChunk(RANK3,chunk_dims3);
204  plist_S.setFillValue(mytype_,&instanceof);
205 
206  hsize_t chunk_dims5[2];
207  chunk_dims5[0]=1;
208  chunk_dims5[1]=csize;
209  plist_c.setChunk(RANK2,chunk_dims5);
210  plist_c.setFillValue(mytype_,&instanceof);
211  }
212  if(wrlist["energy"])
213  {
214  hsize_t chunk_dims4[]={1,1};
215  plist_energy.setChunk(RANK2,chunk_dims4);
216  plist_energy.setFillValue(PredType::NATIVE_DOUBLE,&dref);
217 
218  }
219  if(wrlist["norm"])
220  {
221  hsize_t chunk_dims6[]={1,1};
222  plist_norms.setChunk(RANK2,chunk_dims6);
223  plist_norms.setFillValue(PredType::NATIVE_DOUBLE,&dref);
224  }
225  }
233  void set_elem_space(void)
234  {
235  //timeelem space const for all timesteps
236  timeelem[0]=1;
237  DataSpace t6(RANK1,timeelem);
238  timelemspace=t6;
239 
240  constexpr int dim = D;
241  if(wrlist["packet"])
242  {
243  qpelem[0]=1;
244  qpelem[1]=dim;
245  qpelem[2]=1;
246  DataSpace t1(RANK3,qpelem);
247  qpelemspace=t1;
248  QPelem[0]=1;
249  QPelem[1]=dim;
250  QPelem[2]=dim;
251  DataSpace t2(RANK3,QPelem);
252  QPelemspace=t2;
253  Selem[0]=1;
254  Selem[1]=1;
255  Selem[2]=1;
256  DataSpace t3(RANK3,Selem);
257  Selemspace=t3;
258 
259  celem[0]=1;
260  celem[1]=csize;
261  DataSpace t5(RANK2,celem);
262  celemspace=t5;
263  }
264  if(wrlist["energy"])
265  {
266  energyelem[0]=1;
267  energyelem[1]=1;
268  DataSpace t4(RANK2,energyelem);
269  energyelemspace=t4;
270  }
271  if(wrlist["norm"])
272  {
273  normelem[0]=1;
274  normelem[1]=1;
275  DataSpace t6(RANK2,normelem);
276  normelemspace=t6;
277  }
278  }
286  void set_group_structure(double dt)
287  {
288  H5std_string a1=datablock_string;
289  gblock = std::make_shared<Group>(file_.createGroup(a1));
290  hsize_t q1[]={1};
291  DataSpace s1(RANK1,q1);
292  apacket=gblock->createAttribute("packet",PredType::NATIVE_INT,s1);
293  aenergy=gblock->createAttribute("energy",PredType::NATIVE_INT,s1);
294  anorm=gblock->createAttribute("norm",PredType::NATIVE_INT,s1);
295  adt=gblock->createAttribute("dt",PredType::NATIVE_DOUBLE,s1);
296  adt.write(PredType::NATIVE_DOUBLE,&dt);
297 
298  if(wrlist["packet"])
299  {
300  int ap=1;
301  apacket.write(PredType::NATIVE_INT,&ap);
302  H5std_string a2=(datablock_string+wavepacket_group_string);
303  gpacket = std::make_shared<Group>(file_.createGroup(a2));
304  H5std_string a3=(datablock_string+wavepacket_group_string+packet_group_string);
305  gPi = std::make_shared<Group>(file_.createGroup(a3));
306  H5std_string a4=(datablock_string+wavepacket_group_string+coefficient_group_string);
307  gcoefficient = std::make_shared<Group>(file_.createGroup(a4));
308  }
309  else
310  {
311  int ap=0;
312  apacket.write(PredType::NATIVE_INT,&ap);
313  }
314  H5std_string a7=datablock_string+observables_group;
315  gobservables=std::make_shared<Group>(file_.createGroup(a7));
316  if(wrlist["energy"])
317  {
318  int ae=1;
319  aenergy.write(PredType::NATIVE_INT,&ae);
320  H5std_string a5 = (datablock_string+observables_group+energies_group);
321  genergy = std::make_shared<Group>(file_.createGroup(a5));
322  }
323  else
324  {
325  int ae=0;
326  aenergy.write(PredType::NATIVE_INT,&ae);
327  }
328  if(wrlist["norm"])
329  {
330  int an=1;
331  anorm.write(PredType::NATIVE_INT,&an);
332  H5std_string a6 = (datablock_string+observables_group+norms_group);
333  gnorms = std::make_shared<Group>(file_.createGroup(a6));
334  }
335  else
336  {
337  int an=0;
338  anorm.write(PredType::NATIVE_INT,&an);
339  }
340  }
348  {
349  constexpr int dim = D;
350 
351  hsize_t count6[]={1};
352  hsize_t start6[]={0};
353  hsize_t stride6[]={1};
354  hsize_t block6[]={1};
355  timelemspace.selectHyperslab(H5S_SELECT_SET, count6, start6, stride6, block6);
356 
357  if(wrlist["packet"])
358  {
359  //qp
360  hsize_t count1[]={1,dim,1};
361  hsize_t start1[]={0,0,0};
362  hsize_t stride1[]={1,1,1};
363  hsize_t block1[]={1,1,1};
364  //QP
365  hsize_t count2[]={1,dim,dim};
366  hsize_t start2[]={0,0,0};
367  hsize_t stride2[]={1,1,1};
368  hsize_t block2[]={1,1,1};
369  //S
370  hsize_t count3[]={1,1,1};
371  hsize_t start3[]={0,0,0};
372  hsize_t stride3[]={1,1,1};
373  hsize_t block3[]={1,1,1};
374 
375  //qp
376  qpelemspace.selectHyperslab(H5S_SELECT_SET, count1, start1, stride1, block1);
377  //QP
378  QPelemspace.selectHyperslab(H5S_SELECT_SET, count2, start2, stride2, block2);
379  //Selem also for adQ
380  Selemspace.selectHyperslab(H5S_SELECT_SET, count3, start3, stride3, block3);
381 
382  //coefficients
383  hsize_t count4[2];
384  count4[0]=1;
385  count4[1]=csize;
386  hsize_t start4[]={0,0};
387  hsize_t stride4[]={1,1};
388  hsize_t block4[]={1,1};
389  celemspace.selectHyperslab(H5S_SELECT_SET, count4, start4, stride4, block4);
390  }
391  if(wrlist["energy"])
392  {
393  hsize_t count5[]={1,1};
394  hsize_t start5[]={0,0};
395  hsize_t stride5[]={1,1};
396  hsize_t block5[]={1,1};
397  energyelemspace.selectHyperslab(H5S_SELECT_SET, count5, start5, stride5, block5);
398  }
399  if(wrlist["norm"])
400  {
401  hsize_t count6[]={1,1};
402  hsize_t start6[]={0,0};
403  hsize_t stride6[]={1,1};
404  hsize_t block6[]={1,1};
405  normelemspace.selectHyperslab(H5S_SELECT_SET, count6, start6, stride6, block6);
406  }
407  }
408 
417  {
418  constexpr int dim = D;
419  if(wrlist["packet"])
420  {
421  //set up q and p
422  hsize_t dim1[]={1,dim,1};
423  DataSpace d1(RANK3,dim1,maxdims3);
424  qspace=d1;
425  pspace=d1;
426  //set up Q and P
427  hsize_t dim2[]={1,dim,dim};
428  DataSpace d2(RANK3,dim2,maxdims3);
429  Qspace=d2;
430  Pspace=d2;
431  //set up S and adQ
432  hsize_t dim3[]={1,1,1};
433  DataSpace d3(RANK3,dim3,maxdims3);
434  Sspace=d3;
435  adQspace=d3;
436 
437  //set up coefficients
438  hsize_t dim5[2];
439  dim5[0]=1;
440  dim5[1]=csize;
441  DataSpace d5(RANK2,dim5,maxdims2);
442  cspace=d5;
443 
444  hsize_t dimt1[]={1};
445  DataSpace dt1(RANK1,dimt1,maxdims1);
446  timespace_packet=dt1;
447  }
448  if(wrlist["energy"])
449  {
450  hsize_t dim4[]={1,1};
451  DataSpace d4(RANK2,dim4,maxdims2);
452  energyspace_ekin=d4;
453  energyspace_epot=d4;
454 
455  hsize_t dimt2[]={1};
456  DataSpace dt2(RANK1,dimt2,maxdims1);
457  timespace_ekin=dt2;
458  timespace_epot=dt2;
459  }
460  if(wrlist["norm"])
461  {
462  hsize_t dim5[]={1,1};
463  DataSpace d5(RANK2,dim5,maxdims2);
464  normspace=d5;
465 
466  hsize_t dimt3[]={1};
467  DataSpace dt3(RANK1,dimt3,maxdims1);
468  timespace_norms=dt3;
469  }
470  }
477  void allocate_datasets(void)
478  {
479  if(wrlist["packet"])
480  {
481  H5std_string pack=datablock_string+wavepacket_group_string+packet_group_string;
482  qs=std::make_shared<DataSet>(file_.createDataSet(pack+"/q",mytype_,qspace,plist_qp));
483  ps=std::make_shared<DataSet>(file_.createDataSet(pack+"/p",mytype_,pspace,plist_qp));
484  Qs=std::make_shared<DataSet>(file_.createDataSet(pack+"/Q",mytype_,Qspace,plist_QP));
485  Ps=std::make_shared<DataSet>(file_.createDataSet(pack+"/P",mytype_,Pspace,plist_QP));
486  Ss=std::make_shared<DataSet>(file_.createDataSet(pack+"/S",mytype_,Sspace,plist_S));
487  adQs=std::make_shared<DataSet>(file_.createDataSet(pack+"/adQ",mytype_,adQspace,plist_S));
488  H5std_string tpack=datablock_string+wavepacket_group_string;
489  times_packet=std::make_shared<DataSet>(file_.createDataSet(tpack+"/timegrid",PredType::NATIVE_INT,timespace_packet,plist_time));
490 
491  H5std_string cff=datablock_string+wavepacket_group_string+coefficient_group_string;
492  coeffs=std::make_shared<DataSet>(file_.createDataSet(cff+"/c_0",mytype_,cspace,plist_c));
493  }
494  if(wrlist["energy"])
495  {
496  H5std_string ename=datablock_string+observables_group+energies_group;
497  H5std_string enameepot=ename+"/potential";
498  energys_epot=std::make_shared<DataSet>(file_.createDataSet(enameepot,PredType::NATIVE_DOUBLE,energyspace_epot,plist_energy));
499  H5std_string enameekin=ename+"/kinetic";
500  energys_ekin=std::make_shared<DataSet>(file_.createDataSet(enameekin,PredType::NATIVE_DOUBLE,energyspace_ekin,plist_energy));
501  H5std_string engtime1=ename+"/timegrid_pot";
502  times_epot=std::make_shared<DataSet>(file_.createDataSet(engtime1,PredType::NATIVE_INT,timespace_epot,plist_time));
503  H5std_string engtime2=ename+"/timegrid_kin";
504  times_ekin=std::make_shared<DataSet>(file_.createDataSet(engtime2,PredType::NATIVE_INT,timespace_ekin,plist_time));
505  }
506  if(wrlist["norm"])
507  {
508  H5std_string tmm=datablock_string+observables_group+norms_group+"/norm";
509  normss=std::make_shared<DataSet>(file_.createDataSet(tmm,PredType::NATIVE_DOUBLE,normspace,plist_norms));
510  H5std_string tmt=datablock_string+observables_group+norms_group+"/timegrid";
511  times_norms=std::make_shared<DataSet>(file_.createDataSet(tmt,PredType::NATIVE_INT,timespace_norms,plist_time));
512  }
513  }
520  {
521  if(wrlist["norm"])
522  {
523  exnorms[0]=index_norm;
524  exnorms[1]=1;
525  ex_timegrid_norms[0]=index_norm;
526  }
527  else
528  {
529  std::cout<<"ERROR: setup_extension_norms called with bool=false\n";
530  }
531  }
538  {
539  if(wrlist["energy"])
540  {
541  exepot[0]=index_epot;
542  exepot[1]=1;
543  ex_timegrid_epot[0]=index_epot;
544  }
545  else
546  {
547  std::cout<<"ERROR: setup_extension_epot called with bool=false\n";
548  }
549  }
556  {
557  if(wrlist["energy"])
558  {
559  exekin[0]=index_ekin;
560  exekin[1]=1;
561  ex_timegrid_ekin[0]=index_ekin;
562  }
563  else
564  {
565  std::cout<<"ERROR: setup_extension_ekin called with bool=false\n";
566  }
567  }
574  {
575  constexpr int dim=D;
576  if(wrlist["packet"])
577  {
578  exqp[0]=index_packet;
579  exqp[1]=dim;
580  exqp[2]=1;
581  exQP[0]=index_packet;
582  exQP[1]=dim;
583  exQP[2]=dim;
584  exS[0]=index_packet;
585  exS[1]=1;
586  exS[2]=1;
587 
588  exc[0]=index_packet;
589  exc[1]=csize;
590  ex_timegrid_packet[0]=index_packet;
591  }
592  else
593  {
594  std::cout<<"ERROR: setup_extension_packet called with bool=false\n";
595  }
596  }
603  {
604  if(wrlist["packet"])
605  {
606  //qp
607  qs->extend(exqp);
608  ps->extend(exqp);
609  //QP
610  Qs->extend(exQP);
611  Ps->extend(exQP);
612  //Senergies
613  Ss->extend(exS);
614  adQs->extend(exS);
615 
616  coeffs->extend(exc);
617  times_packet->extend(ex_timegrid_packet);
618  }
619  else
620  {
621  std::cout<<"ERROR: extend_dataset_packet called with bool=false\n";
622  }
623  }
630  {
631  if(wrlist["norm"])
632  {
633  normss->extend(exnorms);
634  times_norms->extend(ex_timegrid_norms);
635  }
636  else
637  {
638  std::cout<<"ERROR: extend_dataset_norms called with bool=false\n";
639  }
640  }
647  {
648  if(wrlist["energy"])
649  {
650  energys_epot->extend(exepot);
651  times_epot->extend(ex_timegrid_epot);
652  }
653  else
654  {
655  std::cout<<"ERROR: extend_dataset_epot called with bool=false\n";
656  }
657  }
664  {
665  if(wrlist["energy"])
666  {
667  energys_ekin->extend(exekin);
668  times_ekin->extend(ex_timegrid_ekin);
669  }
670  else
671  {
672  std::cout<<"ERROR: extend_dataset_ekin called with bool=false\n";
673  }
674  }
681  {
682  if(wrlist["energy"])
683  {
684  energyspace_ekin=energys_ekin->getSpace();
685  timespace_ekin=times_ekin->getSpace();
686  }
687  else
688  {
689  std::cout<<"ERROR: update_filespace_ekin called with bool=false\n";
690  }
691  }
698  {
699  if(wrlist["energy"])
700  {
701  energyspace_epot=energys_epot->getSpace();
702  timespace_epot=times_epot->getSpace();
703  }
704  else
705  {
706  std::cout<<"ERROR: update_filespace_epot called with bool=false\n";
707  }
708  }
715  {
716  if(wrlist["norm"])
717  {
718  normspace=normss->getSpace();
719  timespace_norms=times_norms->getSpace();
720  }
721  else
722  {
723  std::cout<<"ERROR: update_filespace_norms called with bool=false\n";
724  }
725  }
732  {
733  if(wrlist["packet"])
734  {
735  //qp
736  qspace=qs->getSpace();
737  pspace=ps->getSpace();
738  //QP
739  Qspace=Qs->getSpace();
740  Pspace=Ps->getSpace();
741  //S
742  Sspace=Ss->getSpace();
743  adQspace=adQs->getSpace();
744  cspace=coeffs->getSpace();
745  timespace_packet=times_packet->getSpace();
746  }
747  else
748  {
749  std::cout<<"ERROR: update_filespace_packet called with bool=false\n";
750  }
751  }
759  void transform(std::vector<ctype>& newdata,Eigen::Matrix<complex_t,D,D> mat)
760  {
761  constexpr int dim=D;
762  newdata.resize(dim*dim);
763  std::complex<double>* tmp(mat.data());
764  for(int p=0;p<dim*dim;++p)
765  {
766  newdata[p].real=tmp[p].real();
767  newdata[p].imag=tmp[p].imag();
768  }
769  }
777  void transform(std::vector<ctype>& newdata,Eigen::Matrix<real_t,D,1> mat)
778  {
779  constexpr int dim=D;
780  newdata.resize(dim);
781  double* tmp(mat.data());
782  for(int p=0;p<dim;++p)
783  {
784  newdata[p].real=tmp[p];
785  newdata[p].imag=0.;
786  }
787  }
795  void transform(std::vector<ctype>& newdata,complex_t arg)
796  {
797  ctype newarg;
798  newarg.real=arg.real();
799  newarg.imag=arg.imag();
800  newdata.push_back(newarg);
801  }
809  void transform(std::vector<ctype>& newdata,Eigen::Matrix<complex_t, Eigen::Dynamic, 1> cmat)
810  {
811  newdata.resize(csize);
812  for(int q=0;q<csize;++q)
813  {
814  newdata[q].real=cmat[q].real();
815  newdata[q].imag=cmat[q].imag();
816  }
817  }
825  void transform(std::vector<ctype>& newdata,real_t arg)
826  {
827  ctype newarg;
828  newarg.real=arg;
829  newarg.imag=0.;
830  newdata.push_back(newarg);
831  }
839  template<class MultiIndex>
841  {
842  const auto& params = packetto.parameters();
843  if(wrlist["packet"])
844  {
845  if(tindex_packet%timestepsize_packet==0)
846  {
847  select_file_writespace_packet();
848 
849  std::vector<ctype> myc;
851  coeffs->write(myc.data(),mytype_,celemspace,cspace);
852 
853  std::vector<ctype> myQ;
854  transform(myQ,params.Q());
855  Qs->write(myQ.data(),mytype_,QPelemspace,Qspace);
856 
857  std::vector<ctype> myP;
858  transform(myP,params.P());
859  Ps->write(myP.data(),mytype_,QPelemspace,Pspace);
860 
861  std::vector<ctype> myq;
862  transform(myq,params.q());
863  qs->write(myq.data(),mytype_,qpelemspace,qspace);
864 
865  std::vector<ctype> myp;
866  transform(myp,params.p());
867  ps->write(myp.data(),mytype_,qpelemspace,pspace);
868 
869  std::vector<ctype> myS;
870  transform(myS,params.S());
871  Ss->write(myS.data(),mytype_,Selemspace,Sspace);
872 
873  std::vector<ctype> myadQ;
874  transform(myadQ,params.sdQ());
875  adQs->write(myadQ.data(),mytype_,Selemspace,adQspace);
876 
877  times_packet->write(&tindex_packet,PredType::NATIVE_INT,timelemspace,timespace_packet);
878 
879  advance_packet();
880  }
881  tindex_packet+=1;
882  }
883  else
884  {
885  std::cout<<"ERROR: store_packet called with bool=false\n";
886  }
887  }
893  void store_energies(double epot_,double ekin_)
894  {
895  if(wrlist["energy"])
896  {
897  if(tindex_ekin%timestepsize_ekin==0)
898  {
899  select_file_writespace_ekin();
900  energys_ekin->write(&ekin_,PredType::NATIVE_DOUBLE,energyelemspace,energyspace_ekin);
901  times_ekin->write(&tindex_ekin,PredType::NATIVE_INT,timelemspace,timespace_ekin);
902  advance_ekin();
903  }
904  tindex_ekin+=1;
905  if(tindex_epot%timestepsize_epot==0)
906  {
907  select_file_writespace_epot();
908  energys_epot->write(&epot_,PredType::NATIVE_DOUBLE,energyelemspace,energyspace_epot);
909  times_epot->write(&tindex_epot,PredType::NATIVE_INT,timelemspace,timespace_epot);
910  advance_epot();
911  }
912  tindex_epot+=1;
913  }
914  else
915  {
916  std::cout<<"ERROR: store_energies called with bool=false\n";
917  }
918  }
924  template<class MultiIndex>
926  {
927  if(wrlist["norm"])
928  {
929  if(tindex_norm%timestepsize_norms==0)
930  {
931  double mynorm = waveblocks::observables::norm<D,MultiIndex>(packet);
932  select_file_writespace_norm();
933  normss->write(&mynorm,PredType::NATIVE_DOUBLE,normelemspace,normspace);
934  times_norms->write(&tindex_norm,PredType::NATIVE_INT,timelemspace,timespace_norms);
935  advance_norm();
936  }
937  tindex_norm+=1;
938  }
939  else
940  {
941  std::cout<<"ERROR: store_norms called with bool=false\n";
942  }
943  }
950  {
951  constexpr int dim=D;
952  if(wrlist["packet"])
953  {
954  //qp
955  hsize_t count1[]={1,dim,1};
956  hsize_t start1[3];
957  start1[0]=index_packet-1;
958  start1[1]=0;
959  start1[2]=0;
960  hsize_t stride1[]={1,1,1};
961  hsize_t block1[]={1,1,1};
962  //QP
963  hsize_t count2[]={1,dim,dim};
964  hsize_t start2[3];
965  start2[0]=index_packet-1;
966  start2[1]=0;
967  start2[2]=0;
968  hsize_t stride2[]={1,1,1};
969  hsize_t block2[]={1,1,1};
970  //S
971  hsize_t count3[]={1,1,1};
972  hsize_t start3[3];
973  start3[0]=index_packet-1;
974  start3[1]=0;
975  start3[2]=0;
976  hsize_t stride3[]={1,1,1};
977  hsize_t block3[]={1,1,1};
978  //qp
979  qspace.selectHyperslab(H5S_SELECT_SET, count1, start1, stride1, block1);
980  pspace.selectHyperslab(H5S_SELECT_SET, count1, start1, stride1, block1);
981  //QP
982  Qspace.selectHyperslab(H5S_SELECT_SET, count2, start2, stride2, block2);
983  Pspace.selectHyperslab(H5S_SELECT_SET, count2, start2, stride2, block2);
984  //S
985  Sspace.selectHyperslab(H5S_SELECT_SET, count3, start3, stride3, block3);
986  adQspace.selectHyperslab(H5S_SELECT_SET, count3, start3, stride3, block3);
987 
988  //coefficients
989  hsize_t count4[2];
990  count4[0]=1;
991  count4[1]=csize;
992  hsize_t start4[2];
993  start4[0]=index_packet-1;
994  start4[1]=0;
995  hsize_t stride4[]={1,1};
996  hsize_t block4[]={1,1};
997  cspace.selectHyperslab(H5S_SELECT_SET, count4, start4, stride4, block4);
998 
999  hsize_t countt1[]={1};
1000  hsize_t startt1[1];
1001  startt1[0]=index_packet-1;
1002  hsize_t stridet1[]={1};
1003  hsize_t blockt1[]={1};
1004  timespace_packet.selectHyperslab(H5S_SELECT_SET, countt1, startt1, stridet1, blockt1);
1005  }
1006  else
1007  {
1008  std::cout<<"ERROR: select_file_writespace_packet called with bool=false\n";
1009  }
1010  }
1017  void advance_packet(void)
1018  {
1019  index_packet+=1;
1020  setup_extension_packet();
1021  extend_dataset_packet();
1022  update_filespace_packet();
1023  }
1030  {
1031  if(wrlist["energy"])
1032  {
1033  hsize_t count5[]={1,1};
1034  hsize_t start5[2];
1035  start5[0]=index_ekin-1;
1036  start5[1]=0;
1037  hsize_t stride5[]={1,1};
1038  hsize_t block5[]={1,1};
1039  energyspace_ekin.selectHyperslab(H5S_SELECT_SET, count5, start5, stride5, block5);
1040 
1041  hsize_t countt2[]={1};
1042  hsize_t startt2[1];
1043  startt2[0]=index_ekin-1;
1044  hsize_t stridet2[]={1};
1045  hsize_t blockt2[]={1};
1046  timespace_ekin.selectHyperslab(H5S_SELECT_SET, countt2, startt2, stridet2, blockt2);
1047  }
1048  else
1049  {
1050  std::cout<<"ERROR: select_file_writespace_ekin called with bool=false\n";
1051  }
1052  }
1059  void advance_ekin(void)
1060  {
1061  index_ekin+=1;
1062  setup_extension_ekin();
1063  extend_dataset_ekin();
1064  update_filespace_ekin();
1065  }
1072  {
1073  if(wrlist["energy"])
1074  {
1075  hsize_t count5[]={1,1};
1076  hsize_t start5[2];
1077  start5[0]=index_epot-1;
1078  start5[1]=0;
1079  hsize_t stride5[]={1,1};
1080  hsize_t block5[]={1,1};
1081  energyspace_epot.selectHyperslab(H5S_SELECT_SET, count5, start5, stride5, block5);
1082 
1083  hsize_t countt3[]={1};
1084  hsize_t startt3[1];
1085  startt3[0]=index_epot-1;
1086  hsize_t stridet3[]={1};
1087  hsize_t blockt3[]={1};
1088  timespace_epot.selectHyperslab(H5S_SELECT_SET, countt3, startt3, stridet3, blockt3);
1089  }
1090  else
1091  {
1092  std::cout<<"ERROR: select_file_writespace_epot called with bool=false\n";
1093  }
1094  }
1101  void advance_epot(void)
1102  {
1103  index_epot+=1;
1104  setup_extension_epot();
1105  extend_dataset_epot();
1106  update_filespace_epot();
1107  }
1114  {
1115  if(wrlist["norm"])
1116  {
1117  hsize_t count6[]={1,1};
1118  hsize_t start6[2];
1119  start6[0]=index_norm-1;
1120  start6[1]=0;
1121  hsize_t stride6[]={1,1};
1122  hsize_t block6[]={1,1};
1123  normspace.selectHyperslab(H5S_SELECT_SET, count6, start6, stride6, block6);
1124 
1125  hsize_t countt4[]={1};
1126  hsize_t startt4[1];
1127  startt4[0]=index_norm-1;
1128  hsize_t stridet4[]={1};
1129  hsize_t blockt4[]={1};
1130  timespace_norms.selectHyperslab(H5S_SELECT_SET, countt4, startt4, stridet4, blockt4);
1131  }
1132  else
1133  {
1134  std::cout<<"ERROR: select_file_writespace_norms called with bool=false\n";
1135  }
1136  }
1143  void advance_norm(void)
1144  {
1145  index_norm+=1;
1146  setup_extension_norm();
1147  extend_dataset_norm();
1148  update_filespace_norm();
1149  }
1157  void cleanup_packet(void)
1158  {
1159  index_packet-=1;
1160  setup_extension_packet();
1161  extend_dataset_packet();
1162  }
1170  void cleanup_ekin(void)
1171  {
1172  index_ekin-=1;
1173  setup_extension_ekin();
1174  extend_dataset_ekin();
1175  }
1183  void cleanup_epot(void)
1184  {
1185  index_epot-=1;
1186  setup_extension_epot();
1187  extend_dataset_epot();
1188  }
1196  void cleanup_norm(void)
1197  {
1198  index_norm-=1;
1199  setup_extension_norm();
1200  extend_dataset_norm();
1201  }
1207  void poststructuring(void)
1208  {
1209  if(wrlist["packet"])
1210  {
1211  cleanup_packet();
1212  }
1213  if(wrlist["norm"])
1214  {
1215  cleanup_norm();
1216  }
1217  if(wrlist["energy"])
1218  {
1219  cleanup_ekin();
1220  cleanup_epot();
1221  }
1222  }
1223 
1224  private:
1225  H5std_string filename_;
1226  CompType mytype_;
1227  H5File file_;
1228  std::map<std::string,bool> wrlist={{"packet",1},{"energy",0},{"norm",0}};
1229  Attribute apacket;
1230  Attribute aenergy;
1231  Attribute anorm;
1232  Attribute adt;
1233  Attribute aversion;
1234  double dref=0.;
1235  int version=2;
1236  int iref=0;
1237  H5std_string packet_group_string="/Pi";
1238  H5std_string datablock_string="/datablock_0";
1239  H5std_string coefficient_group_string="/coefficients";
1240  H5std_string wavepacket_group_string="/wavepacket";
1241  H5std_string energies_group="/energies";
1242  H5std_string norms_group="/norm";
1243  H5std_string observables_group="/observables";
1244  DSetCreatPropList plist_qp;
1245  DSetCreatPropList plist_QP;
1246  DSetCreatPropList plist_S;
1247  DSetCreatPropList plist_energy;
1248  DSetCreatPropList plist_c;
1249  DSetCreatPropList plist_time;
1250  DSetCreatPropList plist_norms;
1251  const int RANK1=1;
1252  const int RANK2=2;
1253  const int RANK3=3;
1254  const hsize_t maxdims1[1]={H5S_UNLIMITED};
1255  const hsize_t maxdims2[2]={H5S_UNLIMITED,H5S_UNLIMITED};
1256  const hsize_t maxdims3[3]={H5S_UNLIMITED,H5S_UNLIMITED,H5S_UNLIMITED};
1257  hsize_t exqp[3];
1258  hsize_t exQP[3];
1259  hsize_t exS[3];
1260  hsize_t exc[2];
1261  hsize_t exekin[2];
1262  hsize_t exepot[2];
1263  hsize_t exnorms[2];
1264  hsize_t ex_timegrid_norms[1];
1265  hsize_t ex_timegrid_epot[1];
1266  hsize_t ex_timegrid_ekin[1];
1267  hsize_t ex_timegrid_packet[1];
1268  hsize_t qpelem[3];
1269  DataSpace qpelemspace;
1270  hsize_t QPelem[3];
1271  DataSpace QPelemspace;
1272  hsize_t Selem[3];
1273  DataSpace Selemspace;
1274  hsize_t energyelem[2];
1275  DataSpace energyelemspace;
1276  hsize_t timeelem[1];
1277  DataSpace timelemspace;
1278  hsize_t celem[2];
1279  DataSpace celemspace;
1280  hsize_t normelem[2];
1281  DataSpace normelemspace;
1282  int index_packet=1;
1283  int index_norm=1;
1284  int index_ekin=1;
1285  int index_epot=1;
1286  int timestepsize_norms=1;
1287  int timestepsize_ekin=1;
1288  int timestepsize_epot=1;
1289  int timestepsize_packet=1;
1290  int tindex_ekin=0;
1291  int tindex_epot=0;
1292  int tindex_norm=0;
1293  int tindex_packet=0;
1294  int csize;
1295  std::shared_ptr<Group> gblock;
1296  std::shared_ptr<Group> gpacket;
1297  std::shared_ptr<Group> gPi;
1298  std::shared_ptr<Group> gcoefficient;
1299  std::shared_ptr<Group> genergy;
1300  std::shared_ptr<Group> gnorms;
1301  std::shared_ptr<Group> gobservables;
1302  DataSpace qspace;
1303  std::shared_ptr<DataSet> qs;
1304  DataSpace pspace;
1305  std::shared_ptr<DataSet> ps;
1306  DataSpace Qspace;
1307  std::shared_ptr<DataSet> Qs;
1308  DataSpace Pspace;
1309  std::shared_ptr<DataSet> Ps;
1310  DataSpace Sspace;
1311  std::shared_ptr<DataSet> Ss;
1312  DataSpace adQspace;
1313  std::shared_ptr<DataSet> adQs;
1314  DataSpace cspace;
1315  std::shared_ptr<DataSet> coeffs;
1316  DataSpace timespace_packet;
1317  std::shared_ptr<DataSet> times_packet;
1318  DataSpace timespace_ekin;
1319  std::shared_ptr<DataSet> times_ekin;
1320  DataSpace timespace_epot;
1321  std::shared_ptr<DataSet> times_epot;
1322  DataSpace timespace_norms;
1323  std::shared_ptr<DataSet> times_norms;
1324  DataSpace energyspace_ekin;
1325  std::shared_ptr<DataSet> energys_ekin;
1326  DataSpace energyspace_epot;
1327  std::shared_ptr<DataSet> energys_epot;
1328  DataSpace normspace;
1329  std::shared_ptr<DataSet> normss;
1330  };
1331  }
1332 }
DataSpace timespace_epot
space for timegrid epot
Definition: hdf5writer.hpp:1320
void cleanup_epot(void)
reverse last dataset extension for epot
Definition: hdf5writer.hpp:1183
The ctype struct for writing complex numbers.
Definition: hdf5writer.hpp:34
void set_write_packet(bool flag)
sets bool value for writing the packet(matrices and coefficients)
Definition: hdf5writer.hpp:117
DataSpace timelemspace
space of timegrid element written from program to file needed by HDF interface
Definition: hdf5writer.hpp:1277
std::shared_ptr< Group > gPi
group for matrices in packet
Definition: hdf5writer.hpp:1297
void setup_extension_epot(void)
setup extension for epot
Definition: hdf5writer.hpp:537
void allocate_datasets(void)
allocate space for datasets
Definition: hdf5writer.hpp:477
Definition: coefficients_file_parser.cpp:10
void extend_dataset_epot(void)
extend dataset for next timestep for epot
Definition: hdf5writer.hpp:646
std::shared_ptr< DataSet > Ss
dataset for packet.S() in file
Definition: hdf5writer.hpp:1311
DataSpace energyelemspace
space of energy element written from program to file needed by HDF interface
Definition: hdf5writer.hpp:1275
DataSpace Sspace
space for packet.S() in file
Definition: hdf5writer.hpp:1310
DSetCreatPropList plist_S
PropList for packet.S()
Definition: hdf5writer.hpp:1246
DataSpace pspace
space for packet.p() in file
Definition: hdf5writer.hpp:1304
std::shared_ptr< Group > gcoefficient
group for coefficients in packet
Definition: hdf5writer.hpp:1298
H5std_string filename_
placeholder for filename
Definition: hdf5writer.hpp:1225
DataSpace qpelemspace
space of q,p element written from program to file needed by HDF interface
Definition: hdf5writer.hpp:1269
void setup_extension_norm(void)
setup extension for norms
Definition: hdf5writer.hpp:519
function p(by, bw, bv)
Definition: jquery.js:23
void select_elem_hyperslabs(void)
From HDF interface select element hyperslabs.
Definition: hdf5writer.hpp:347
void prestructuring(waveblocks::wavepackets::ScalarHaWp< D, MultiIndex > packet, double dt)
prestructure after knowing bool values and packet
Definition: hdf5writer.hpp:90
DataSpace timespace_ekin
space for timegrid ekin
Definition: hdf5writer.hpp:1318
void set_timestep_epot(int timestep)
set timestep for writing epot
Definition: hdf5writer.hpp:166
void store_packet(const waveblocks::wavepackets::ScalarHaWp< D, MultiIndex > &packetto)
store ScalarHaWp<D,Multiindex> packet
Definition: hdf5writer.hpp:840
void set_timestep_norm(int timestep)
set timestep for writing norms
Definition: hdf5writer.hpp:149
void advance_ekin(void)
advance writing position for ekin and extends set
Definition: hdf5writer.hpp:1059
DataSpace timespace_packet
space for timegrid for packet in file
Definition: hdf5writer.hpp:1316
void set_file_dataspace(void)
set dataspace used in file
Definition: hdf5writer.hpp:416
H5File file_
H5File placeholder.
Definition: hdf5writer.hpp:1227
void store_energies(double epot_, double ekin_)
store energies in chosen timestep
Definition: hdf5writer.hpp:893
void cleanup_norm(void)
reverse last dataset extension for norms
Definition: hdf5writer.hpp:1196
std::shared_ptr< DataSet > energys_ekin
dataset for ekin in file
Definition: hdf5writer.hpp:1325
double imag
Definition: hdf5writer.hpp:36
DataSpace timespace_norms
space for timegrid in file
Definition: hdf5writer.hpp:1322
std::shared_ptr< DataSet > times_packet
dataset for timegrid for packet in file
Definition: hdf5writer.hpp:1317
std::complex< real_t > complex_t
Definition: types.hpp:15
void update_filespace_ekin(void)
update ekin filespace
Definition: hdf5writer.hpp:680
Attribute aenergy
attribute to save bool energy in datablock_0
Definition: hdf5writer.hpp:1230
double real_t
Definition: types.hpp:14
void advance_epot(void)
advance writing position for epot and extends set
Definition: hdf5writer.hpp:1101
DSetCreatPropList plist_QP
PropList for packet.Q() packet.P()
Definition: hdf5writer.hpp:1245
void select_file_writespace_packet(void)
select file writespace for packet
Definition: hdf5writer.hpp:949
std::shared_ptr< Group > gobservables
group for observables
Definition: hdf5writer.hpp:1301
DataSpace QPelemspace
space of Q,P element written from program to file needed by HDF interface
Definition: hdf5writer.hpp:1271
void set_group_structure(double dt)
set up group structure in file
Definition: hdf5writer.hpp:286
var ap
Definition: jquery.js:23
void set_timestep_energies(int timestep)
set timestep for writing energies
Definition: hdf5writer.hpp:157
std::shared_ptr< DataSet > times_ekin
dataset for timegrid for ekin in file
Definition: hdf5writer.hpp:1319
std::shared_ptr< DataSet > coeffs
dataset for coefficients in file
Definition: hdf5writer.hpp:1315
void update_filespace_packet(void)
update packet filespace
Definition: hdf5writer.hpp:731
void setup_extension_packet(void)
setup extension for packet
Definition: hdf5writer.hpp:573
std::shared_ptr< DataSet > Qs
dataset for packet.Q() in file
Definition: hdf5writer.hpp:1307
std::shared_ptr< DataSet > qs
dataset for packet.q() in file
Definition: hdf5writer.hpp:1303
hdf5writer(std::string name)
Construction of hdf5 writer class with a name.
Definition: hdf5writer.hpp:60
DSetCreatPropList plist_norms
PropList for norms.
Definition: hdf5writer.hpp:1250
std::shared_ptr< DataSet > times_norms
dataset for timegrid in file
Definition: hdf5writer.hpp:1323
void cleanup_ekin(void)
reverse last dataset extension for ekin
Definition: hdf5writer.hpp:1170
std::shared_ptr< DataSet > energys_epot
dataset for epot in file
Definition: hdf5writer.hpp:1327
void transform(std::vector< ctype > &newdata, Eigen::Matrix< complex_t, Eigen::Dynamic, 1 > cmat)
transform an Eigen::Matrix<complex_t,Eigen::Dynamic,1> to std::vector<ctype>
Definition: hdf5writer.hpp:809
int csize
runtime size coefficients
Definition: hdf5writer.hpp:1294
std::shared_ptr< DataSet > adQs
dataset for packet.sdQ() in file
Definition: hdf5writer.hpp:1313
std::shared_ptr< Group > gnorms
group for norms
Definition: hdf5writer.hpp:1300
void set_timestep_packet(int timestep)
set timestep for writing packet
Definition: hdf5writer.hpp:141
DSetCreatPropList plist_time
PropList for timegrids.
Definition: hdf5writer.hpp:1249
std::shared_ptr< DataSet > times_epot
dataset for timegrid for epot in file
Definition: hdf5writer.hpp:1321
std::shared_ptr< Group > genergy
group for energies
Definition: hdf5writer.hpp:1299
double real
Definition: hdf5writer.hpp:35
DSetCreatPropList plist_qp
PropList for packet.q() packet.p()
Definition: hdf5writer.hpp:1244
DataSpace Pspace
space for packet.P() in file
Definition: hdf5writer.hpp:1308
void select_file_writespace_epot(void)
select file writespace for epot
Definition: hdf5writer.hpp:1071
DataSpace normelemspace
space of norm element written from program to file needed by HDF interface
Definition: hdf5writer.hpp:1281
HaWpParamSet< D > & parameters()
Grants writeable access to the Hagedorn parameter set of the wavepacket.
Definition: hawp_commons.hpp:230
void transform(std::vector< ctype > &newdata, real_t arg)
transform real_t to std::vector<ctype>
Definition: hdf5writer.hpp:825
DSetCreatPropList plist_c
PropList for coefficients.
Definition: hdf5writer.hpp:1248
void update_filespace_norm(void)
update norms filespace
Definition: hdf5writer.hpp:714
void update_filespace_epot(void)
update epot filespace
Definition: hdf5writer.hpp:697
void transform(std::vector< ctype > &newdata, complex_t arg)
transform a std::complex variable into std::vector<ctype>
Definition: hdf5writer.hpp:795
void set_write_norm(bool flag)
sets bool value for writing norms
Definition: hdf5writer.hpp:133
void store_norm(const waveblocks::wavepackets::ScalarHaWp< D, MultiIndex > &packet)
store norms in chosen timestep
Definition: hdf5writer.hpp:925
std::shared_ptr< DataSet > normss
dataset for norms in file
Definition: hdf5writer.hpp:1329
void advance_norm(void)
advance writing position for norms and extends set
Definition: hdf5writer.hpp:1143
std::shared_ptr< DataSet > ps
dataset for packet.p() in file
Definition: hdf5writer.hpp:1305
void extend_dataset_packet(void)
extend dataset for next timestep for packet
Definition: hdf5writer.hpp:602
std::shared_ptr< Group > gpacket
group for packet
Definition: hdf5writer.hpp:1296
void set_coeff_dim(waveblocks::wavepackets::ScalarHaWp< D, MultiIndex > packet)
runtime function to evaluate number of coefficients
Definition: hdf5writer.hpp:77
DataSpace normspace
space for norms
Definition: hdf5writer.hpp:1328
DSetCreatPropList plist_energy
PropList for energies.
Definition: hdf5writer.hpp:1247
void set_chunk_dim(void)
Set up chunk dimension for the written variables.
Definition: hdf5writer.hpp:184
void transform(std::vector< ctype > &newdata, Eigen::Matrix< real_t, D, 1 > mat)
transform Eigen::Matrix<real_t,D,1> into std::vector<ctype>
Definition: hdf5writer.hpp:777
DataSpace cspace
space for coefficients in file
Definition: hdf5writer.hpp:1314
Concrete implementation of a scalar Hagedorn wavepacket.
Definition: hawp_commons.hpp:209
void extend_dataset_ekin(void)
extend dataset for next timestep for ekin
Definition: hdf5writer.hpp:663
void select_file_writespace_ekin(void)
select file writespace for ekin
Definition: hdf5writer.hpp:1029
Attribute anorm
attribute to save bool norm in datablock_0
Definition: hdf5writer.hpp:1231
struct waveblocks::io::ctype instanceof
void extend_dataset_norm(void)
extend dataset for next timestep for norms
Definition: hdf5writer.hpp:629
DataSpace energyspace_ekin
space for ekin in file
Definition: hdf5writer.hpp:1324
DataSpace adQspace
space for packet.sdQ() in file
Definition: hdf5writer.hpp:1312
Our HDF5 writer class.
Definition: hdf5writer.hpp:47
void transform(std::vector< ctype > &newdata, Eigen::Matrix< complex_t, D, D > mat)
transform Eigen::Matrix<complex_t,D,D> into std::vector<ctype>
Definition: hdf5writer.hpp:759
DataSpace Qspace
space for packet.Q() in file
Definition: hdf5writer.hpp:1306
void poststructuring(void)
last resize for exact length
Definition: hdf5writer.hpp:1207
var b
Definition: jquery.js:16
void setup_extension_ekin(void)
setup extension for ekin
Definition: hdf5writer.hpp:555
void select_file_writespace_norm(void)
select file writespace for norms
Definition: hdf5writer.hpp:1113
Attribute aversion
attribute to save file version
Definition: hdf5writer.hpp:1233
DataSpace Selemspace
space of S element written from program to file needed by HDF interface
Definition: hdf5writer.hpp:1273
CompType mytype_
declaration of H5:CompType member used for HDF interface to write ctype*
Definition: hdf5writer.hpp:1226
void set_write_energies(bool flag)
sets bool value for writing the energies
Definition: hdf5writer.hpp:125
DataSpace energyspace_epot
space for epot in file
Definition: hdf5writer.hpp:1326
void set_elem_space(void)
Set up elem space for HDF interface.
Definition: hdf5writer.hpp:233
Attribute adt
attribute to save dt in datablock_0
Definition: hdf5writer.hpp:1232
Attribute apacket
attribute to save bool packet in datablock_0
Definition: hdf5writer.hpp:1229
std::shared_ptr< DataSet > Ps
dataset for packet.P() in file
Definition: hdf5writer.hpp:1309
void advance_packet(void)
advance writing position for packet and extends set
Definition: hdf5writer.hpp:1017
std::shared_ptr< Group > gblock
group for datablock
Definition: hdf5writer.hpp:1295
void cleanup_packet(void)
reverse last dataset extension for packet
Definition: hdf5writer.hpp:1157
DataSpace qspace
space for packet.q() in file
Definition: hdf5writer.hpp:1302
void set_timestep_ekin(int timestep)
set timestep for writing ekin
Definition: hdf5writer.hpp:174
DataSpace celemspace
space of coefficient element written from program to file needed by HDF interface ...
Definition: hdf5writer.hpp:1279