//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/Aggregate/Paracrystal2D.h
//! @brief     Defines class Paracrystal2D.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_SAMPLE_AGGREGATE_PARACRYSTAL2D_H
#define BORNAGAIN_SAMPLE_AGGREGATE_PARACRYSTAL2D_H

#include "Sample/Aggregate/ICrystal2D.h"
#include <array>
#include <heinz/Complex.h>
#include <memory>

class Profile2D;

//! Interference function of a 2D paracrystal.

class Paracrystal2D : public ICrystal2D {
public:
    Paracrystal2D(const IParticle& particle, const Lattice2D& lattice, double damping_length,
                  double domain_size_1, double domain_size_2);

    ~Paracrystal2D() override;

    void setDomainSizes(double size_1, double size_2);
    void setProbabilityDistributions(const Profile2D& pdf_1, const Profile2D& pdf_2);
    void setDampingLength(double damping_length);

    std::string className() const final { return "Paracrystal2D"; }

#ifndef SWIG
    Paracrystal2D* clone() const override;
    void validate() const override;

    std::vector<double> domainSizes() const;

    double dampingLength() const { return m_damping_length; }

    const Profile2D* pdf1() const { return m_pdf1.get(); }
    const Profile2D* pdf2() const { return m_pdf2.get(); }

private:
    double interferenceForXi(double xi, double qx, double qy) const override;
    double interference1D(double qx, double qy, double xi, size_t index) const;
    complex_t FTPDF(double qx, double qy, double xi, size_t index) const;
    void transformToPrincipalAxes(double qx, double qy, double gamma, double delta, double& q_pa_1,
                                  double& q_pa_2) const;

    std::unique_ptr<Profile2D> m_pdf1, m_pdf2;
    double m_damping_length; //!< Damping length for removing delta function singularity at q=0.
    std::array<double, 2> m_domain_sizes; //!< Coherence domain sizes

#endif // SWIG
};

#endif // BORNAGAIN_SAMPLE_AGGREGATE_PARACRYSTAL2D_H
