Mantid
Loading...
Searching...
No Matches
Convolution.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
13#include "MantidCurveFitting/DllConfig.h"
14#include <cmath>
15#include <memory>
16#include <vector>
17
18namespace Mantid {
19namespace CurveFitting {
20namespace Functions {
28class MANTID_CURVEFITTING_DLL Convolution : public API::CompositeFunction {
29public:
40 size_t m_size;
41 double *m_data;
42 bool m_even;
43 public:
49 HalfComplex(double *data, const size_t &n) : m_size(n / 2 + 1), m_data(data), m_even(n / 2 * 2 == n) {}
51 size_t size() const { return m_size; }
57 double real(size_t i) const {
58 if (i >= m_size)
59 return 0.;
60 if (i == 0)
61 return m_data[0];
62 return m_data[2 * i - 1];
63 }
69 double imag(size_t i) const {
70 if (i >= m_size)
71 return 0.;
72 if (i == 0)
73 return 0;
74 if (m_even && i == m_size - 1)
75 return 0;
76 return m_data[2 * i];
77 }
84 void set(size_t i, const double &re, const double &im) {
85 if (i >= m_size)
86 return;
87 if (i == 0) // this is purely real
88 {
89 m_data[0] = re;
90 } else if (m_even && i == m_size - 1) // this is also purely real
91 {
92 m_data[2 * i - 1] = re;
93 } else {
94 m_data[2 * i - 1] = re;
95 m_data[2 * i] = im;
96 }
97 }
98 };
99
101 Convolution();
102
104 std::string name() const override { return "Convolution"; }
105 const std::string category() const override { return "General"; }
109 void function(const API::FunctionDomain &domain, API::FunctionValues &values) const override;
110 void functionFFTMode(const API::FunctionDomain &domain, API::FunctionValues &values) const;
111 void functionDirectMode(const API::FunctionDomain &domain, API::FunctionValues &values) const;
113 void functionDeriv(const API::FunctionDomain &domain, API::Jacobian &jacobian) override;
114
116 void setAttribute(const std::string &attName, const Attribute &) override;
117
119 size_t addFunction(API::IFunction_sptr f) override;
121 void setUpForFit() override;
122
125 void refreshResolution() const;
126
127protected:
129 void init() override;
130
131private:
135 mutable std::vector<double> m_resolution;
136 void innerFunctionsAre1D() const;
137};
138
139} // namespace Functions
140} // namespace CurveFitting
141} // namespace Mantid
size_t m_size
Maximum size of the store.
const std::vector< Type > & m_data
Definition: TableColumn.h:417
A composite function is a function containing other functions.
Base class that represents the domain of a function.
A class to store values calculated by a function.
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
Class for helping to read the transformed data.
Definition: Convolution.h:39
size_t size() const
Returns the size of the transform.
Definition: Convolution.h:51
double real(size_t i) const
The real part of i-th transform coefficient.
Definition: Convolution.h:57
void set(size_t i, const double &re, const double &im)
Set a new value for i-th complex coefficient.
Definition: Convolution.h:84
HalfComplex(double *data, const size_t &n)
Constructor.
Definition: Convolution.h:49
bool m_even
true if the size of the original data is even
Definition: Convolution.h:42
double imag(size_t i) const
The imaginary part of i-th transform coefficient.
Definition: Convolution.h:69
double * m_data
pointer to the transformed data
Definition: Convolution.h:41
Performes convolution of two functions.
Definition: Convolution.h:28
const std::string category() const override
The categories the Fit function belong to.
Definition: Convolution.h:105
std::vector< double > m_resolution
Keep the Fourier transform of the resolution function (divided by the step in xValues) when in FFT mo...
Definition: Convolution.h:135
std::string name() const override
overwrite IFunction base class methods
Definition: Convolution.h:104
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
Helper class which provides the Collimation Length for SANS instruments.