/* region_convex_hull.cc - This file is part of MUSIC - a code to generate multi-scale initial conditions for cosmological simulations Copyright (C) 2010-13 Oliver Hahn */ #include #include #include #include #include #include #include #include #include "region_generator.hh" #include "convex_hull.hh" #include "point_file_reader.hh" //! Convex hull region plugin class region_convex_hull_plugin : public region_generator_plugin{ private: convex_hull *phull_; int shift[3], shift_level, padding_; double vfac_; bool do_extra_padding_; std::vector level_dist_; void apply_shift( size_t Np, double *p, int *shift, int levelmin ) { double dx = 1.0/(1< pp; vfac_ = cf.getValue("cosmology","vfact"); padding_ = cf.getValue("setup","padding"); std::string point_file = cf.getValue("setup","region_point_file"); point_reader pfr; pfr.read_points_from_file( point_file, vfac_, pp ); if( cf.containsKey("setup","region_point_shift") ) { std::string point_shift = cf.getValue("setup","region_point_shift"); if(sscanf( point_shift.c_str(), "%d,%d,%d", &shift[0],&shift[1],&shift[2] )!=3){ LOGERR("Error parsing triple for region_point_shift"); throw std::runtime_error("Error parsing triple for region_point_shift"); } unsigned point_levelmin = cf.getValue("setup","region_point_levelmin"); apply_shift( pp.size()/3, &pp[0], shift, point_levelmin ); shift_level = point_levelmin; } // compute the convex hull phull_ = new convex_hull( &pp[0], pp.size()/3 ); //expand the ellipsoid by one grid cell unsigned levelmax = cf.getValue("setup","levelmax"); double dx = 1.0/(1ul<expand( sqrt(3.)*dx ); // output the center double c[3] = { phull_->centroid_[0], phull_->centroid_[1], phull_->centroid_[2] }; LOGINFO("Region center from convex hull centroid determined at\n\t (%f,%f,%f)",c[0],c[1],c[2]); //----------------------------------------------------------------- // when querying the bounding box, do we need extra padding? do_extra_padding_ = false; // conditions should be added here { std::string output_plugin = cf.getValue("output","format"); if( output_plugin == std::string("grafic2") ) do_extra_padding_ = true; } level_dist_.assign( levelmax+1, 0.0 ); // generate the higher level ellipsoids for( int ilevel = levelmax_-1; ilevel > 0; --ilevel ) { dx = 1.0/(1ul<<(ilevel)); level_dist_[ilevel] = level_dist_[ilevel+1] + padding_ * dx; } } ~region_convex_hull_plugin() { delete phull_; } void get_AABB( double *left, double *right, unsigned level ) { for( int i=0; i<3; ++i ) { left[i] = phull_->left_[i]; right[i] = phull_->right_[i]; } double dx = 1.0/(1ul<check_point( x, level_dist_[ilevel] ); } bool is_grid_dim_forced( size_t* ndims ) { return false; } void get_center( double *xc ) { xc[0] = phull_->centroid_[0]; xc[1] = phull_->centroid_[1]; xc[2] = phull_->centroid_[2]; } void get_center_unshifted( double *xc ) { double dx = 1.0/(1<centroid_[0], phull_->centroid_[1], phull_->centroid_[2] }; xc[0] = c[0]+shift[0]*dx; xc[1] = c[1]+shift[1]*dx; xc[2] = c[2]+shift[2]*dx; } }; namespace{ region_generator_plugin_creator_concrete< region_convex_hull_plugin > creator("convex_hull"); }