Coverage Report

Created: 2024-12-20 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/builds/MusicScience37Projects/numerical-analysis/numerical-collection-cpp/include/num_collect/integration/gauss_legendre_integrator.h
Line
Count
Source
1
/*
2
 * Copyright 2021 MusicScience37 (Kenta Kabashima)
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
/*!
17
 * \file
18
 * \brief Definition of legendre_roots function.
19
 */
20
#pragma once
21
22
// IWYU pragma: no_include <complex>
23
24
#include <type_traits>
25
26
#include <Eigen/Core>
27
28
#include "num_collect/base/concepts/invocable_as.h"
29
#include "num_collect/base/concepts/real_scalar.h"
30
#include "num_collect/base/exception.h"
31
#include "num_collect/base/index_type.h"
32
#include "num_collect/constants/half.h"  // IWYU pragma: keep
33
#include "num_collect/constants/one.h"   // IWYU pragma: keep
34
#include "num_collect/constants/two.h"   // IWYU pragma: keep
35
#include "num_collect/functions/legendre.h"
36
#include "num_collect/functions/legendre_roots.h"
37
#include "num_collect/logging/logging_macros.h"
38
39
namespace num_collect::integration {
40
41
/*!
42
 * \brief Class to perform numerical integration with Gauss-Legendre formula.
43
 *
44
 * \tparam Signature Function signature.
45
 */
46
template <typename Signature>
47
class gauss_legendre_integrator;
48
49
/*!
50
 * \brief Class to perform numerical integration with Gauss-Legendre formula.
51
 *
52
 * \tparam Result Type of results.
53
 * \tparam Variable Type of variables.
54
 */
55
template <typename Result, base::concepts::real_scalar Variable>
56
class gauss_legendre_integrator<Result(Variable)> {
57
public:
58
    //! Type of variables.
59
    using variable_type = std::decay_t<Variable>;
60
61
    //! Type of results.
62
    using result_type = std::decay_t<Result>;
63
64
    //! Default degree.
65
    static constexpr index_type default_degree = 20;
66
67
    /*!
68
     * \brief Constructor.
69
     *
70
     * \param[in] degree Degree.
71
     */
72
    explicit gauss_legendre_integrator(index_type degree = default_degree)
73
22
        : roots_(degree) {
74
22
        if (degree < 1) {
75
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
76
0
                "Degree of Legendre function must be at least one.");
77
0
        }
78
22
        update_weight();
79
22
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFN5Eigen6MatrixIdLi2ELi1ELi0ELi2ELi1EEEdEEC2El
Line
Count
Source
73
12
        : roots_(degree) {
74
12
        if (degree < 1) {
75
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
76
0
                "Degree of Legendre function must be at least one.");
77
0
        }
78
12
        update_weight();
79
12
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFffEEC2El
Line
Count
Source
73
4
        : roots_(degree) {
74
4
        if (degree < 1) {
75
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
76
0
                "Degree of Legendre function must be at least one.");
77
0
        }
78
4
        update_weight();
79
4
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFNSt3__17complexIfEEfEEC2El
Line
Count
Source
73
1
        : roots_(degree) {
74
1
        if (degree < 1) {
75
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
76
0
                "Degree of Legendre function must be at least one.");
77
0
        }
78
1
        update_weight();
79
1
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFddEEC2El
Line
Count
Source
73
4
        : roots_(degree) {
74
4
        if (degree < 1) {
75
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
76
0
                "Degree of Legendre function must be at least one.");
77
0
        }
78
4
        update_weight();
79
4
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFNSt3__17complexIdEEdEEC2El
Line
Count
Source
73
1
        : roots_(degree) {
74
1
        if (degree < 1) {
75
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
76
0
                "Degree of Legendre function must be at least one.");
77
0
        }
78
1
        update_weight();
79
1
    }
80
81
    /*!
82
     * \brief Compute internal variables for integration.
83
     *
84
     * \param[in] degree Degree.
85
     */
86
2
    void prepare(index_type degree) {
87
2
        if (degree < 1) {
88
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
89
0
                "Degree of Legendre function must be at least one.");
90
0
        }
91
2
        roots_.compute(degree);
92
2
        update_weight();
93
2
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFffEE7prepareEl
Line
Count
Source
86
1
    void prepare(index_type degree) {
87
1
        if (degree < 1) {
88
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
89
0
                "Degree of Legendre function must be at least one.");
90
0
        }
91
1
        roots_.compute(degree);
92
1
        update_weight();
93
1
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFddEE7prepareEl
Line
Count
Source
86
1
    void prepare(index_type degree) {
87
1
        if (degree < 1) {
88
0
            NUM_COLLECT_LOG_AND_THROW(invalid_argument,
89
0
                "Degree of Legendre function must be at least one.");
90
0
        }
91
1
        roots_.compute(degree);
92
1
        update_weight();
93
1
    }
94
95
    /*!
96
     * \brief Integrate a function.
97
     *
98
     * \tparam Function Type of function.
99
     * \param[in] function Function.
100
     * \param[in] left Left boundary.
101
     * \param[in] right Right boundary.
102
     * \return Result.
103
     */
104
    template <base::concepts::invocable_as<result_type(variable_type)> Function>
105
    [[nodiscard]] auto integrate(const Function& function, variable_type left,
106
4.16k
        variable_type right) const -> result_type {
107
4.16k
        const auto degree = roots_.degree();
108
4.16k
        const auto mean = constants::half<variable_type> * (left + right);
109
4.16k
        const auto half_width = constants::half<variable_type> * (right - left);
110
4.16k
        Result sum = function(mean) * constants::zero<variable_type>;
111
25.2k
        for (index_type i = 0; i < degree; ++i) {
112
21.0k
            const variable_type x = mean + half_width * roots_[i];
113
21.0k
            const variable_type weight = weights_[i];
114
21.0k
            sum += weight * function(x);
115
21.0k
        }
116
4.16k
        return sum * half_width;
117
4.16k
    }
_ZNK11num_collect11integration25gauss_legendre_integratorIFN5Eigen6MatrixIdLi2ELi1ELi0ELi2ELi1EEEdEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEENS_3ode3avf4impl13avf_integrandIN16num_prob_collect3ode23spring_movement_problemEEEEES4_RKSB_dd
Line
Count
Source
106
4.15k
        variable_type right) const -> result_type {
107
4.15k
        const auto degree = roots_.degree();
108
4.15k
        const auto mean = constants::half<variable_type> * (left + right);
109
4.15k
        const auto half_width = constants::half<variable_type> * (right - left);
110
4.15k
        Result sum = function(mean) * constants::zero<variable_type>;
111
24.9k
        for (index_type i = 0; i < degree; ++i) {
112
20.7k
            const variable_type x = mean + half_width * roots_[i];
113
20.7k
            const variable_type weight = weights_[i];
114
20.7k
            sum += weight * function(x);
115
20.7k
        }
116
4.15k
        return sum * half_width;
117
4.15k
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFffEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE_EEfRKS8_ff
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
21
        for (index_type i = 0; i < degree; ++i) {
112
20
            const variable_type x = mean + half_width * roots_[i];
113
20
            const variable_type weight = weights_[i];
114
20
            sum += weight * function(x);
115
20
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFffEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE0_EEfRKS8_ff
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
21
        for (index_type i = 0; i < degree; ++i) {
112
20
            const variable_type x = mean + half_width * roots_[i];
113
20
            const variable_type weight = weights_[i];
114
20
            sum += weight * function(x);
115
20
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFffEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE1_EEfRKS8_ff
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
51
        for (index_type i = 0; i < degree; ++i) {
112
50
            const variable_type x = mean + half_width * roots_[i];
113
50
            const variable_type weight = weights_[i];
114
50
            sum += weight * function(x);
115
50
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFffEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE2_EEfRKS8_ff
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
51
        for (index_type i = 0; i < degree; ++i) {
112
50
            const variable_type x = mean + half_width * roots_[i];
113
50
            const variable_type weight = weights_[i];
114
50
            sum += weight * function(x);
115
50
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFNSt3__17complexIfEEfEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE3_EES4_RKSB_ff
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
21
        for (index_type i = 0; i < degree; ++i) {
112
20
            const variable_type x = mean + half_width * roots_[i];
113
20
            const variable_type weight = weights_[i];
114
20
            sum += weight * function(x);
115
20
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFddEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE_EEdRKS8_dd
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
21
        for (index_type i = 0; i < degree; ++i) {
112
20
            const variable_type x = mean + half_width * roots_[i];
113
20
            const variable_type weight = weights_[i];
114
20
            sum += weight * function(x);
115
20
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFddEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE0_EEdRKS8_dd
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
21
        for (index_type i = 0; i < degree; ++i) {
112
20
            const variable_type x = mean + half_width * roots_[i];
113
20
            const variable_type weight = weights_[i];
114
20
            sum += weight * function(x);
115
20
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFddEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE1_EEdRKS8_dd
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
51
        for (index_type i = 0; i < degree; ++i) {
112
50
            const variable_type x = mean + half_width * roots_[i];
113
50
            const variable_type weight = weights_[i];
114
50
            sum += weight * function(x);
115
50
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFddEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE2_EEdRKS8_dd
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
51
        for (index_type i = 0; i < degree; ++i) {
112
50
            const variable_type x = mean + half_width * roots_[i];
113
50
            const variable_type weight = weights_[i];
114
50
            sum += weight * function(x);
115
50
        }
116
1
        return sum * half_width;
117
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFNSt3__17complexIdEEdEE9integrateITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE3_EES4_RKSB_dd
Line
Count
Source
106
1
        variable_type right) const -> result_type {
107
1
        const auto degree = roots_.degree();
108
1
        const auto mean = constants::half<variable_type> * (left + right);
109
1
        const auto half_width = constants::half<variable_type> * (right - left);
110
1
        Result sum = function(mean) * constants::zero<variable_type>;
111
21
        for (index_type i = 0; i < degree; ++i) {
112
20
            const variable_type x = mean + half_width * roots_[i];
113
20
            const variable_type weight = weights_[i];
114
20
            sum += weight * function(x);
115
20
        }
116
1
        return sum * half_width;
117
1
    }
118
119
    /*!
120
     * \brief Integrate a function.
121
     *
122
     * \tparam Function Type of function.
123
     * \param[in] function Function.
124
     * \param[in] left Left boundary.
125
     * \param[in] right Right boundary.
126
     * \return Result.
127
     */
128
    template <base::concepts::invocable_as<result_type(variable_type)> Function>
129
    [[nodiscard]] auto operator()(const Function& function, variable_type left,
130
4.16k
        variable_type right) const -> result_type {
131
4.16k
        return integrate(function, left, right);
132
4.16k
    }
_ZNK11num_collect11integration25gauss_legendre_integratorIFN5Eigen6MatrixIdLi2ELi1ELi0ELi2ELi1EEEdEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEENS_3ode3avf4impl13avf_integrandIN16num_prob_collect3ode23spring_movement_problemEEEEES4_RKSB_dd
Line
Count
Source
130
4.15k
        variable_type right) const -> result_type {
131
4.15k
        return integrate(function, left, right);
132
4.15k
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFffEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE_EEfRKS8_ff
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFffEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE0_EEfRKS8_ff
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFffEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE1_EEfRKS8_ff
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFffEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE2_EEfRKS8_ff
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFNSt3__17complexIfEEfEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IfEvvEUlfE3_EES4_RKSB_ff
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFddEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE_EEdRKS8_dd
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFddEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE0_EEdRKS8_dd
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFddEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE1_EEdRKS8_dd
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFddEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE2_EEdRKS8_dd
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
gauss_legendre_integrator_test.cpp:_ZNK11num_collect11integration25gauss_legendre_integratorIFNSt3__17complexIdEEdEEclITkNS_4base8concepts12invocable_asIFu7__decayIT_Eu7__decayIT0_EEEEZL31CATCH2_INTERNAL_TEMPLATE_TEST_0IdEvvEUldE3_EES4_RKSB_dd
Line
Count
Source
130
1
        variable_type right) const -> result_type {
131
1
        return integrate(function, left, right);
132
1
    }
133
134
private:
135
    /*!
136
     * \brief Update weight for roots.
137
     */
138
24
    void update_weight() {
139
24
        const auto degree = roots_.degree();
140
24
        weights_.resize(degree);
141
444
        for (index_type i = 0; i < degree; ++i) {
142
420
            const variable_type x = roots_[i];
143
420
            const auto temp = static_cast<variable_type>(degree) *
144
420
                functions::legendre(x, degree - 1);
145
420
            weights_[i] = constants::two<variable_type> *
146
420
                (constants::one<variable_type> - x * x) / (temp * temp);
147
420
        }
148
24
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFN5Eigen6MatrixIdLi2ELi1ELi0ELi2ELi1EEEdEE13update_weightEv
Line
Count
Source
138
12
    void update_weight() {
139
12
        const auto degree = roots_.degree();
140
12
        weights_.resize(degree);
141
72
        for (index_type i = 0; i < degree; ++i) {
142
60
            const variable_type x = roots_[i];
143
60
            const auto temp = static_cast<variable_type>(degree) *
144
60
                functions::legendre(x, degree - 1);
145
60
            weights_[i] = constants::two<variable_type> *
146
60
                (constants::one<variable_type> - x * x) / (temp * temp);
147
60
        }
148
12
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFffEE13update_weightEv
Line
Count
Source
138
5
    void update_weight() {
139
5
        const auto degree = roots_.degree();
140
5
        weights_.resize(degree);
141
165
        for (index_type i = 0; i < degree; ++i) {
142
160
            const variable_type x = roots_[i];
143
160
            const auto temp = static_cast<variable_type>(degree) *
144
160
                functions::legendre(x, degree - 1);
145
160
            weights_[i] = constants::two<variable_type> *
146
160
                (constants::one<variable_type> - x * x) / (temp * temp);
147
160
        }
148
5
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFNSt3__17complexIfEEfEE13update_weightEv
Line
Count
Source
138
1
    void update_weight() {
139
1
        const auto degree = roots_.degree();
140
1
        weights_.resize(degree);
141
21
        for (index_type i = 0; i < degree; ++i) {
142
20
            const variable_type x = roots_[i];
143
20
            const auto temp = static_cast<variable_type>(degree) *
144
20
                functions::legendre(x, degree - 1);
145
20
            weights_[i] = constants::two<variable_type> *
146
20
                (constants::one<variable_type> - x * x) / (temp * temp);
147
20
        }
148
1
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFddEE13update_weightEv
Line
Count
Source
138
5
    void update_weight() {
139
5
        const auto degree = roots_.degree();
140
5
        weights_.resize(degree);
141
165
        for (index_type i = 0; i < degree; ++i) {
142
160
            const variable_type x = roots_[i];
143
160
            const auto temp = static_cast<variable_type>(degree) *
144
160
                functions::legendre(x, degree - 1);
145
160
            weights_[i] = constants::two<variable_type> *
146
160
                (constants::one<variable_type> - x * x) / (temp * temp);
147
160
        }
148
5
    }
_ZN11num_collect11integration25gauss_legendre_integratorIFNSt3__17complexIdEEdEE13update_weightEv
Line
Count
Source
138
1
    void update_weight() {
139
1
        const auto degree = roots_.degree();
140
1
        weights_.resize(degree);
141
21
        for (index_type i = 0; i < degree; ++i) {
142
20
            const variable_type x = roots_[i];
143
20
            const auto temp = static_cast<variable_type>(degree) *
144
20
                functions::legendre(x, degree - 1);
145
20
            weights_[i] = constants::two<variable_type> *
146
20
                (constants::one<variable_type> - x * x) / (temp * temp);
147
20
        }
148
1
    }
149
150
    //! Roots of Legendre function.
151
    functions::legendre_roots<variable_type> roots_;
152
153
    //! List of weights for roots.
154
    Eigen::Matrix<variable_type, Eigen::Dynamic, 1> weights_{};
155
};
156
157
}  // namespace num_collect::integration