File: Gauss.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (71 lines) | stat: -rw-r--r-- 2,096 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/SoftParticle/Gauss.cpp
//! @brief     Implements class GaussSphere.
//!
//! @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/SoftParticle/Gauss.h"
#include "Base/Util/Assert.h"
#include "Sample/Shape/BoxNet.h"
#include "Sample/Shape/TruncatedEllipsoidNet.h"
#include <limits>
#include <numbers>

using std::numbers::pi;

GaussSphere::GaussSphere(const std::vector<double> P)
    : IFormfactor(P)
    , m_mean_radius(m_P[0])
{
    validateOrThrow();
}

GaussSphere::GaussSphere(double mean_radius)
    : GaussSphere(std::vector<double>{mean_radius})
{
}

complex_t GaussSphere::formfactor(C3 q) const
{
    ASSERT(m_validated);
    const double max_ql = std::sqrt(-4 * pi * std::log(std::numeric_limits<double>::min()) / 3);

    double qzh = q.z().real() * m_mean_radius;
    if (std::abs(qzh) > max_ql)
        return 0.0;
    double qxr = q.x().real() * m_mean_radius;
    if (std::abs(qxr) > max_ql)
        return 0.0;
    double qyr = q.y().real() * m_mean_radius;
    if (std::abs(qyr) > max_ql)
        return 0.0;

    return pow(m_mean_radius, 3) * std::exp(-(qxr * qxr + qyr * qyr + qzh * qzh) / 4.0 / pi);
}

std::string GaussSphere::validate() const
{
    std::vector<std::string> errs;
    requestGt0(errs, m_mean_radius, "mean_radius");
    if (!errs.empty())
        return jointError(errs);

    const double R = m_mean_radius;
    m_shape3D = std::make_unique<TruncatedEllipsoidNet>(R, R, R, 2 * R, 0);

    m_validated = true;
    return "";
}

bool GaussSphere::contains(const R3&) const
{
    throw std::runtime_error("Soft particle cannot be used as mesocrystal outer shape");
}