25#include <boost/regex.hpp>
33using namespace CurveFitting;
34using namespace Kernel;
41const std::string ION_PREFIX(
"ion");
42const std::string SPECTRUM_PREFIX(
"sp");
43const std::string BACKGROUND_PREFIX(
"bg");
44const std::string PEAK_PREFIX(
"pk");
48const boost::regex SPECTRUM_ATTR_REGEX(SPECTRUM_PREFIX +
"([0-9]+)\\.(.+)");
51const boost::regex BACKGROUND_ATTR_REGEX(BACKGROUND_PREFIX +
"\\.(.+)");
54const boost::regex PEAK_ATTR_REGEX(PEAK_PREFIX +
"([0-9]+)\\.(.+)");
57const boost::regex ION_ATTR_REGEX(ION_PREFIX +
"([0-9]+)\\.(.+)");
60const boost::regex PHYS_PROP_ATTR_REGEX(
"((ion[0-9]+\\.)?(cv|chi|mh|mt))\\.(.+)");
64class Peaks :
public CrystalFieldPeaksBase,
public API::IFunctionGeneral {
66 Peaks() : CrystalFieldPeaksBase() {}
67 std::string
name()
const override {
return "Peaks"; }
68 size_t getNumberDomainColumns()
const override {
69 throw Exception::NotImplementedError(
"This method is intentionally not implemented.");
71 size_t getNumberValuesPerArgument()
const override {
72 throw Exception::NotImplementedError(
"This method is intentionally not implemented.");
74 void functionGeneral(
const API::FunctionDomainGeneral & , API::FunctionValues & )
const override {
75 throw Exception::NotImplementedError(
"This method is intentionally not implemented.");
81 void declareIntensityScaling(
size_t nSpec) {
85 for (
size_t i = 0; i < nSpec; ++i) {
88 declareParameter(
"IntensityScaling" + si, 1.0,
"Intensity scaling factor for spectrum " + si);
89 }
catch (std::invalid_argument &) {
100 :
IFunction(), m_nControlParams(0), m_nControlSourceParams(0), m_dirtyTarget(true) {}
106 throw std::logic_error(
"FunctionGenerator failed to generate target function.");
121 throw std::logic_error(
"Failed to build target function.");
122 return m_target->getNumberDomains();
127 std::vector<IFunction_sptr> funs;
129 for (
size_t i = 0; i < composite.nFunctions(); ++i) {
135 funs.emplace_back(fun);
186 }
catch (std::invalid_argument &) {
196 }
catch (std::invalid_argument &) {
199 if (!boost::regex_search(
name, match, PEAK_ATTR_REGEX)) {
241 throw std::invalid_argument(
"CrystalFieldFunction parameter not found: " +
name);
243 return found->second;
249 throw std::invalid_argument(
"CrystalFieldFunction's parameter index " +
std::to_string(i) +
" is out of range " +
378 if (index < m_source->
nParams()) {
393 const std::string & ) {
405 for (
size_t i = 0; i < numAttributes; ++i) {
412 auto moveAttributeName = [&](
const std::string &
name) {
413 auto iterFound = std::find(controlAttributeNames.begin(), controlAttributeNames.end(),
name);
414 if (iterFound != controlAttributeNames.end()) {
415 controlAttributeNames.erase(iterFound);
420 auto prependPrefix = [&](
const std::string &prefix,
const std::vector<std::string> &names) {
421 for (
auto name : names) {
422 if (
name.find(
"NumDeriv") != std::string::npos)
424 name.insert(
name.begin(), prefix.begin(), prefix.end());
429 moveAttributeName(
"Ions");
430 moveAttributeName(
"Symmetries");
431 moveAttributeName(
"Temperatures");
432 moveAttributeName(
"Background");
436 std::copy_if(controlAttributeNames.begin(), controlAttributeNames.end(), std::back_inserter(
m_attributeNames),
437 [](
const auto &
name) { return name.find(
".") == std::string::npos; });
440 std::string prefix(SPECTRUM_PREFIX);
443 for (
auto &attrName : attrNames) {
444 attrName.insert(attrName.begin(), prefix.begin(), prefix.end());
450 auto fun =
m_target->getFunction(iSpec).get();
452 if (compositePhysProp) {
454 std::string physPropPrefix(compositePhysProp->getFunction(0)->name());
455 physPropPrefix.append(
".");
456 for (
size_t ion = 0; ion < compositePhysProp->nFunctions(); ++ion) {
457 std::string prefix(ION_PREFIX);
458 prefix.append(
std::to_string(ion)).append(
".").append(physPropPrefix);
459 auto names = compositePhysProp->getFunction(ion)->getAttributeNames();
460 prependPrefix(prefix, names);
464 std::string prefix(fun->name());
466 auto names = fun->getAttributeNames();
467 prependPrefix(prefix, names);
488 if (attRef.first ==
nullptr) {
492 return attRef.first->getAttribute(attRef.second);
498 if (attRef.first ==
nullptr) {
505 attRef.first->setAttribute(attRef.second, attr);
506 if (attName.find(
"FWHM") != std::string::npos || attName.find(
"Background") != std::string::npos) {
514 if (attRef.first ==
nullptr) {
517 return attRef.first->hasAttribute(attRef.second);
528 if (boost::regex_match(attName, match, SPECTRUM_ATTR_REGEX)) {
529 auto index = std::stoul(match[1]);
530 auto attNameNoIndex = match[2].str();
534 if (attNameNoIndex ==
"FWHMX" || attNameNoIndex ==
"FWHMY") {
538 return std::make_pair(
nullptr,
"");
541 return std::make_pair(
nullptr,
"");
542 }
else if (boost::regex_match(attName, match, PHYS_PROP_ATTR_REGEX)) {
543 auto prop = match[1].str();
544 auto nameRemainder = match[4].str();
547 return std::make_pair(propIt->second.get(), nameRemainder);
549 return std::make_pair(
nullptr,
"");
551 return std::make_pair(&
m_control, attName);
582 tie.asString().find(
"/Sigma") != std::string::npos;
589 if (constraint ==
nullptr) {
627 if (composite ==
nullptr) {
628 throw std::logic_error(
"Source of CrystalFieldFunction is not composite.");
662 throw std::logic_error(
"CrystalFieldFunction failed to generate target function.");
701 m_target->setAttributeValue(
"NumDeriv",
true);
705 if (!bkgdShape.empty()) {
706 auto background = API::FunctionFactory::Instance().createInitialized(bkgdShape);
707 spectrum->addFunction(background);
714 if (values.
size() == 0) {
718 if (values.
size() % 2 != 0) {
719 throw std::runtime_error(
"CrystalFieldPeaks returned odd number of values.");
725 auto defaultFWHM = FWHMs.empty() ? 0.0 : FWHMs[0];
731 nRequiredPeaks, fixAllPeaks);
745 peakCalculator.
calculateEigenSystem(energies, waveFunctions, hamiltonian, hamiltonianZeeman, nre);
746 hamiltonian += hamiltonianZeeman;
751 const bool addBackground =
true;
752 for (
size_t i = 0; i < nSpec; ++i) {
754 fun->addFunction(
buildSpectrum(nre, energies, waveFunctions, temperatures[i], FWHMs.size() > i ? FWHMs[i] : 0., i,
755 addBackground, intensityScaling));
756 fun->setDomainIndex(i, i);
760 for (
const auto &prop : physProps) {
761 auto physPropFun =
buildPhysprop(nre, energies, waveFunctions, hamiltonian, prop);
762 fun->addFunction(physPropFun);
763 fun->setDomainIndex(i, i);
774 m_target->setAttributeValue(
"NumDeriv",
true);
778 if (!bkgdShape.empty()) {
779 auto background = API::FunctionFactory::Instance().createInitialized(bkgdShape);
780 spectrum->addFunction(background);
784 auto defaultFWHM = FWHMs.empty() ? 0.0 : FWHMs[0];
792 for (
size_t ionIndex = 0; ionIndex < compSource.nFunctions(); ++ionIndex) {
795 compSource.getFunction(ionIndex)->function(domain, values);
797 if (values.
size() == 0) {
801 if (values.
size() % 2 != 0) {
802 throw std::runtime_error(
"CrystalFieldPeaks returned odd number of values.");
805 auto ionSpectrum = std::make_shared<CompositeFunction>();
807 nRequiredPeaks, fixAllPeaks);
808 spectrum->addFunction(ionSpectrum);
818 std::vector<CompositeFunction *> spectra(nSpec);
819 for (
size_t i = 0; i < nSpec; ++i) {
820 auto spectrum = std::make_shared<CompositeFunction>();
821 spectra[i] = spectrum.get();
822 multiDomain->addFunction(spectrum);
823 multiDomain->setDomainIndex(i, i);
826 std::vector<CompositeFunction_sptr> compositePhysProps(physProps.size());
827 std::generate(compositePhysProps.begin(), compositePhysProps.end(),
828 []() { return std::make_shared<CompositeFunction>(); });
831 for (
size_t ionIndex = 0; ionIndex < compSource.nFunctions(); ++ionIndex) {
837 const auto &peakCalculator =
dynamic_cast<CrystalFieldPeaksBase &
>(*compSource.getFunction(ionIndex));
838 peakCalculator.
calculateEigenSystem(energies, waveFunctions, hamiltonian, hamiltonianZeeman, nre);
839 hamiltonian += hamiltonianZeeman;
843 const bool addBackground = ionIndex == 0;
844 auto ionIntensityScaling = compSource.getFunction(ionIndex)->getParameter(
"IntensityScaling");
845 for (
size_t i = 0; i < nSpec; ++i) {
847 spectra[i]->addFunction(
buildSpectrum(nre, energies, waveFunctions, temperatures[i],
848 FWHMs.size() > i ? FWHMs[i] : 0., i, addBackground,
849 ionIntensityScaling * spectrumIntensityScaling));
853 for (
const auto &prop : physProps) {
854 auto physPropFun =
buildPhysprop(nre, energies, waveFunctions, hamiltonian, prop);
855 compositePhysProps[i]->addFunction(physPropFun);
856 std::string propName =
"ion";
857 propName.append(
std::to_string(ionIndex)).append(
".").append(prop);
864 for (
const auto &propFun : compositePhysProps) {
865 multiDomain->addFunction(propFun);
866 multiDomain->setDomainIndex(i, i);
889 calculateIntensities(nre, energies, waveFunctions, temperature, toleranceEnergy, degeneration, eEnergies, iEnergies);
890 calculateExcitations(eEnergies, iEnergies, toleranceEnergy, toleranceIntensity, eExcitations, iExcitations);
891 const auto nPeaks = eExcitations.
size();
892 values.
expand(2 * nPeaks);
893 for (
size_t i = 0; i < nPeaks; ++i) {
911 double fwhm,
size_t iSpec,
bool addBackground,
912 double intensityScaling)
const {
914 calcExcitations(nre, energies, waveFunctions, temperature, values, intensityScaling);
923 if (addBackground && !bkgdShape.empty()) {
924 if (bkgdShape.find(
"name=") != 0 && bkgdShape.front() !=
'(') {
925 bkgdShape =
"name=" + bkgdShape;
927 auto background = API::FunctionFactory::Instance().createInitialized(bkgdShape);
928 spectrum->addFunction(background);
934 nRequiredPeaks, fixAllPeaks);
947 const std::string &propName)
const {
949 if (propName ==
"cv") {
950 auto propFun = std::make_shared<CrystalFieldHeatCapacityCalculation>();
951 propFun->setEnergy(energies);
954 if (propName ==
"chi") {
955 auto propFun = std::make_shared<CrystalFieldSusceptibilityCalculation>();
956 propFun->setEigensystem(energies, waveFunctions, nre);
959 if (propName ==
"mh") {
960 auto propFun = std::make_shared<CrystalFieldMagnetisationCalculation>();
961 propFun->setHamiltonian(hamiltonian, nre);
964 if (propName ==
"mt") {
965 auto propFun = std::make_shared<CrystalFieldMomentCalculation>();
966 propFun->setHamiltonian(hamiltonian, nre);
970 throw std::runtime_error(
"Physical property type not understood: " + propName);
985 if (propName ==
"cv") {
988 }
else if (propName ==
"chi") {
991 }
else if (propName ==
"mh") {
994 }
else if (propName ==
"mt") {
998 throw std::runtime_error(
"Physical property type not understood: " + propName);
1043 auto defaultFWHM = FWHMs.empty() ? 0.0 : FWHMs[0];
1048 m_source->function(domain, values);
1049 m_target->setAttributeValue(
"NumDeriv",
true);
1052 defaultFWHM, fixAllPeaks);
1063 peakCalculator.
calculateEigenSystem(energies, waveFunctions, hamiltonian, hamiltonianZeeman, nre);
1064 hamiltonian += hamiltonianZeeman;
1070 for (
size_t iSpec = 0; iSpec < temperatures.size(); ++iSpec) {
1072 updateSpectrum(*fun.getFunction(iSpec), nre, energies, waveFunctions, temperatures[iSpec],
1073 FWHMs.size() > iSpec ? FWHMs[iSpec] : 0., iSpec, iFirst, intensityScaling);
1077 updatePhysprop(nre, energies, waveFunctions, hamiltonian, *prop.second);
1089 auto defaultFWHM = FWHMs.empty() ? 0.0 : FWHMs[0];
1093 for (
size_t ionIndex = 0; ionIndex < compSource.nFunctions(); ++ionIndex) {
1096 compSource.getFunction(ionIndex)->function(domain, values);
1107 for (
size_t ionIndex = 0; ionIndex < compSource.nFunctions(); ++ionIndex) {
1114 peakCalculator.
calculateEigenSystem(energies, waveFunctions, hamiltonian, hamiltonianZeeman, nre);
1115 hamiltonian += hamiltonianZeeman;
1120 auto ionIntensityScaling = compSource.getFunction(ionIndex)->getParameter(
"IntensityScaling");
1121 for (
size_t iSpec = 0; iSpec < temperatures.size(); ++iSpec) {
1123 auto &ionSpectrum =
dynamic_cast<CompositeFunction &
>(*spectrum.getFunction(ionIndex));
1124 auto spectrumIntensityScaling =
m_control.
getFunction(iSpec)->getParameter(
"IntensityScaling");
1125 updateSpectrum(ionSpectrum, nre, energies, waveFunctions, temperatures[iSpec],
1126 FWHMs.size() > iSpec ? FWHMs[iSpec] : 0., iSpec, iFirst,
1127 ionIntensityScaling * spectrumIntensityScaling);
1130 std::string prefix(
"ion");
1132 auto prefixSize = prefix.size();
1134 if (prop.first.substr(0, prefixSize) == prefix) {
1135 updatePhysprop(nre, energies, waveFunctions, hamiltonian, *prop.second);
1154 size_t iSpec,
size_t iFirst,
double intensityScaling)
const {
1162 calcExcitations(nre, energies, waveFunctions, temperature, values, intensityScaling);
1193 for (
size_t i = 0; i <
n; ++i) {
1194 size_t j = i + iFirst;
1195 auto paramName(prefix);
1207 size_t peakIndex = 0;
1210 const auto &background = *
m_target->getFunction(0);
1215 for (
size_t ip = peakIndex; ip <
m_target->nFunctions(); ++ip) {
1216 std::string prefix(PEAK_PREFIX);
1227 std::string prefix(SPECTRUM_PREFIX);
1234 size_t peakIndex = 0;
1235 for (
size_t iSpec = 0; iSpec <
m_target->nFunctions(); ++iSpec) {
1238 std::string spectrumPrefix(SPECTRUM_PREFIX);
1242 const auto &background = *spectrum->getFunction(0);
1247 for (
size_t ip = peakIndex; ip < spectrum->nFunctions(); ++ip) {
1248 std::string prefix(spectrumPrefix);
1249 prefix.append(PEAK_PREFIX).append(
std::to_string(ip - peakIndex)).append(
".");
1266 for (
size_t ion = 0; ion < crystalField.nFunctions(); ++ion) {
1267 std::string prefix(ION_PREFIX);
1273 size_t ionIndex = 0;
1276 const auto &background = *
m_target->getFunction(0);
1281 for (
size_t ion = ionIndex; ion <
m_target->nFunctions(); ++ion) {
1282 std::string ionPrefix(ION_PREFIX);
1286 for (
size_t ip = 0; ip < spectrum.nFunctions(); ++ip) {
1287 std::string prefix(ionPrefix);
1288 prefix.append(PEAK_PREFIX).append(
std::to_string(ip)).append(
".");
1299 std::string prefix(SPECTRUM_PREFIX);
1305 for (
size_t ion = 0; ion < crystalField.nFunctions(); ++ion) {
1306 std::string prefix(ION_PREFIX);
1312 for (
size_t iSpec = 0; iSpec <
nSpectra(); ++iSpec) {
1314 std::string spectrumPrefix(SPECTRUM_PREFIX);
1318 for (
size_t ion = 0; ion < crystalField.nFunctions(); ++ion) {
1319 auto &ionSpectrum =
dynamic_cast<const CompositeFunction &
>(*spectrum.getFunction(ion));
1320 size_t peakIndex = 0;
1323 std::string prefix(spectrumPrefix);
1324 prefix.append(BACKGROUND_PREFIX).append(
".");
1327 std::string ionPrefix(ION_PREFIX);
1328 ionPrefix.append(
std::to_string(ion)).append(
".").append(spectrumPrefix);
1330 for (
size_t ip = peakIndex; ip < ionSpectrum.nFunctions(); ++ip) {
1331 std::string prefix(ionPrefix);
1332 prefix.append(PEAK_PREFIX).append(
std::to_string(ip - peakIndex)).append(
".");
1340 std::string physPropPrefix(spectrum.getFunction(0)->name());
1341 physPropPrefix.append(
".");
1342 for (
size_t ion = 0; ion < crystalField.nFunctions(); ++ion) {
1343 std::string prefix(ION_PREFIX);
1344 prefix.append(
std::to_string(ion)).append(
".").append(physPropPrefix);
1361 for (
size_t i = 0; i < np; ++i) {
std::vector< size_t > m_IntensityScalingIdx
std::vector< size_t > m_PPLambdaIdxChild
std::vector< size_t > m_PPLambdaIdxSelf
double value
The value of the point.
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
std::map< DeltaEMode::Type, std::string > index
A composite function is a function containing other functions.
ParameterTie * getTie(size_t i) const override
Get the tie of i-th parameter.
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
size_t getParameterIndex(const ParameterReference &ref) const override
Return parameter index from a parameter reference.
void setParameterDescription(size_t, const std::string &description) override
Set i-th parameter description.
std::size_t nFunctions() const override
Number of functions.
bool isExplicitlySet(size_t i) const override
Checks if a parameter has been set explicitly.
size_t nParams() const override
Total number of parameters.
double getParameter(size_t i) const override
Get i-th parameter.
double getError(size_t i) const override
Get the fitting error for a parameter.
Attribute getAttribute(const std::string &name) const override
Return a value of attribute attName.
std::string parameterDescription(size_t i) const override
Returns the description of parameter i.
IFunction_sptr getFunction(std::size_t i) const override
Returns the pointer to i-th function.
void setError(size_t i, double err) override
Set the fitting error for a parameter.
IConstraint * getConstraint(size_t i) const override
Get constraint of i-th parameter.
ParameterStatus getParameterStatus(size_t i) const override
Get status of parameter.
void checkFunction()
Check the function.
void setParameterStatus(size_t i, ParameterStatus status) override
Change status of parameter.
Represent a domain of a very general type.
Base class that represents the domain of a function.
A class to store values calculated by a function.
size_t size() const
Return the number of values.
void expand(size_t n)
Expand values to a new size, preserve stored values.
void setCalculated(double value)
set all calculated values to same number
An interface to a constraint.
Attribute is a non-fitting parameter.
std::string asUnquotedString() const
Returns a string value that is guarenteed to be unquoted.
std::vector< double > asVector() const
Returns vector<double> if attribute is vector<double>, throws exception otherwise.
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
std::string asString() const
Returns string value if attribute is a string, throws exception otherwise.
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
bool isEmpty() const
Check if a string attribute is empty.
bool asBool() const
Returns bool value if attribute is a bool, throws exception otherwise.
This is an interface to a fitting function - a semi-abstarct class.
virtual size_t nParams() const =0
Total number of parameters.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
friend class CompositeFunction
ParameterStatus
Describe parameter status in relation to fitting: Active: Fit varies such parameter directly.
virtual void tie(const std::string &parName, const std::string &expr, bool isDefault=false)
Tie a parameter to other parameters (or a constant)
virtual ParameterTie * getTie(size_t i) const
Get the tie of i-th parameter.
virtual void setAttribute(const std::string &name, const Attribute &)
Set a value to attribute attName.
virtual void setUpForFit()
Set up the function for a fit.
virtual std::vector< std::string > getAttributeNames() const
Returns a list of attribute names.
virtual std::string attributeName(size_t index) const
Get name of ith attribute.
virtual std::string parameterName(size_t i) const =0
Returns the name of parameter i.
virtual std::string name() const =0
Returns the function's name.
virtual size_t nAttributes() const
Returns the number of attributes associated with the function.
virtual IConstraint * getConstraint(size_t i) const
Get constraint of i-th parameter.
A composite function defined on a CompositeDomain.
A reference to a parameter in a function.
IFunction * ownerFunction() const
std::size_t getLocalIndex() const
Return parameter index in the local function.
IFunction * getLocalFunction() const
Return pointer to the local function.
double get(const size_t i) const
Get an element.
size_t size() const
Size of the vector.
const std::vector< double > & temperatures() const
API::IFunction_sptr buildSource()
Build the source function.
void buildControls()
Build control functions for individual spectra.
const std::vector< std::string > & physProps() const
const std::vector< double > & FWHMs() const
bool hasPhysProperties() const
Check if there are any phys. properties.
bool isMultiSpectrum() const
Is it a multi-spectrum case?
bool isMultiSite() const
Are there multiple ions?
bool hasPeaks() const
Any peaks defined?
void updateMultiSite() const
Update the target function in a multi site case.
Attribute getAttribute(const std::string &name) const override
Return a value of attribute attName.
std::unordered_map< std::string, size_t > m_mapNames2Indices
Map parameter names to indices.
void updatePhysprop(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, const ComplexFortranMatrix &ham, API::IFunction &fun) const
Update a physical property function.
API::IFunction_sptr buildPhysprop(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, const ComplexFortranMatrix &ham, const std::string &propName) const
Build a physical property function.
void checkTargetFunction() const
Update target function if necessary.
API::IFunction_sptr m_source
Function that calculates parameters of the target function.
bool m_dirtyTarget
Flag indicating that updateTargetFunction() is required.
void calcExcitations(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, double temperature, API::FunctionValues &values, double intensityScaling) const
Calculate excitations at given temperature.
void updateMultiSiteMultiSpectrum() const
Update the target function in a multi site - multi spectrum case.
void updateMultiSiteSingleSpectrum() const
Update the target function in a multi site - single spectrum case.
void makeMapsSingleSiteMultiSpectrum() const
Parameter-index map for single-site multi-spectrum.
std::pair< API::IFunction *, std::string > getAttributeReference(const std::string &attName) const
Get a reference to an attribute.
void updateSpectrum(API::IFunction &spectrum, int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, double temperature, double fwhm, size_t iSpec, size_t iFirst, double intensityScaling) const
Update a function for a single spectrum.
size_t makeMapsForFunction(const IFunction &fun, size_t iFirst, const std::string &prefix) const
Make parameter names from names of a function and map them to indices.
void buildMultiSiteSingleSpectrum() const
Build the target function in a multi site - single spectrum case.
double getParameter(size_t i) const override
Get i-th parameter.
size_t parameterIndex(const std::string &name) const override
Returns the index of parameter name.
std::vector< std::string > m_attributeNames
Attribute names.
void setSource(API::IFunction_sptr source) const
Set the source function.
void setAttribute(const std::string &name, const Attribute &) override
Set a value to attribute attName.
CrystalFieldFunction()
Constructor.
std::vector< std::string > m_mapIndices2Names
Map parameter indices to names.
void makeMapsMultiSiteMultiSpectrum() const
Parameter-index map for multi-site multi-spectrum.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
API::ParameterTie * getTie(size_t i) const override
Get the tie for i-th parameter.
API::CompositeFunction & compositeSource() const
Get a reference to the source function if it's composite.
std::vector< std::string > getAttributeNames() const override
Returns a list of attribute names.
std::vector< double > m_parameterResetCache
Temporary cache for parameter values during source function resetting.
bool hasParameter(const std::string &name) const override
Check if function has a parameter with this name.
void buildMultiSite() const
Build the target function in a multi site case.
bool hasBackground() const
Check if the spectra have a background.
API::IFunction_sptr buildSpectrum(int nre, const DoubleFortranVector &en, const ComplexFortranMatrix &wf, double temperature, double fwhm, size_t i, bool addBackground, double intensityScaling) const
Build a function for a single spectrum.
bool hasPhysProperties() const
Check if there are any phys. properties.
size_t nSpectra() const
Get number of the number of spectra (excluding phys prop data).
void makeMapsMultiSiteSingleSpectrum() const
Parameter-index map for multi-site single-spectrum.
double getError(size_t i) const override
Get the fitting error for a parameter.
void buildSingleSiteSingleSpectrum() const
Build the target function in a single site - single spectrum case.
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
bool ignoreTie(const API::ParameterTie &tie) const override
Checks if whether tie should be ignored.
bool hasAttribute(const std::string &name) const override
Check if attribute attName exists.
void setUpForFit() override
Set up the function for a fit.
void buildSingleSiteMultiSpectrum() const
Build the target function in a single site - multi spectrum case.
void setError(size_t i, double err) override
Set the fitting error for a parameter.
void checkSourceFunction() const
Build source function if necessary.
bool isMultiSpectrum() const
Check if the function is set up for a multi-spectrum calculations (Multiple temperatures defined)
void buildMultiSiteMultiSpectrum() const
Build the target function in a multi site - multi spectrum case.
size_t getNumberDomains() const override
Get number of domains required by this function.
std::unordered_map< std::string, API::IFunction_sptr > m_mapPrefixes2PhysProps
Map parameter/attribute prefixes to pointers to phys prop functions.
void buildSourceFunction() const
Build the source function.
void makeMaps() const
Make maps between parameter names and indices.
void buildSingleSite() const
Build the target function in a single site case.
void cacheSourceParameters() const
Temporary cache parameter values of the source function if it's initialised.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
std::vector< bool > m_fixResetCache
size_t m_nControlParams
Cached number of parameters in m_control.
void updateTargetFunction() const
Update the target function.
bool isExplicitlySet(size_t i) const override
Checks if a parameter has been set explicitly.
CrystalFieldControl m_control
Function that creates the source function.
void buildTargetFunction() const
Build target function.
void buildAttributeNames() const
Build and cache the attribute names.
void setParameterStatus(size_t i, ParameterStatus status) override
Change status of parameter.
void updateSingleSite() const
Update the target function in a single site case.
size_t m_nControlSourceParams
Cached number of parameters in m_control and m_source.
void updateSingleSiteMultiSpectrum() const
Update the target function in a single site - multi spectrum case.
void setParameterDescription(size_t, const std::string &description) override
Set i-th parameter description.
API::CompositeFunction_sptr m_target
Function that actually calculates the output.
API::IConstraint * getConstraint(size_t i) const override
Get the i-th constraint.
bool isMultiSite() const
Check if the function is set up for a multi-site calculations.
std::string name() const override
Returns the function's name.
void makeMapsSingleSiteSingleSpectrum() const
Parameter-index map for single-site single-spectrum.
size_t getParameterIndex(const API::ParameterReference &ref) const override
Return parameter index from a parameter reference.
ParameterStatus getParameterStatus(size_t i) const override
Get status of parameter.
std::string parameterDescription(size_t i) const override
Returns the description of parameter i.
void updateSingleSiteSingleSpectrum() const
Update the target function in a single site - single spectrum case.
bool hasPeaks() const
Check if there are peaks (there is at least one spectrum).
size_t nAttributes() const override
Returns the number of attributes associated with the function.
void function(const API::FunctionDomain &domain, API::FunctionValues &values) const override
Evaluate the function.
std::vector< API::IFunction_sptr > createEquivalentFunctions() const override
Split this function (if needed) into a list of independent functions.
size_t nParams() const override
Total number of parameters.
void setEnergy(const DoubleFortranVector &en)
void setHamiltonian(const ComplexFortranMatrix &ham, const int nre)
void setHamiltonian(const ComplexFortranMatrix &ham, const int nre)
CrystalFieldPeaks is a function that calculates crystal field peak positions and intensities.
void calculateEigenSystem(DoubleFortranVector &en, ComplexFortranMatrix &wf, ComplexFortranMatrix &ham, ComplexFortranMatrix &hz, int &nre) const
Calculate the crystal field eigensystem.
void setEigensystem(const DoubleFortranVector &en, const ComplexFortranMatrix &wf, const int nre)
Marks code as not implemented yet.
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
size_t updateSpectrumFunction(API::CompositeFunction &spectrum, const std::string &peakShape, const API::FunctionValues ¢resAndIntensities, size_t iFirst, const std::vector< double > &xVec, const std::vector< double > &yVec, double fwhmVariation, double defaultFWHM, bool fixAllPeaks)
Update the peaks parameters after recalculationof the crystal field.
size_t buildSpectrumFunction(API::CompositeFunction &spectrum, const std::string &peakShape, const API::FunctionValues ¢resAndIntensities, const std::vector< double > &xVec, const std::vector< double > &yVec, double fwhmVariation, double defaultFWHM, size_t nRequiredPeaks, bool fixAllPeaks)
Utility functions to help set up peak functions in a Crystal Field spectrum.
void MANTID_CURVEFITTING_DLL calculateExcitations(const DoubleFortranVector &e_energies, const DoubleFortranMatrix &i_energies, double de, double di, DoubleFortranVector &e_excitations, DoubleFortranVector &i_excitations)
Calculate the excitations (transition energies) and their intensities.
void MANTID_CURVEFITTING_DLL calculateIntensities(int nre, const DoubleFortranVector &energies, const ComplexFortranMatrix &wavefunctions, double temperature, double de, IntFortranVector °eneration, DoubleFortranVector &e_energies, DoubleFortranMatrix &i_energies)
Calculate the intensities of transitions.
std::string to_string(const wide_integer< Bits, Signed > &n)