2020-08-21 17:03:33 +02:00
|
|
|
// This file is part of monofonIC (MUSIC2)
|
|
|
|
// A software package to generate ICs for cosmological simulations
|
|
|
|
// Copyright (C) 2020 by Oliver Hahn
|
|
|
|
//
|
|
|
|
// monofonIC is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// monofonIC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-05-09 21:41:54 +02:00
|
|
|
|
2019-08-02 17:55:00 +02:00
|
|
|
#pragma once
|
2019-05-09 21:41:54 +02:00
|
|
|
|
|
|
|
#include <string>
|
2019-07-31 11:57:40 +02:00
|
|
|
#include <cstring>
|
2019-05-09 21:41:54 +02:00
|
|
|
#include <map>
|
|
|
|
|
2019-08-02 17:55:00 +02:00
|
|
|
#include <particle_container.hh>
|
|
|
|
#include <general.hh>
|
|
|
|
#include <grid_fft.hh>
|
|
|
|
#include <config_file.hh>
|
2020-09-10 04:12:32 +02:00
|
|
|
#include <cosmology_calculator.hh>
|
2019-05-09 21:41:54 +02:00
|
|
|
|
2019-08-07 17:51:40 +02:00
|
|
|
enum class output_type {particles,field_lagrangian,field_eulerian};
|
|
|
|
|
2019-11-01 12:03:02 +01:00
|
|
|
|
2019-08-02 17:55:00 +02:00
|
|
|
class output_plugin
|
2019-07-31 11:57:40 +02:00
|
|
|
{
|
|
|
|
protected:
|
2020-04-04 20:55:24 +02:00
|
|
|
//! reference to the config_file object that holds all configuration options
|
|
|
|
config_file &cf_;
|
2019-07-31 11:57:40 +02:00
|
|
|
|
2020-09-10 04:12:32 +02:00
|
|
|
//! reference to the cosmology calculator object that does all things cosmological
|
|
|
|
std::unique_ptr<cosmology::calculator> &pcc_;
|
|
|
|
|
2019-07-31 11:57:40 +02:00
|
|
|
//! output file or directory name
|
|
|
|
std::string fname_;
|
2019-08-02 17:55:00 +02:00
|
|
|
|
|
|
|
//! name of the output interface
|
2019-07-31 11:57:40 +02:00
|
|
|
std::string interface_name_;
|
|
|
|
public:
|
|
|
|
//! constructor
|
2020-09-10 04:12:32 +02:00
|
|
|
output_plugin(config_file &cf, std::unique_ptr<cosmology::calculator>& pcc, std::string interface_name )
|
|
|
|
: cf_(cf), pcc_(pcc), interface_name_(interface_name)
|
2019-07-31 11:57:40 +02:00
|
|
|
{
|
2020-04-04 20:55:24 +02:00
|
|
|
fname_ = cf_.get_value<std::string>("output", "filename");
|
2019-07-31 11:57:40 +02:00
|
|
|
}
|
|
|
|
|
2019-08-02 17:55:00 +02:00
|
|
|
//! virtual destructor
|
|
|
|
virtual ~output_plugin(){}
|
|
|
|
|
2019-08-02 19:07:45 +02:00
|
|
|
//! routine to write particle data for a species
|
2020-01-24 15:00:32 +01:00
|
|
|
virtual void write_particle_data(const particle::container &pc, const cosmo_species &s, double Omega_species ) {};
|
2019-07-31 11:57:40 +02:00
|
|
|
|
2019-08-02 19:07:45 +02:00
|
|
|
//! routine to write gridded fluid component data for a species
|
|
|
|
virtual void write_grid_data(const Grid_FFT<real_t> &g, const cosmo_species &s, const fluid_component &c ) {};
|
|
|
|
|
|
|
|
//! routine to query whether species is written as grid data
|
2019-08-07 17:51:40 +02:00
|
|
|
virtual output_type write_species_as ( const cosmo_species &s ) const = 0;
|
|
|
|
|
|
|
|
//! routine to query whether species is written as grid data
|
|
|
|
// virtual bool write_species_as_grid( const cosmo_species &s ) = 0;
|
2019-08-02 19:07:45 +02:00
|
|
|
|
|
|
|
//! routine to query whether species is written as particle data
|
2019-08-07 17:51:40 +02:00
|
|
|
// virtual bool write_species_as_particles( const cosmo_species &s ){ return !write_species_as_grid(s); }
|
2019-11-01 12:03:02 +01:00
|
|
|
|
|
|
|
//! query if output wants 64bit precision for real values
|
|
|
|
virtual bool has_64bit_reals() const = 0;
|
|
|
|
|
|
|
|
//! query if output wants 64bit precision for integer values
|
|
|
|
virtual bool has_64bit_ids() const = 0;
|
2019-08-02 19:07:45 +02:00
|
|
|
|
2019-08-02 17:55:00 +02:00
|
|
|
//! routine to return a multiplicative factor that contains the desired position units for the output
|
2019-07-31 11:57:40 +02:00
|
|
|
virtual real_t position_unit() const = 0;
|
|
|
|
|
2019-08-02 17:55:00 +02:00
|
|
|
//! routine to return a multiplicative factor that contains the desired velocity units for the output
|
2019-07-31 11:57:40 +02:00
|
|
|
virtual real_t velocity_unit() const = 0;
|
2020-07-02 01:27:53 +02:00
|
|
|
|
|
|
|
//! routine to return a multiplicative factor that contains critical density * box volume in desired mass units for output
|
|
|
|
virtual real_t mass_unit() const = 0;
|
2019-05-09 21:41:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief implements abstract factory design pattern for output plug-ins
|
|
|
|
*/
|
|
|
|
struct output_plugin_creator
|
|
|
|
{
|
|
|
|
//! create an instance of a plug-in
|
2020-09-10 04:12:32 +02:00
|
|
|
virtual std::unique_ptr<output_plugin> create(config_file &cf, std::unique_ptr<cosmology::calculator>& pcc) const = 0;
|
2019-07-31 11:57:40 +02:00
|
|
|
|
2019-05-09 21:41:54 +02:00
|
|
|
//! destroy an instance of a plug-in
|
2019-07-31 11:57:40 +02:00
|
|
|
virtual ~output_plugin_creator() {}
|
2019-05-09 21:41:54 +02:00
|
|
|
};
|
|
|
|
|
2019-07-31 11:57:40 +02:00
|
|
|
//! maps the name of a plug-in to a pointer of the factory pattern
|
|
|
|
std::map<std::string, output_plugin_creator *> &get_output_plugin_map();
|
2019-05-09 21:41:54 +02:00
|
|
|
|
|
|
|
//! print a list of all registered output plug-ins
|
|
|
|
void print_output_plugins();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief concrete factory pattern for output plug-ins
|
|
|
|
*/
|
2019-07-31 11:57:40 +02:00
|
|
|
template <class Derived>
|
2019-05-09 21:41:54 +02:00
|
|
|
struct output_plugin_creator_concrete : public output_plugin_creator
|
|
|
|
{
|
|
|
|
//! register the plug-in by its name
|
2019-07-31 11:57:40 +02:00
|
|
|
output_plugin_creator_concrete(const std::string &plugin_name)
|
2019-05-09 21:41:54 +02:00
|
|
|
{
|
2019-07-31 11:57:40 +02:00
|
|
|
get_output_plugin_map()[plugin_name] = this;
|
2019-05-09 21:41:54 +02:00
|
|
|
}
|
2019-07-31 11:57:40 +02:00
|
|
|
|
2019-05-09 21:41:54 +02:00
|
|
|
//! create an instance of the plug-in
|
2020-09-10 04:12:32 +02:00
|
|
|
std::unique_ptr<output_plugin> create(config_file &cf, std::unique_ptr<cosmology::calculator>& pcc) const
|
2019-05-09 21:41:54 +02:00
|
|
|
{
|
2020-09-10 04:12:32 +02:00
|
|
|
return std::make_unique<Derived>(cf,pcc); // Derived( cf );
|
2019-05-09 21:41:54 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//! failsafe version to select the output plug-in
|
2020-09-10 04:12:32 +02:00
|
|
|
std::unique_ptr<output_plugin> select_output_plugin(config_file &cf, std::unique_ptr<cosmology::calculator>& pcc);
|
2019-05-09 21:41:54 +02:00
|
|
|
|