File: PhysicalScan.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 (201 lines) | stat: -rw-r--r-- 5,725 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sim/Scan/PhysicalScan.cpp
//! @brief     Implements interface PhysicalScan.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2023
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "Sim/Scan/PhysicalScan.h"
#include "Base/Axis/Scale.h"
#include "Base/Math/Numeric.h"
#include "Device/Beam/Beam.h"
#include "Device/Beam/IFootprint.h"
#include "Device/Pol/PolFilter.h"
#include "Param/Distrib/Distributions.h"

PhysicalScan::PhysicalScan(const Scale& axis)
    : BeamScan(axis)
{
}

PhysicalScan::~PhysicalScan() = default;

void PhysicalScan::copyPhysicalScan(PhysicalScan* dest) const
{
    copyBeamScan(dest);
    if (m_lambda_distrib)
        dest->setWavelengthDistribution(*m_lambda_distrib);
    if (m_alpha_distrib)
        dest->setGrazingAngleDistribution(*m_alpha_distrib);
    if (m_phi_distrib)
        dest->setAzimuthalAngleDistribution(*m_phi_distrib);
}

bool PhysicalScan::isCommonFootprint() const
{
    const auto* ref_fp = m_beams.front()->footprint();
    if (!ref_fp) {
        // footprint is not set
        for (const auto& b : m_beams)
            if (b->footprint())
                return false;
    } else {
        // footprint is set
        double ref = ref_fp->widthRatio();
        for (const auto& b : m_beams) {
            if (!b->footprint())
                return false;
            // TODO check that footprint type is the same? Isn't it too expensive and redundant?
            if (!Numeric::almostEqual(b->footprint()->widthRatio(), ref, 1))
                return false;
        }
    }
    return true;
}

std::vector<const INode*> PhysicalScan::nodeChildren() const
{
    std::vector<const INode*> result;
    for (const INode* n : BeamScan::nodeChildren())
        result << n;
    if (m_lambda_distrib)
        result << m_lambda_distrib.get();
    if (m_alpha_distrib)
        result << m_alpha_distrib.get();
    if (m_phi_distrib)
        result << m_phi_distrib.get();
    return result;
}

void PhysicalScan::setFootprint(const IFootprint* footprint)
{
    for (auto& b : m_beams)
        b->setFootprint(footprint);
}

const IFootprint* PhysicalScan::commonFootprint() const
{
    if (!isCommonFootprint())
        throw std::runtime_error("Footprint function changes during scan. "
                                 "Use 'footprintAt(i)' instead.");
    return m_beams.front()->footprint();
}

const IFootprint* PhysicalScan::footprintAt(size_t i) const
{
    return m_beams[i]->footprint();
}

double PhysicalScan::commonWavelength() const
{
    if (!isCommonWavelength())
        throw std::runtime_error("Wavelength changes during scan. "
                                 "Use 'wavelengthAt(i)' instead.");
    return m_beams.front()->wavelength();
}

double PhysicalScan::wavelengthAt(size_t i) const
{
    return m_beams[i]->wavelength();
}

double PhysicalScan::commonGrazingAngle() const
{
    if (!isCommonGrazingAngle())
        throw std::runtime_error("Grazing angle changes during scan. "
                                 "Use 'grazingAngleAt(i)' instead.");
    return m_beams.front()->alpha_i();
}

void PhysicalScan::setWavelength(double lambda)
{
    for (auto& b : m_beams)
        b->setWavelength(lambda);
}

void PhysicalScan::setWavelengthDistribution(const IDistribution1D& distr)
{
    m_lambda_distrib.reset(distr.clone());
}

double PhysicalScan::grazingAngleAt(size_t i) const
{
    return m_beams[i]->alpha_i();
}

double PhysicalScan::commonAzimuthalAngle() const
{
    if (!isCommonAzimuthalAngle())
        throw std::runtime_error("Azimuthal angle changes during scan. "
                                 "Use 'azimuthalAngleAt(i)' instead.");
    return m_beams.front()->phi_i();
}

double PhysicalScan::azimuthalAngleAt(size_t i) const
{
    return m_beams[i]->phi_i();
}

void PhysicalScan::setGrazingAngle(double alpha)
{
    for (auto& b : m_beams)
        b->setGrazingAngle(alpha);
}

void PhysicalScan::setGrazingAngleDistribution(const IDistribution1D& distr)
{
    m_alpha_distrib.reset(distr.clone());
}

void PhysicalScan::setAzimuthalAngle(double phi)
{
    for (auto& b : m_beams)
        b->setAzimuthalAngle(phi);
}

void PhysicalScan::setAzimuthalAngleDistribution(const IDistribution1D& distr)
{
    m_phi_distrib.reset(distr.clone());
}

size_t PhysicalScan::nDistributionSamples() const
{
    size_t alpha_samples = m_alpha_distrib ? m_alpha_distrib->nSamples() : 1;
    size_t lambda_samples = m_lambda_distrib ? m_lambda_distrib->nSamples() : 1;
    size_t phi_samples = m_phi_distrib ? m_phi_distrib->nSamples() : 1;
    return lambda_samples * alpha_samples * phi_samples;
}

bool PhysicalScan::isCommonWavelength() const
{
    const auto ref = m_beams.front()->wavelength();
    for (const auto& b : m_beams)
        if (!Numeric::almostEqual(b->wavelength(), ref, 1))
            return false;
    return true;
}

bool PhysicalScan::isCommonGrazingAngle() const
{
    const auto ref = m_beams.front()->alpha_i();
    for (const auto& b : m_beams)
        if (!Numeric::almostEqual(b->alpha_i(), ref, 1))
            return false;
    return true;
}

bool PhysicalScan::isCommonAzimuthalAngle() const
{
    const auto ref = m_beams.front()->phi_i();
    for (const auto& b : m_beams)
        if (!Numeric::almostEqual(b->phi_i(), ref, 1))
            return false;
    return true;
}