mirror of
https://github.com/cosmo-sims/MUSIC.git
synced 2024-09-19 17:03:46 +02:00
merge (with experimental new rewrite of random number factory)
This commit is contained in:
parent
507b6daa41
commit
90f0d15170
3 changed files with 98 additions and 2 deletions
6
main.cc
6
main.cc
|
@ -270,6 +270,7 @@ double compute_finest_sigma( grid_hierarchy& u )
|
|||
/*****************************************************************************************************/
|
||||
|
||||
region_generator_plugin *the_region_generator;
|
||||
RNG_plugin *the_random_number_generator;
|
||||
|
||||
int main (int argc, const char * argv[])
|
||||
{
|
||||
|
@ -286,8 +287,9 @@ int main (int argc, const char * argv[])
|
|||
if( argc != 2 ){
|
||||
std::cout << " This version is compiled with the following plug-ins:\n";
|
||||
|
||||
print_region_generator_plugins();
|
||||
print_region_generator_plugins();
|
||||
print_transfer_function_plugins();
|
||||
print_RNG_plugins();
|
||||
print_output_plugins();
|
||||
|
||||
std::cerr << "\n In order to run, you need to specify a parameter file!\n\n";
|
||||
|
@ -390,7 +392,6 @@ int main (int argc, const char * argv[])
|
|||
transfer_function_plugin *the_transfer_function_plugin
|
||||
= select_transfer_function_plugin( cf );
|
||||
|
||||
|
||||
cosmology cosmo( cf );
|
||||
|
||||
std::cout << " - starting at a=" << cosmo.astart << std::endl;
|
||||
|
@ -430,6 +431,7 @@ int main (int argc, const char * argv[])
|
|||
|
||||
the_region_generator = select_region_generator_plugin( cf );
|
||||
|
||||
the_random_number_generator = select_RNG_plugin( cf );
|
||||
//------------------------------------------------------------------------------
|
||||
//... determine run parameters
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
51
random.cc
51
random.cc
|
@ -12,6 +12,57 @@
|
|||
|
||||
// TODO: move all this into a plugin!!!
|
||||
|
||||
std::map< std::string, RNG_plugin_creator *>&
|
||||
get_RNG_plugin_map()
|
||||
{
|
||||
static std::map< std::string, RNG_plugin_creator* > RNG_plugin_map;
|
||||
return RNG_plugin_map;
|
||||
}
|
||||
|
||||
void print_RNG_plugins()
|
||||
{
|
||||
std::map< std::string, RNG_plugin_creator *>& m = get_RNG_plugin_map();
|
||||
std::map< std::string, RNG_plugin_creator *>::iterator it;
|
||||
it = m.begin();
|
||||
std::cout << " - Available random number generator plug-ins:\n";
|
||||
while( it!=m.end() )
|
||||
{
|
||||
if( (*it).second )
|
||||
std::cout << "\t\'" << (*it).first << "\'\n";
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
RNG_plugin *select_RNG_plugin( config_file& cf )
|
||||
{
|
||||
std::string rngname = cf.getValueSafe<std::string>( "random", "generator", "MUSIC" );
|
||||
|
||||
RNG_plugin_creator *the_RNG_plugin_creator
|
||||
= get_RNG_plugin_map()[ rngname ];
|
||||
|
||||
if( !the_RNG_plugin_creator )
|
||||
{
|
||||
std::cerr << " - Error: random number generator plug-in \'" << rngname << "\' not found." << std::endl;
|
||||
LOGERR("Invalid/Unregistered random number generator plug-in encountered : %s",rngname.c_str() );
|
||||
print_RNG_plugins();
|
||||
throw std::runtime_error("Unknown random number generator plug-in");
|
||||
|
||||
}else
|
||||
{
|
||||
std::cout << " - Selecting random number generator plug-in \'" << rngname << "\'..." << std::endl;
|
||||
LOGUSER("Selecting random number generator plug-in : %s",rngname.c_str() );
|
||||
}
|
||||
|
||||
RNG_plugin *the_RNG_plugin
|
||||
= the_RNG_plugin_creator->create( cf );
|
||||
|
||||
return the_RNG_plugin;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if defined(FFTW3) && defined( SINGLE_PRECISION)
|
||||
//#define fftw_complex fftwf_complex
|
||||
|
|
43
random.hh
43
random.hh
|
@ -32,6 +32,49 @@
|
|||
#include "constraints.hh"
|
||||
|
||||
|
||||
class RNG_plugin{
|
||||
protected:
|
||||
config_file *pcf_; //!< pointer to config_file from which to read parameters
|
||||
public:
|
||||
explicit RNG_plugin( config_file& cf )
|
||||
: pcf_( &cf )
|
||||
{ }
|
||||
virtual ~RNG_plugin() { }
|
||||
virtual bool is_multiscale() const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct RNG_plugin_creator
|
||||
{
|
||||
virtual RNG_plugin * create( config_file& cf ) const = 0;
|
||||
virtual ~RNG_plugin_creator() { }
|
||||
};
|
||||
|
||||
std::map< std::string, RNG_plugin_creator *>&
|
||||
get_RNG_plugin_map();
|
||||
|
||||
void print_RNG_plugins( void );
|
||||
|
||||
template< class Derived >
|
||||
struct RNG_plugin_creator_concrete : public RNG_plugin_creator
|
||||
{
|
||||
//! register the plugin by its name
|
||||
RNG_plugin_creator_concrete( const std::string& plugin_name )
|
||||
{
|
||||
get_RNG_plugin_map()[ plugin_name ] = this;
|
||||
}
|
||||
|
||||
//! create an instance of the plugin
|
||||
RNG_plugin* create( config_file& cf ) const
|
||||
{
|
||||
return new Derived( cf );
|
||||
}
|
||||
};
|
||||
|
||||
typedef RNG_plugin RNG_instance;
|
||||
RNG_plugin *select_RNG_plugin( config_file& cf );
|
||||
|
||||
|
||||
/*!
|
||||
* @brief encapsulates all things random number generator related
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue