From 7e69a43036bed5e330c8783a643372c089882181 Mon Sep 17 00:00:00 2001 From: Oliver Hahn Date: Thu, 21 Mar 2013 22:09:59 +0100 Subject: [PATCH] added new option "gadget_cell_centered=yes/no" to enable half-cell shift for gadget particle positions --- plugins/output_gadget2.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/plugins/output_gadget2.cc b/plugins/output_gadget2.cc index 1df1d9e..b10b004 100644 --- a/plugins/output_gadget2.cc +++ b/plugins/output_gadget2.cc @@ -24,6 +24,7 @@ public: bool do_baryons_; double omegab_; double gamma_; + bool shift_halfcell_; protected: @@ -755,6 +756,8 @@ public: nfiles_ = cf.getValueSafe("output","gadget_num_files",1); blongids_ = cf.getValueSafe("output","gadget_longids",false); + + shift_halfcell_ = cf.getValueSafe("output","gadget_cell_centered",false); //if( nfiles_ < (int)ceil((double)npart/(double)npartmax_) ) // LOGWARN("Should use more files."); @@ -954,7 +957,15 @@ public: shift[1] = -(double)cf_.getValue( "setup", "shift_y" )*h; shift[2] = -(double)cf_.getValue( "setup", "shift_z" )*h; } -*/ +*/ + + if( shift_halfcell_ ) + { + double h = 1.0/(1<<(levelmin_+1)); + shift = new double[3]; + shift[0] = shift[1] = shift[2] = -h; + } + size_t npart = npfine+npcoarse; size_t nwritten = 0; @@ -1212,7 +1223,14 @@ public: shift[1] = -(double)cf_.getValue( "setup", "shift_y" )*h; shift[2] = -(double)cf_.getValue( "setup", "shift_z" )*h; }*/ - + + if( shift_halfcell_ ) + { + double h = 1.0/(1<<(levelmin_+1)); + shift = new double[3]; + shift[0] = shift[1] = shift[2] = -h; + } + size_t npart = gh.count_leaf_cells(gh.levelmin(), gh.levelmax());; size_t nwritten = 0;