/*******************************************************************************
 * This file is part of Shadowfax
 * Copyright (C) 2015 Bert Vandenbroucke (bert.vandenbroucke@gmail.com)
 *
 * Shadowfax is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Shadowfax is distributed in the hope that it will be useful,
 * but WITOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Shadowfax. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

/**
 * @file SpecificICGenerator.hpp
 *
 * @brief ICGenerator for hard-coded initial conditions
 *
 * @author Bert Vandenbroucke (bert.vandenbroucke@ugent.be)
 */
#ifndef SPECIFICICGENERATOR_HPP
#define SPECIFICICGENERATOR_HPP

#include "ICGenerator.hpp"  // for ICMode::IC_RAND, etc

class DelCont;
class ParticleVector;

/*! @brief Type of special initial condition to generate */
enum ICSpecType {
    /*! Gresho vortex (2D only) */
    IC_SPEC_GRESHO = 0,
    /*! Sedov-Taylor blastwave */
    IC_SPEC_SEDOV_TAYLOR,
    /*! Dwarf galaxy halo (experimental) */
    IC_SPEC_DWARF,
    /*! Kelvin-Helmholtz test (2D only) */
    IC_SPEC_KH,
    /*! Evrard collapse test (3D only) */
    IC_SPEC_EVRARD,
    /*! N-body test (3D only) */
    IC_SPEC_NBODY
};

/**
 * @brief ICGenerator to generate hardcoded initial conditions
 *
 * Used to generate initial conditions that cannot be generated by the
 * BlockICGenerator. Code to generate positions and hydrodynamical quantities
 * is hardcoded in member functions of this class.
 */
class SpecificICGenerator : public ICGenerator {
  private:
    /*! @brief Adiabatic index of the gas in the initial condition */
    double _gamma;

    /*! @brief Number of gas particles to generate */
    unsigned int _ngaspart;

    /*! @brief Number of dark matter particles to generate */
    unsigned int _ndmpart;

    /*! @brief ICMode of grid to use */
    unsigned int _mode;

    /*! @brief ICSpecType of the initial condition */
    unsigned int _type;
    /*! @brief Density contrast at the edge of the Evrard sphere (outside the
     *  sphere is a homogeneous region) */
    double _evrardfrac;

    /*! @brief DelCont specifying the dimensions of the simulation box */
    DelCont* _container;

    /*! @brief Flag indicating whether the simulation box is periodic (true) or
     *  reflective (false) */
    bool _periodic;

    void make_cartesian_grid(ParticleVector& plist);
    void make_random_grid(ParticleVector& plist);
    void relax_grid(ParticleVector& grid, unsigned int numlloyd);
    void apply_profiles(ParticleVector& grid);

    void apply_profile_gresho(ParticleVector& grid);
    void apply_profile_sedov_taylor(ParticleVector& grid);
    void apply_profile_dwarf(ParticleVector& grid);
    void apply_profile_kh(ParticleVector& grid);
    void apply_profile_evrard(ParticleVector& grid);

    void set_conserved_variables(ParticleVector& grid);

    void add_DM(ParticleVector& grid);

    void add_DM_plummer(ParticleVector& grid);

    double rand_double();

  public:
    SpecificICGenerator(unsigned int ngaspart, unsigned int ndmpart,
                        unsigned int type = IC_SPEC_GRESHO,
                        unsigned int seed = 42, unsigned int mode = IC_RAND,
                        double gamma = 1.66667);
    virtual ~SpecificICGenerator();

    ParticleVector generate(unsigned int numlloyd = 10,
                            bool conserved_variables = false);

    static double gplummer(double q);
};

#endif  // SPECIFICICGENERATOR_HPP
