Commit 129191ef authored by Roman Tolchenov's avatar Roman Tolchenov
Browse files

Re #18222. Fix parameter referencing in FunctionGenerator.

parent 64da8a34
......@@ -416,8 +416,10 @@ size_t CompositeFunction::addFunction(IFunction_sptr f) {
* @param i :: The index of the function to remove
*/
void CompositeFunction::removeFunction(size_t i) {
if (i >= nFunctions())
throw std::out_of_range("Function index out of range.");
if (i >= nFunctions()) {
throw std::out_of_range("Function index (" + std::to_string(i) +
") out of range (" + std::to_string(nFunctions()) + ").");
}
IFunction_sptr fun = getFunction(i);
......@@ -477,8 +479,11 @@ void CompositeFunction::replaceFunctionPtr(const IFunction_sptr f_old,
* @param f :: A pointer to the new function
*/
void CompositeFunction::replaceFunction(size_t i, IFunction_sptr f) {
if (i >= nFunctions())
throw std::out_of_range("Function index out of range.");
if (i >= nFunctions()) {
throw std::out_of_range("Function index (" + std::to_string(i) +
") out of range (" + std::to_string(nFunctions()) + ").");
}
IFunction_sptr fun = getFunction(i);
size_t np_old = fun->nParams();
......@@ -522,7 +527,8 @@ void CompositeFunction::replaceFunction(size_t i, IFunction_sptr f) {
*/
IFunction_sptr CompositeFunction::getFunction(std::size_t i) const {
if (i >= nFunctions()) {
throw std::out_of_range("Function index out of range.");
throw std::out_of_range("Function index (" + std::to_string(i) +
") out of range (" + std::to_string(nFunctions()) + ").");
}
return m_functions[i];
}
......@@ -534,7 +540,8 @@ IFunction_sptr CompositeFunction::getFunction(std::size_t i) const {
*/
size_t CompositeFunction::functionIndex(std::size_t i) const {
if (i >= nParams()) {
throw std::out_of_range("Function parameter index out of range.");
throw std::out_of_range("Function parameter index (" + std::to_string(i) +
") out of range (" + std::to_string(nParams()) + ").");
}
return m_IFunction[i];
}
......
......@@ -158,9 +158,13 @@ void FunctionGenerator::unfix(size_t i) {
/// Return parameter index from a parameter reference.
size_t
FunctionGenerator::getParameterIndex(const ParameterReference &ref) const {
auto index = m_source->getParameterIndex(ref);
if (index < m_nOwnParams) {
return index;
if (ref.getFunction() == this) {
auto index = ref.getIndex();
auto np = nParams();
if (index < np) {
return index;
}
return np;
}
checkTargetFunction();
return m_target->getParameterIndex(ref) + m_nOwnParams;
......@@ -265,6 +269,7 @@ void FunctionGenerator::addTie(API::ParameterTie *tie) {
m_source->addTie(tie);
} else {
checkTargetFunction();
tie->reset(m_target.get(), tie->getIndex() - m_nOwnParams, tie->isDefault());
m_target->addTie(tie);
}
}
......
......@@ -652,6 +652,37 @@ public:
TS_ASSERT_THROWS_NOTHING(fit->execute());
}
void test_ties_in_composite_function() {
std::string funDef =
"name=CrystalFieldSpectrum,Ion=Ce,Symmetry=C2v,Temperature=44.0,"
"ToleranceEnergy=1e-10,ToleranceIntensity=0.1,FixAllPeaks=False,"
"PeakShape=Lorentzian,FWHM=1.1,B44=-0.12544,B20=0.37737,B22=3.977,B40=-"
"0.031787,B42=-0.11611;name=CrystalFieldSpectrum,Ion=Pr,Symmetry=C2v,Temperature="
"44.0,ToleranceEnergy=1e-10,ToleranceIntensity=0.1,FixAllPeaks=False,"
"PeakShape=Lorentzian,FWHM=1.1,B44=-0.12544,B20=0.37737,B22=3.977,B40=-"
"0.031787,B42=-0.11611;ties=(f1.IntensityScaling=2.0*f0.IntensityScaling,f0.f1.FWHM=f1.f2.FWHM/2)";
auto fun = FunctionFactory::Instance().createInitialized(funDef);
{
auto index = fun->parameterIndex("f1.IntensityScaling");
auto tie = fun->getTie(index);
TS_ASSERT(tie);
if (!tie) {
return;
}
TS_ASSERT_EQUALS(tie->asString(),
"f1.IntensityScaling=2.0*f0.IntensityScaling");
}
{
auto index = fun->parameterIndex("f0.f1.FWHM");
auto tie = fun->getTie(index);
TS_ASSERT(tie);
if (!tie) {
return;
}
TS_ASSERT_EQUALS(tie->asString(), "f0.f1.FWHM=f1.f2.FWHM/2");
}
}
private:
std::pair<double, double> getBounds(API::IFunction &fun,
const std::string &parName) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment