/* output_generic.cc - This file is part of MUSIC - a code to generate multi-scale initial conditions for cosmological simulations Copyright (C) 2010-13 Oliver Hahn */ #ifdef HAVE_HDF5 #include "output.hh" #include "HDF_IO.hh" class generic_output_plugin : public output_plugin { protected: using output_plugin::cf_; template< typename Tt > void write2HDF5( std::string fname, std::string dname, const MeshvarBnd& data ) { int n0 = data.size(0), n1 = data.size(1), n2 = data.size(2), nb = data.m_nbnd; std::vector vdata; vdata.reserve((unsigned)(n0+2*nb)*(n1+2*nb)*(n2+2*nb)); for(int i=-nb; i=(int)gh.levelmin(); --ilevel ) for( unsigned i=0; isize(0); ++i ) for( unsigned j=0; jsize(1); ++j ) for( unsigned k=0; ksize(2); ++k ) if( ! gh.is_refined(ilevel,i,j,k) ) { real_t rho = (*gh.get_grid(ilevel))(i,j,k); if( rho > rhomax ) { rhomax = rho; lvl_rhomax = ilevel; gh.cell_pos(ilevel, i, j, k, loc_rhomax); } if( rho < rhomin ) { rhomin = rho; lvl_rhomin = ilevel; gh.cell_pos(ilevel, i, j, k, loc_rhomin); } if( ilevel == (int)gh.levelmax() ) { if( rho > rhomax_lm ) { rhomax_lm = rho; gh.cell_pos(ilevel, i, j, k, loc_rhomax_lm); } if( rho < rhomin_lm ) { rhomin_lm = rho; gh.cell_pos(ilevel, i, j, k, loc_rhomin_lm); } } } double h = 1.0/(1<( "setup", "shift_x" )*h; shift[1] = -(double)cf_.getValue( "setup", "shift_y" )*h; shift[2] = -(double)cf_.getValue( "setup", "shift_z" )*h; if( gh.levelmin() != gh.levelmax() ) { LOGINFO("Global density extrema: "); LOGINFO(" minimum: delta=%f at (%f,%f,%f) (level=%d)",rhomin,loc_rhomin[0],loc_rhomin[1],loc_rhomin[2],lvl_rhomin); LOGINFO(" shifted back at (%f,%f,%f)",loc_rhomin[0]+shift[0],loc_rhomin[1]+shift[1],loc_rhomin[2]+shift[2]); LOGINFO(" maximum: delta=%f at (%f,%f,%f) (level=%d)",rhomax,loc_rhomax[0],loc_rhomax[1],loc_rhomax[2],lvl_rhomax); LOGINFO(" shifted back at (%f,%f,%f)",loc_rhomax[0]+shift[0],loc_rhomax[1]+shift[1],loc_rhomax[2]+shift[2]); LOGINFO("Density extrema on finest level: "); LOGINFO(" minimum: delta=%f at (%f,%f,%f)",rhomin_lm,loc_rhomin_lm[0],loc_rhomin_lm[1],loc_rhomin_lm[2]); LOGINFO(" shifted back at (%f,%f,%f)",loc_rhomin_lm[0]+shift[0],loc_rhomin_lm[1]+shift[1],loc_rhomin_lm[2]+shift[2]); LOGINFO(" maximum: delta=%f at (%f,%f,%f)",rhomax_lm,loc_rhomax_lm[0],loc_rhomax_lm[1],loc_rhomax_lm[2]); LOGINFO(" shifted back at (%f,%f,%f)",loc_rhomax_lm[0]+shift[0],loc_rhomax_lm[1]+shift[1],loc_rhomax_lm[2]+shift[2]); }else{ LOGINFO("Global density extrema: "); LOGINFO(" minimum: delta=%f at (%f,%f,%f)",rhomin,loc_rhomin[0],loc_rhomin[1],loc_rhomin[2]); LOGINFO(" shifted back at (%f,%f,%f)",loc_rhomin[0]+shift[0],loc_rhomin[1]+shift[1],loc_rhomin[2]+shift[2]); LOGINFO(" maximum: delta=%f at (%f,%f,%f)",rhomax,loc_rhomax[0],loc_rhomax[1],loc_rhomax[2]); LOGINFO(" shifted back at (%f,%f,%f)",loc_rhomax[0]+shift[0],loc_rhomax[1]+shift[1],loc_rhomax[2]+shift[2]); } } void write_dm_potential( const grid_hierarchy& gh ) { char sstr[128]; for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) { sprintf(sstr,"level_%03d_DM_potential",ilevel); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); } } void write_gas_potential( const grid_hierarchy& gh ) { char sstr[128]; for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) { sprintf(sstr,"level_%03d_BA_potential",ilevel); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); } } void write_gas_velocity( int coord, const grid_hierarchy& gh ) { char sstr[128]; for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) { if( coord == 0 ) sprintf(sstr,"level_%03d_BA_vx",ilevel); else if( coord == 1 ) sprintf(sstr,"level_%03d_BA_vy",ilevel); else if( coord == 2 ) sprintf(sstr,"level_%03d_BA_vz",ilevel); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); } } void write_gas_position( int coord, const grid_hierarchy& gh ) { } void write_gas_density( const grid_hierarchy& gh ) { char sstr[128]; for( unsigned ilevel=0; ilevel<=levelmax_; ++ilevel ) { sprintf(sstr,"level_%03d_BA_rho",ilevel); write2HDF5( fname_, sstr, *gh.get_grid(ilevel) ); } } void finalize( void ) { } }; namespace{ output_plugin_creator_concrete< generic_output_plugin > creator("generic"); } #endif