Mantid
Loading...
Searching...
No Matches
IFunction1D.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
16#include "MantidAPI/IFunction1D.tcc"
18#include "MantidAPI/Jacobian.h"
21#include "MantidAPI/TextAxis.h"
29
30#include <sstream>
31
32namespace Mantid::API {
33using namespace Geometry;
34
36Kernel::Logger IFunction1D::g_log("IFunction1D");
37
38void IFunction1D::function(const FunctionDomain &domain, FunctionValues &values) const {
39 auto histoDomain = dynamic_cast<const FunctionDomain1DHistogram *>(&domain);
40 if (histoDomain) {
41 histogram1D(values.getPointerToCalculated(0), histoDomain->leftBoundary(), histoDomain->getPointerAt(0),
42 histoDomain->size());
43 return;
44 }
45 const auto *d1d = dynamic_cast<const FunctionDomain1D *>(&domain);
46 if (!d1d) {
47 throw std::invalid_argument("Unexpected domain in IFunction1D");
48 }
49 function1D(values.getPointerToCalculated(0), d1d->getPointerAt(0), d1d->size());
50}
51
52void IFunction1D::functionDeriv(const FunctionDomain &domain, Jacobian &jacobian) {
53 auto histoDomain = dynamic_cast<const FunctionDomain1DHistogram *>(&domain);
54 if (histoDomain) {
55 histogramDerivative1D(&jacobian, histoDomain->leftBoundary(), histoDomain->getPointerAt(0), histoDomain->size());
56 return;
57 }
58 const auto *d1d = dynamic_cast<const FunctionDomain1D *>(&domain);
59 if (!d1d) {
60 throw std::invalid_argument("Unexpected domain in IFunction1D");
61 }
62 functionDeriv1D(&jacobian, d1d->getPointerAt(0), d1d->size());
63}
64
65void IFunction1D::derivative(const FunctionDomain &domain, FunctionValues &values, const size_t order) const {
66 const auto *d1d = dynamic_cast<const FunctionDomain1D *>(&domain);
67 if (!d1d) {
68 throw std::invalid_argument("Unexpected domain in IFunction1D");
69 }
70
71 derivative1D(values.getPointerToCalculated(0), d1d->getPointerAt(0), d1d->size(), order);
72}
73
74void IFunction1D::derivative1D(double *out, const double *xValues, size_t nData, const size_t order) const {
75 UNUSED_ARG(out);
76 UNUSED_ARG(xValues);
77 UNUSED_ARG(nData);
78 UNUSED_ARG(order);
79 throw Kernel::Exception::NotImplementedError("Derivative is not implemented for this function.");
80}
81
82void IFunction1D::functionDeriv1D(Jacobian *jacobian, const double *xValues, const size_t nData) {
83 auto evalMethod = [this](double *out, const double *xValues, const size_t nData) {
84 this->function1D(out, xValues, nData);
85 };
86 this->calcNumericalDerivative1D(jacobian, std::move(evalMethod), xValues, nData);
87}
88
96void IFunction1D::histogram1D(double *out, double left, const double *right, const size_t nBins) const {
97 UNUSED_ARG(out);
100 UNUSED_ARG(nBins);
101 throw Kernel::Exception::NotImplementedError("Integration is not implemented for this function.");
102}
103
110void IFunction1D::histogramDerivative1D(Jacobian *jacobian, double left, const double *right,
111 const size_t nBins) const {
112 UNUSED_ARG(jacobian);
115 UNUSED_ARG(nBins);
116 throw Kernel::Exception::NotImplementedError("Integration is not implemented for this function.");
117}
118
119} // namespace Mantid::API
double left
Definition: LineProfile.cpp:80
double right
Definition: LineProfile.cpp:81
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
Implements FunctionDomain1D as a set of bins for a histogram.
Represent a domain for functions of one real argument.
Base class that represents the domain of a function.
A class to store values calculated by a function.
double * getPointerToCalculated(size_t i)
Get a pointer to calculated data at index i.
virtual void histogram1D(double *out, double left, const double *right, const size_t nBins) const
Calculate histogram data for the given bin boundaries.
Definition: IFunction1D.cpp:96
virtual void derivative(const FunctionDomain &domain, FunctionValues &values, const size_t order=1) const
Definition: IFunction1D.cpp:65
void functionDeriv(const FunctionDomain &domain, Jacobian &jacobian) override
Derivatives of function with respect to active parameters.
Definition: IFunction1D.cpp:52
virtual void derivative1D(double *out, const double *xValues, const size_t nData, const size_t order) const
Function to calculate the derivatives of the data set.
Definition: IFunction1D.cpp:74
virtual void histogramDerivative1D(Jacobian *jacobian, double left, const double *right, const size_t nBins) const
Derivatives of the histogram1D with respect to active parameters.
void calcNumericalDerivative1D(Jacobian *jacobian, EvaluationMethod func1D, const double *xValues, const size_t nData)
Calculate a numerical derivative for the 1D data.
virtual void functionDeriv1D(Jacobian *jacobian, const double *xValues, const size_t nData)
Derivatives of function with respect to active parameters.
Definition: IFunction1D.cpp:82
void function(const FunctionDomain &domain, FunctionValues &values) const override
Evaluates the function for all arguments in the domain.
Definition: IFunction1D.cpp:38
virtual void function1D(double *out, const double *xValues, const size_t nData) const =0
Function you want to fit to.
static Kernel::Logger g_log
Logger instance.
Definition: IFunction1D.h:74
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
Marks code as not implemented yet.
Definition: Exception.h:138