//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/Aggregate/LongRangeOrdered2D.cpp
//! @brief     Implements the interface class LongRangeOrdered2D.
//!
//! @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)
//
//  ************************************************************************************************

#include "Sample/Aggregate/LongRangeOrdered2D.h"

LongRangeOrdered2D::LongRangeOrdered2D(const IParticle& particle, double lateral_var)
    : Ordered2D(particle)
    , m_lateral_pos_var(lateral_var)
{
}

LongRangeOrdered2D::~LongRangeOrdered2D() = default;

void LongRangeOrdered2D::setLateralPositionVariance(double var)
{
    if (var < 0.0)
        throw std::runtime_error(className()
                                 + "::setLateralPosVariance called with negative argument");
    m_lateral_pos_var = var;
}

double LongRangeOrdered2D::DWfactor(R3 q) const
{
    // remove z component for two-dimensional interference functions:
    if (supportsMultilayer())
        q.setZ(0.0);
    return std::exp(-q.mag2() * m_lateral_pos_var * m_lateral_pos_var);
}
void LongRangeOrdered2D::instructLRClone(LongRangeOrdered2D* dest) const
{
    instructClone(dest);
    dest->setLateralPositionVariance(lateralPositionVariance());
}
