Commit cea418ff authored by Roman Tolchenov's avatar Roman Tolchenov
Browse files

Re #15700. Clang-format patch.

parent bcc87feb
......@@ -375,7 +375,7 @@ void CompositeFunction::checkFunction() {
}
}
/**
/**
* Remove all member functions
*/
void CompositeFunction::clear() {
......@@ -746,6 +746,5 @@ CompositeFunction::getContainingFunction(const ParameterReference &ref) const {
return IFunction_sptr();
}
} // namespace API
} // namespace Mantid
......@@ -12,7 +12,7 @@ namespace Mantid {
namespace CurveFitting {
namespace Functions {
/**
Calculates crystal field spectrum.
Calculates crystal field spectrum.
Copyright © 2007-8 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
......@@ -37,7 +37,6 @@ Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport CrystalFieldSpectrum : public API::IFunction {
public:
/// Constructor
CrystalFieldSpectrum();
......@@ -46,7 +45,7 @@ public:
const std::string category() const override { return "General"; }
/** @name Overrides implementing composition of two functions:
* CrystalFieldPeaks and CompositeFunction.
* CrystalFieldPeaks and CompositeFunction.
* These can be factored out into a separate class later.
*/
//@{
......@@ -89,10 +88,12 @@ public:
virtual void unfix(size_t i) override;
/// Return parameter index from a parameter reference.
virtual size_t getParameterIndex(const API::ParameterReference &ref) const override;
virtual size_t
getParameterIndex(const API::ParameterReference &ref) const override;
/// Tie a parameter to other parameters (or a constant)
virtual API::ParameterTie *tie(const std::string &parName, const std::string &expr,
bool isDefault = false) override;
virtual API::ParameterTie *tie(const std::string &parName,
const std::string &expr,
bool isDefault = false) override;
/// Apply the ties
virtual void applyTies() override;
/// Remove all ties
......@@ -134,13 +135,15 @@ public:
/// Return a value of attribute attName
virtual Attribute getAttribute(const std::string &name) const override;
/// Set a value to attribute attName
virtual void setAttribute(const std::string &name, const Attribute &) override;
virtual void setAttribute(const std::string &name,
const Attribute &) override;
/// Check if attribute attName exists
virtual bool hasAttribute(const std::string &name) const override;
//@}
/// Evaluate the function
void function(const API::FunctionDomain &domain, API::FunctionValues &values) const override;
void function(const API::FunctionDomain &domain,
API::FunctionValues &values) const override;
protected:
/// overwrite IFunction base class method, which declare function parameters
......
......@@ -72,8 +72,10 @@ protected:
const size_t nData) override;
/// overwrite IFunction base class method, which declare function parameters
void init() override;
private:
/// When Amplitude is set via setHeight() and fwhm() == 0 height is made equal to Amplitude.
/// When Amplitude is set via setHeight() and fwhm() == 0 height is made equal
/// to Amplitude.
/// The flag is used after that when FWHM is set to non-zero value.
/// The height in this case must remain the same but amplitude change.
bool m_amplitudeEqualHeight;
......
......@@ -317,7 +317,8 @@ CrystalFieldPeaks::CrystalFieldPeaks()
declareParameter("IB65", 0.0, "Imaginary part of the B65 field parameter.");
declareParameter("IB66", 0.0, "Imaginary part of the B66 field parameter.");
declareParameter("IntensityScaling", 1.0, "A scaling factor for peak intensities.");
declareParameter("IntensityScaling", 1.0,
"A scaling factor for peak intensities.");
setSymmetryC1(*this);
}
......
......@@ -33,16 +33,17 @@ using namespace API;
DECLARE_FUNCTION(CrystalFieldSpectrum)
/// Constructor
CrystalFieldSpectrum::CrystalFieldSpectrum(): m_nOwnParams(m_crystalField.nParams()),m_dirty(true) {
CrystalFieldSpectrum::CrystalFieldSpectrum()
: m_nOwnParams(m_crystalField.nParams()), m_dirty(true) {
declareAttribute("PeakShape", Attribute("Lorentzian"));
declareAttribute("FWHM", Attribute(0.0));
}
void CrystalFieldSpectrum::init() {}
/// Set i-th parameter
/// Set i-th parameter
void CrystalFieldSpectrum::setParameter(size_t i, const double &value,
bool explicitlySet) {
bool explicitlySet) {
if (i < m_nOwnParams) {
m_crystalField.setParameter(i, value, explicitlySet);
m_dirty = true;
......@@ -52,9 +53,9 @@ void CrystalFieldSpectrum::setParameter(size_t i, const double &value,
}
}
/// Set i-th parameter description
void CrystalFieldSpectrum::setParameterDescription(size_t i,
const std::string &description) {
/// Set i-th parameter description
void CrystalFieldSpectrum::setParameterDescription(
size_t i, const std::string &description) {
if (i < m_nOwnParams) {
m_crystalField.setParameterDescription(i, description);
} else {
......@@ -63,38 +64,39 @@ void CrystalFieldSpectrum::setParameterDescription(size_t i,
}
}
/// Get i-th parameter
/// Get i-th parameter
double CrystalFieldSpectrum::getParameter(size_t i) const {
return i < m_nOwnParams ? m_crystalField.getParameter(i)
: m_spectrum.getParameter(i - m_nOwnParams);
}
/// Set parameter by name.
void CrystalFieldSpectrum::setParameter(const std::string &name, const double &value,
bool explicitlySet) {
void CrystalFieldSpectrum::setParameter(const std::string &name,
const double &value,
bool explicitlySet) {
auto i = parameterIndex(name);
setParameter(i, value, explicitlySet);
}
/// Set description of parameter by name.
void CrystalFieldSpectrum::setParameterDescription(const std::string &name,
const std::string &description) {
/// Set description of parameter by name.
void CrystalFieldSpectrum::setParameterDescription(
const std::string &name, const std::string &description) {
auto i = parameterIndex(name);
setParameterDescription(i, description);
}
/// Get parameter by name.
/// Get parameter by name.
double CrystalFieldSpectrum::getParameter(const std::string &name) const {
auto i = parameterIndex(name);
return getParameter(i);
}
/// Total number of parameters
/// Total number of parameters
size_t CrystalFieldSpectrum::nParams() const {
return m_crystalField.nParams() + m_spectrum.nParams();
}
/// Returns the index of parameter name
/// Returns the index of parameter name
size_t CrystalFieldSpectrum::parameterIndex(const std::string &name) const {
if (isOwnName(name)) {
return m_crystalField.parameterIndex(name);
......@@ -104,27 +106,31 @@ size_t CrystalFieldSpectrum::parameterIndex(const std::string &name) const {
}
}
/// Returns the name of parameter i
/// Returns the name of parameter i
std::string CrystalFieldSpectrum::parameterName(size_t i) const {
return i < m_nOwnParams ? m_crystalField.parameterName(i) : m_spectrum.parameterName(i - m_nOwnParams);
return i < m_nOwnParams ? m_crystalField.parameterName(i)
: m_spectrum.parameterName(i - m_nOwnParams);
}
/// Returns the description of parameter i
/// Returns the description of parameter i
std::string CrystalFieldSpectrum::parameterDescription(size_t i) const {
return i < m_nOwnParams ? m_crystalField.parameterDescription(i) : m_spectrum.parameterDescription(i - m_nOwnParams);
return i < m_nOwnParams ? m_crystalField.parameterDescription(i)
: m_spectrum.parameterDescription(i - m_nOwnParams);
}
/// Checks if a parameter has been set explicitly
/// Checks if a parameter has been set explicitly
bool CrystalFieldSpectrum::isExplicitlySet(size_t i) const {
return i < m_nOwnParams ? m_crystalField.isExplicitlySet(i) : m_spectrum.isExplicitlySet(i - m_nOwnParams);
return i < m_nOwnParams ? m_crystalField.isExplicitlySet(i)
: m_spectrum.isExplicitlySet(i - m_nOwnParams);
}
/// Get the fitting error for a parameter
/// Get the fitting error for a parameter
double CrystalFieldSpectrum::getError(size_t i) const {
return i < m_nOwnParams ? m_crystalField.getError(i) : m_spectrum.getError(i - m_nOwnParams);
return i < m_nOwnParams ? m_crystalField.getError(i)
: m_spectrum.getError(i - m_nOwnParams);
}
/// Set the fitting error for a parameter
/// Set the fitting error for a parameter
void CrystalFieldSpectrum::setError(size_t i, double err) {
if (i < m_nOwnParams) {
m_crystalField.setError(i, err);
......@@ -134,11 +140,13 @@ void CrystalFieldSpectrum::setError(size_t i, double err) {
}
}
/// Check if a declared parameter i is fixed
/// Check if a declared parameter i is fixed
bool CrystalFieldSpectrum::isFixed(size_t i) const {
return i < m_nOwnParams ? m_crystalField.isFixed(i) : m_spectrum.isFixed(i - m_nOwnParams);}
return i < m_nOwnParams ? m_crystalField.isFixed(i)
: m_spectrum.isFixed(i - m_nOwnParams);
}
/// Removes a declared parameter i from the list of active
/// Removes a declared parameter i from the list of active
void CrystalFieldSpectrum::fix(size_t i) {
if (i < m_nOwnParams) {
m_crystalField.fix(i);
......@@ -147,7 +155,7 @@ void CrystalFieldSpectrum::fix(size_t i) {
}
}
/// Restores a declared parameter i to the active status
/// Restores a declared parameter i to the active status
void CrystalFieldSpectrum::unfix(size_t i) {
if (i < m_nOwnParams) {
m_crystalField.unfix(i);
......@@ -157,7 +165,8 @@ void CrystalFieldSpectrum::unfix(size_t i) {
}
/// Return parameter index from a parameter reference.
size_t CrystalFieldSpectrum::getParameterIndex(const ParameterReference &ref) const {
size_t
CrystalFieldSpectrum::getParameterIndex(const ParameterReference &ref) const {
auto index = m_crystalField.getParameterIndex(ref);
if (index < m_nOwnParams) {
return index;
......@@ -166,8 +175,9 @@ size_t CrystalFieldSpectrum::getParameterIndex(const ParameterReference &ref) co
}
/// Tie a parameter to other parameters (or a constant)
API::ParameterTie *CrystalFieldSpectrum::tie(const std::string &parName, const std::string &expr,
bool isDefault) {
API::ParameterTie *CrystalFieldSpectrum::tie(const std::string &parName,
const std::string &expr,
bool isDefault) {
if (isOwnName(parName)) {
return m_crystalField.tie(parName, expr, isDefault);
} else {
......@@ -240,13 +250,11 @@ void CrystalFieldSpectrum::removeConstraint(const std::string &parName) {
}
/// Set up the function for a fit.
void CrystalFieldSpectrum::setUpForFit() {
updateSpectrumFunction();
}
void CrystalFieldSpectrum::setUpForFit() { updateSpectrumFunction(); }
/// Declare a new parameter
void CrystalFieldSpectrum::declareParameter(const std::string &, double,
const std::string &) {
const std::string &) {
throw Kernel::Exception::NotImplementedError(
"CrystalFieldSpectrum cannot not have its own parameters.");
}
......@@ -262,10 +270,10 @@ void CrystalFieldSpectrum::addTie(API::ParameterTie *tie) {
}
}
/// Returns the number of attributes associated with the function
size_t CrystalFieldSpectrum::nAttributes() const {
return IFunction::nAttributes() + m_crystalField.nAttributes() + m_spectrum.nAttributes();
return IFunction::nAttributes() + m_crystalField.nAttributes() +
m_spectrum.nAttributes();
}
/// Returns a list of attribute names
......@@ -279,7 +287,8 @@ std::vector<std::string> CrystalFieldSpectrum::getAttributeNames() const {
}
/// Return a value of attribute attName
API::IFunction::Attribute CrystalFieldSpectrum::getAttribute(const std::string &attName) const {
API::IFunction::Attribute
CrystalFieldSpectrum::getAttribute(const std::string &attName) const {
if (IFunction::hasAttribute(attName)) {
return IFunction::getAttribute(attName);
} else if (attName == "NumDeriv") {
......@@ -293,7 +302,7 @@ API::IFunction::Attribute CrystalFieldSpectrum::getAttribute(const std::string &
/// Set a value to attribute attName
void CrystalFieldSpectrum::setAttribute(const std::string &attName,
const IFunction::Attribute &att) {
const IFunction::Attribute &att) {
if (IFunction::hasAttribute(attName)) {
IFunction::setAttribute(attName, att);
m_dirty = true;
......@@ -323,7 +332,7 @@ bool CrystalFieldSpectrum::hasAttribute(const std::string &attName) const {
// Evaluates the function
void CrystalFieldSpectrum::function(const API::FunctionDomain &domain,
API::FunctionValues &values) const {
API::FunctionValues &values) const {
updateSpectrumFunction();
m_spectrum.function(domain, values);
}
......@@ -332,7 +341,8 @@ void CrystalFieldSpectrum::function(const API::FunctionDomain &domain,
/// @param aName :: A name to test.
bool CrystalFieldSpectrum::isOwnName(const std::string &aName) const {
if (aName.empty()) {
throw std::invalid_argument("Parameter or attribute name cannot be empty string.");
throw std::invalid_argument(
"Parameter or attribute name cannot be empty string.");
}
return (aName.front() != 'f' || aName.find('.') == std::string::npos);
}
......@@ -352,13 +362,14 @@ void CrystalFieldSpectrum::buildSpectrumFunction() const {
}
if (values.size() % 2 != 0) {
throw std::runtime_error("CrystalFieldPeaks returned add number of values.");
throw std::runtime_error(
"CrystalFieldPeaks returned add number of values.");
}
auto peakShape = IFunction::getAttribute("PeakShape").asString();
auto fwhm = IFunction::getAttribute("FWHM").asDouble();
auto nPeaks = values.size() / 2;
for(size_t i = 0; i < nPeaks; ++i) {
for (size_t i = 0; i < nPeaks; ++i) {
auto fun = API::FunctionFactory::Instance().createFunction(peakShape);
auto peak = boost::dynamic_pointer_cast<API::IPeakFunction>(fun);
if (!peak) {
......@@ -386,12 +397,13 @@ void CrystalFieldSpectrum::updateSpectrumFunction() const {
auto nPeaks = values.size() / 2;
if (m_spectrum.nFunctions() != nPeaks) {
//throw std::runtime_error("Number of peaks has changed: "+std::to_string(nPeaks));
// throw std::runtime_error("Number of peaks has changed:
// "+std::to_string(nPeaks));
buildSpectrumFunction();
return;
}
for(size_t i = 0; i < nPeaks; ++i) {
for (size_t i = 0; i < nPeaks; ++i) {
auto fun = m_spectrum.getFunction(i);
auto peak = boost::dynamic_pointer_cast<API::IPeakFunction>(fun);
if (!peak) {
......@@ -402,7 +414,6 @@ void CrystalFieldSpectrum::updateSpectrumFunction() const {
peak->setCentre(centre);
peak->setIntensity(intensity);
}
}
/// Update spectrum function if necessary.
......
......@@ -18,8 +18,7 @@ using namespace API;
DECLARE_FUNCTION(Gaussian)
Gaussian::Gaussian() : IPeakFunction(), m_intensityCache(0.0) {
}
Gaussian::Gaussian() : IPeakFunction(), m_intensityCache(0.0) {}
void Gaussian::init() {
declareParameter("Height", 0.0, "Height of peak");
......@@ -88,7 +87,8 @@ double Gaussian::intensity() const {
m_intensityCache = height;
}
} else {
m_intensityCache = getParameter("Height") * getParameter("Sigma") * sqrt(2.0 * M_PI);
m_intensityCache =
getParameter("Height") * getParameter("Sigma") * sqrt(2.0 * M_PI);
}
return m_intensityCache;
}
......@@ -108,23 +108,17 @@ void Gaussian::setIntensity(const double i) {
}
}
void Gaussian::fixCentre() {
fixParameter("PeakCentre");
}
void Gaussian::fixCentre() { fixParameter("PeakCentre"); }
void Gaussian::unfixCentre() {
unfixParameter("PeakCentre");
}
void Gaussian::unfixCentre() { unfixParameter("PeakCentre"); }
void Gaussian::fixIntensity() {
std::string formula = std::to_string(intensity() / sqrt(2.0 * M_PI)) + "/Sigma";
std::string formula =
std::to_string(intensity() / sqrt(2.0 * M_PI)) + "/Sigma";
tie("Height", formula);
}
void Gaussian::unfixIntensity() {
removeTie("Height");
}
void Gaussian::unfixIntensity() { removeTie("Height"); }
} // namespace Functions
} // namespace CurveFitting
......
......@@ -44,7 +44,7 @@ void Lorentzian::setHeight(const double h) {
}
}
void Lorentzian::setFwhm(const double w) {
void Lorentzian::setFwhm(const double w) {
auto gamma = getParameter("FWHM");
if (gamma == 0.0 && w != 0.0 && m_amplitudeEqualHeight) {
auto h = getParameter("Amplitude");
......@@ -53,24 +53,16 @@ void Lorentzian::setFwhm(const double w) {
if (w != 0.0) {
m_amplitudeEqualHeight = false;
}
setParameter("FWHM", w);
setParameter("FWHM", w);
}
void Lorentzian::fixCentre() {
fixParameter("PeakCentre");
}
void Lorentzian::fixCentre() { fixParameter("PeakCentre"); }
void Lorentzian::unfixCentre() {
unfixParameter("PeakCentre");
}
void Lorentzian::unfixCentre() { unfixParameter("PeakCentre"); }
void Lorentzian::fixIntensity() {
fixParameter("Amplitude");
}
void Lorentzian::fixIntensity() { fixParameter("Amplitude"); }
void Lorentzian::unfixIntensity() {
unfixParameter("Amplitude");
}
void Lorentzian::unfixIntensity() { unfixParameter("Amplitude"); }
void Lorentzian::functionLocal(double *out, const double *xValues,
const size_t nData) const {
......
......@@ -286,7 +286,7 @@ private:
ws->setX(0, x.toVector());
ws->getSpectrum(0)->setData(y.toVector(), e);
assert(n == noise.size());
for(size_t i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
ws->dataY(0)[i] += noiseLevel * noise[i];
ws->dataE(0)[i] += noiseLevel;
}
......@@ -295,4 +295,3 @@ private:
};
#endif /*CHEBYSHEVTEST_H_*/
......@@ -19,10 +19,8 @@ using namespace Mantid::CurveFitting;
using namespace Mantid::CurveFitting::Algorithms;
using namespace Mantid::CurveFitting::Functions;
class CrystalFieldSpectrumTest : public CxxTest::TestSuite {
public:
void test_function() {
CrystalFieldSpectrum fun;
fun.setParameter("B20", 0.37737);
......@@ -82,7 +80,8 @@ public:
}
void test_evaluate() {
auto fun = boost::shared_ptr<CrystalFieldSpectrum>(new CrystalFieldSpectrum);
auto fun =
boost::shared_ptr<CrystalFieldSpectrum>(new CrystalFieldSpectrum);
fun->setParameter("B20", 0.37737);
fun->setParameter("B22", 3.9770);
fun->setParameter("B40", -0.031787);
......@@ -106,13 +105,14 @@ public:
FunctionValues t(x);
testFun->function(x, t);
for(size_t i = 0; i < x.size(); ++i) {
TS_ASSERT_DELTA( y[i] / t[i], 1, 2e-4);
for (size_t i = 0; i < x.size(); ++i) {
TS_ASSERT_DELTA(y[i] / t[i], 1, 2e-4);
}
}
void test_evaluate_gaussian() {
auto fun = boost::shared_ptr<CrystalFieldSpectrum>(new CrystalFieldSpectrum);
auto fun =
boost::shared_ptr<CrystalFieldSpectrum>(new CrystalFieldSpectrum);
fun->setParameter("B20", 0.37737);
fun->setParameter("B22", 3.9770);
fun->setParameter("B40", -0.031787);
......@@ -134,14 +134,17 @@ public:
auto height2 = std::to_string(0.7204 / (2.0 * sqrt(2.0 * M_PI)));
auto height3 = std::to_string(0.4298 / (3.0 * sqrt(2.0 * M_PI)));
auto testFun = FunctionFactory::Instance().createInitialized(
"name=Gaussian,PeakCentre=0.0,Height="+height1+",Sigma=10.0;"
"name=Gaussian,PeakCentre=29.3261,Height="+height2+",Sigma=2.0;"
"name=Gaussian,PeakCentre=44.3412,Height="+height3+",Sigma=3.0;");
"name=Gaussian,PeakCentre=0.0,Height=" + height1 +
",Sigma=10.0;"
"name=Gaussian,PeakCentre=29.3261,Height=" +
height2 + ",Sigma=2.0;"
"name=Gaussian,PeakCentre=44.3412,Height=" +
height3 + ",Sigma=3.0;");
FunctionValues t(x);
testFun->function(x, t);
for(size_t i = 0; i < x.size(); ++i) {
TS_ASSERT_DELTA( y[i] / t[i], 1, 2e-4);
for (size_t i = 0; i < x.size(); ++i) {
TS_ASSERT_DELTA(y[i] / t[i], 1, 2e-4);
}
}
......@@ -167,24 +170,24 @@ public:
auto i = fun->parameterIndex("f2.FWHM");
auto tie = fun->getTie(i);
TS_ASSERT(tie);
if (tie){
if (tie) {
TS_ASSERT_EQUALS(tie->asString(), "f2.FWHM=2.1")
}
i = fun->parameterIndex("B60");
tie = fun->getTie(i);
TS_ASSERT(tie);
if (tie){
if (tie) {
TS_ASSERT_EQUALS(tie->asString(), "B60=0")
}
i = fun->parameterIndex("BmolY");
tie = fun->getTie(i);
TS_ASSERT(tie);
if (tie){
if (tie) {
TS_ASSERT_EQUALS(tie->asString(), "BmolY=0")
}
size_t nTies = 0;
for(size_t i = 0; i < fun->nParams(); ++i) {
for (size_t i = 0; i < fun->nParams(); ++i) {
auto tie = fun->getTie(i);
if (tie) {
++nTies;
......@@ -195,7 +198,7 @@ public:
void test_constraints() {
std::string funDef =
"name=CrystalFieldSpectrum,Ion=Ce,B20=0.37,B22=3.9,"
"name=CrystalFieldSpectrum,Ion=Ce,B20=0.37,B22=3.9,"
"B40=-0.03,B42=-0.1,B44=-0.12,constraints=(0<B44<10,f1.FWHM>1.3)";
auto fun = FunctionFactory::Instance().createInitialized(funDef);
TS_ASSERT(fun);
......@@ -214,8 +217,6 @@ public:
TS_ASSERT_EQUALS(constraint->getIndex(), 13);
}
}
};
#endif /*CRYSTALFIELDSPECTRUMTEST_H_*/
......@@ -213,9 +213,9 @@ public:
TS_ASSERT(s.minimize());
API::IFunction_sptr res = costFun->getFittingFunction();
//std::cerr << "result=" << s.getError() << std::endl;
//std::cerr << "cost=" << costFun->val() << std::endl;
//for (size_t i = 0; i < res->nParams(); ++i) {
// std::cerr << "result=" << s.getError() << std::endl;
// std::cerr << "cost=" << costFun->val() << std::endl;
// for (size_t i = 0; i < res->nParams(); ++i) {
// std::cerr << res->parameterName(i) << " = " << res->getParameter(i)
// << std::endl;
//}
......@@ -586,7 +586,6 @@ public: