Mantid
Loading...
Searching...
No Matches
CrystalFieldFunction.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
13
14#include <unordered_map>
15
16namespace Mantid {
17namespace CurveFitting {
18namespace Functions {
22class MANTID_CURVEFITTING_DLL CrystalFieldFunction : public API::IFunction {
23public:
25 std::string name() const override { return "CrystalFieldFunction"; }
26 const std::string category() const override { return "General"; }
27 size_t getNumberDomains() const override;
28 std::vector<API::IFunction_sptr> createEquivalentFunctions() const override;
30 void function(const API::FunctionDomain &domain, API::FunctionValues &values) const override;
31
32 //@ Parameters
34
35 void setParameter(size_t, const double &value, bool explicitlySet = true) override;
37 void setParameterDescription(size_t, const std::string &description) override;
39 double getParameter(size_t i) const override;
41 void setParameter(const std::string &name, const double &value, bool explicitlySet = true) override;
43 void setParameterDescription(const std::string &name, const std::string &description) override;
45 double getParameter(const std::string &name) const override;
47 bool hasParameter(const std::string &name) const override;
49 size_t nParams() const override;
51 size_t parameterIndex(const std::string &name) const override;
53 std::string parameterName(size_t i) const override;
55 std::string parameterDescription(size_t i) const override;
57 bool isExplicitlySet(size_t i) const override;
59 double getError(size_t i) const override;
61 double getError(const std::string &name) const override;
63 void setError(size_t i, double err) override;
65 void setError(const std::string &name, double err) override;
66
68 size_t getParameterIndex(const API::ParameterReference &ref) const override;
70 void setUpForFit() override;
72 API::ParameterTie *getTie(size_t i) const override;
74 bool ignoreTie(const API::ParameterTie &tie) const override;
76 API::IConstraint *getConstraint(size_t i) const override;
78
82 size_t nAttributes() const override;
84 std::vector<std::string> getAttributeNames() const override;
86 Attribute getAttribute(const std::string &name) const override;
88 void setAttribute(const std::string &name, const Attribute &) override;
90 bool hasAttribute(const std::string &name) const override;
92
94
95
97 bool isMultiSite() const;
100 bool isMultiSpectrum() const;
102 bool hasBackground() const;
104 bool hasPeaks() const;
106 bool hasPhysProperties() const;
108
110 void checkSourceFunction() const;
112 void buildTargetFunction() const;
114 size_t nSpectra() const;
115
116protected:
118 void declareParameter(const std::string &name, double initValue = 0, const std::string &description = "") override;
120 void setParameterStatus(size_t i, ParameterStatus status) override;
122 ParameterStatus getParameterStatus(size_t i) const override;
123
125 void buildSourceFunction() const;
127 void updateTargetFunction() const;
128
129private:
131 void buildSingleSite() const;
133 void buildMultiSite() const;
135 void buildSingleSiteSingleSpectrum() const;
137 void buildSingleSiteMultiSpectrum() const;
139 void buildMultiSiteSingleSpectrum() const;
141 void buildMultiSiteMultiSpectrum() const;
142
144 void updateSingleSite() const;
146 void updateMultiSite() const;
148 void updateSingleSiteSingleSpectrum() const;
150 void updateSingleSiteMultiSpectrum() const;
152 void updateMultiSiteSingleSpectrum() const;
154 void updateMultiSiteMultiSpectrum() const;
155
157 API::IFunction_sptr buildSpectrum(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf,
158 double temperature, double fwhm, size_t i, bool addBackground,
159 double intensityScaling) const;
161 void updateSpectrum(API::IFunction &spectrum, int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf,
162 double temperature, double fwhm, size_t iSpec, size_t iFirst, double intensityScaling) const;
164 void calcExcitations(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, double temperature,
165 API::FunctionValues &values, double intensityScaling) const;
167 API::IFunction_sptr buildPhysprop(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf,
168 const ComplexFortranMatrix &ham, const std::string &propName) const;
170 void updatePhysprop(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf,
171 const ComplexFortranMatrix &ham, API::IFunction &fun) const;
172
174 void setSource(API::IFunction_sptr source) const;
176 void checkTargetFunction() const;
178 API::CompositeFunction &compositeSource() const;
179
181 std::pair<API::IFunction *, std::string> getAttributeReference(const std::string &attName) const;
183 void buildAttributeNames() const;
184
186 void makeMaps() const;
187 void makeMapsSingleSiteSingleSpectrum() const;
188 void makeMapsSingleSiteMultiSpectrum() const;
189 void makeMapsMultiSiteSingleSpectrum() const;
190 void makeMapsMultiSiteMultiSpectrum() const;
191 size_t makeMapsForFunction(const IFunction &fun, size_t iFirst, const std::string &prefix) const;
192 void cacheSourceParameters() const;
200 mutable size_t m_nControlParams;
204 mutable bool m_dirtyTarget;
206 mutable std::unordered_map<std::string, size_t> m_mapNames2Indices;
208 mutable std::vector<std::string> m_mapIndices2Names;
210 mutable std::vector<std::string> m_attributeNames;
212 mutable std::unordered_map<std::string, API::IFunction_sptr> m_mapPrefixes2PhysProps;
214 mutable std::vector<double> m_parameterResetCache;
215 mutable std::vector<bool> m_fixResetCache;
216};
217
218} // namespace Functions
219} // namespace CurveFitting
220} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
int nSpectra
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.
An interface to a constraint.
Definition: IConstraint.h:26
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
This is an interface to a fitting function - a semi-abstarct class.
Definition: IFunction.h:163
A reference to a parameter in a function.
Ties fitting parameters.
Definition: ParameterTie.h:35
A function that controls creation of the source of CrystalFieldFunction.
std::unordered_map< std::string, size_t > m_mapNames2Indices
Map parameter names to indices.
API::IFunction_sptr m_source
Function that calculates parameters of the target function.
bool m_dirtyTarget
Flag indicating that updateTargetFunction() is required.
std::vector< std::string > m_attributeNames
Attribute names.
std::vector< std::string > m_mapIndices2Names
Map parameter indices to names.
std::vector< double > m_parameterResetCache
Temporary cache for parameter values during source function resetting.
std::unordered_map< std::string, API::IFunction_sptr > m_mapPrefixes2PhysProps
Map parameter/attribute prefixes to pointers to phys prop functions.
const std::string category() const override
The categories the Fit function belong to.
size_t m_nControlParams
Cached number of parameters in m_control.
CrystalFieldControl m_control
Function that creates the source function.
size_t m_nControlSourceParams
Cached number of parameters in m_control and m_source.
API::CompositeFunction_sptr m_target
Function that actually calculates the output.
std::string name() const override
Returns the function's name.
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
std::shared_ptr< CompositeFunction > CompositeFunction_sptr
shared pointer to the composite function base class
Helper class which provides the Collimation Length for SANS instruments.