//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/Interface/RoughnessModels.cpp
//! @brief     Implements RoughnessModels enumerator and Python wrapper.
//!
//! @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/Interface/RoughnessModels.h"
#include "Base/Math/Functions.h"
#include "Base/Util/Assert.h"
#include <cmath>
#include <numbers>

using std::numbers::pi;

ErfRoughness::ErfRoughness()
    : RoughnessModel()
{
}

double ErfRoughness::transient(double x, double sigma) const
{
    ASSERT(sigma >= 0);
    if (sigma == 0.0)
        return Math::Heaviside(x);

    const double prefactor = std::sqrt(1.0 / 2.0);
    return (1.0 + std::erf(prefactor * x / sigma)) / 2.0;
}

ErfRoughness* ErfRoughness::clone() const
{
    return new ErfRoughness;
}

TanhRoughness::TanhRoughness()
    : RoughnessModel()
{
}

double TanhRoughness::transient(double x, double sigma) const
{
    ASSERT(sigma >= 0);
    if (sigma == 0.0)
        return Math::Heaviside(x);

    const double prefactor = pi / 2. / std::sqrt(3);
    return (1.0 + std::tanh(prefactor * x / sigma)) / 2.0;
}

TanhRoughness* TanhRoughness::clone() const
{
    return new TanhRoughness;
}
