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//----------------------------------------------------------------------
18#include "MantidAPI/Jacobian.h"
21#include "MantidAPI/TextAxis.h"
29
30#include <sstream>
31
32namespace Mantid::API {
33using namespace Geometry;
34
35void IFunction1D::function(const FunctionDomain &domain, FunctionValues &values) const {
36 auto histoDomain = dynamic_cast<const FunctionDomain1DHistogram *>(&domain);
37 if (histoDomain) {
38 histogram1D(values.getPointerToCalculated(0), histoDomain->leftBoundary(), histoDomain->getPointerAt(0),
39 histoDomain->size());
40 return;
41 }
42 const auto *d1d = dynamic_cast<const FunctionDomain1D *>(&domain);
43 if (!d1d) {
44 throw std::invalid_argument("Unexpected domain in IFunction1D");
45 }
46 function1D(values.getPointerToCalculated(0), d1d->getPointerAt(0), d1d->size());
47}
48
49void IFunction1D::functionDeriv(const FunctionDomain &domain, Jacobian &jacobian) {
50 auto histoDomain = dynamic_cast<const FunctionDomain1DHistogram *>(&domain);
51 if (histoDomain) {
52 histogramDerivative1D(&jacobian, histoDomain->leftBoundary(), histoDomain->getPointerAt(0), histoDomain->size());
53 return;
54 }
55 const auto *d1d = dynamic_cast<const FunctionDomain1D *>(&domain);
56 if (!d1d) {
57 throw std::invalid_argument("Unexpected domain in IFunction1D");
58 }
59 functionDeriv1D(&jacobian, d1d->getPointerAt(0), d1d->size());
60}
61
62void IFunction1D::derivative(const FunctionDomain &domain, FunctionValues &values, const size_t order) const {
63 const auto *d1d = dynamic_cast<const FunctionDomain1D *>(&domain);
64 if (!d1d) {
65 throw std::invalid_argument("Unexpected domain in IFunction1D");
66 }
67
68 derivative1D(values.getPointerToCalculated(0), d1d->getPointerAt(0), d1d->size(), order);
69}
70
71void IFunction1D::derivative1D(double *out, const double *xValues, size_t nData, const size_t order) const {
72 UNUSED_ARG(out);
73 UNUSED_ARG(xValues);
74 UNUSED_ARG(nData);
75 UNUSED_ARG(order);
76 throw Kernel::Exception::NotImplementedError("Derivative is not implemented for this function.");
77}
78
79void IFunction1D::functionDeriv1D(Jacobian *jacobian, const double *xValues, const size_t nData) {
80 auto evalMethod = [this](double *out, const double *xValues, const size_t nData) {
81 this->function1D(out, xValues, nData);
82 };
83 this->calcNumericalDerivative1D(jacobian, std::move(evalMethod), xValues, nData);
84}
85
93void IFunction1D::histogram1D(double *out, double left, const double *right, const size_t nBins) const {
94 UNUSED_ARG(out);
97 UNUSED_ARG(nBins);
98 throw Kernel::Exception::NotImplementedError("Integration is not implemented for this function.");
99}
100
107void IFunction1D::histogramDerivative1D(Jacobian *jacobian, double left, const double *right,
108 const size_t nBins) const {
109 UNUSED_ARG(jacobian);
112 UNUSED_ARG(nBins);
113 throw Kernel::Exception::NotImplementedError("Integration is not implemented for this function.");
114}
115
116} // namespace Mantid::API
double left
double right
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:44
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.
virtual void derivative(const FunctionDomain &domain, FunctionValues &values, const size_t order=1) const
void functionDeriv(const FunctionDomain &domain, Jacobian &jacobian) override
Derivatives of function with respect to active parameters.
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.
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.
void function(const FunctionDomain &domain, FunctionValues &values) const override
Evaluates the function for all arguments in the domain.
virtual void function1D(double *out, const double *xValues, const size_t nData) const =0
Function you want to fit to.
Represents the Jacobian in IFitFunction::functionDeriv.
Definition Jacobian.h:22
Marks code as not implemented yet.
Definition Exception.h:138