Skip to content
Snippets Groups Projects
Commit 4e79d47e authored by Michael Wedel's avatar Michael Wedel
Browse files

Refs #11043. Added PawleyFunction skeleton

parent 40e5686e
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,7 @@ set ( SRC_FILES
src/NormaliseByPeakArea.cpp
src/PRConjugateGradientMinimizer.cpp
src/ParDomain.cpp
src/PawleyFunction.cpp
src/PeakParameterFunction.cpp
src/PlotPeakByLogValue.cpp
src/Polynomial.cpp
......@@ -179,6 +180,7 @@ set ( INC_FILES
inc/MantidCurveFitting/NormaliseByPeakArea.h
inc/MantidCurveFitting/PRConjugateGradientMinimizer.h
inc/MantidCurveFitting/ParDomain.h
inc/MantidCurveFitting/PawleyFunction.h
inc/MantidCurveFitting/PeakParameterFunction.h
inc/MantidCurveFitting/PlotPeakByLogValue.h
inc/MantidCurveFitting/Polynomial.h
......@@ -257,14 +259,14 @@ set ( TEST_FILES
FullprofPolynomialTest.h
FunctionDomain1DSpectrumCreatorTest.h
FunctionFactoryConstraintTest.h
FunctionParameterDecoratorFitTest.h
FunctionParameterDecoratorFitTest.h
GSLMatrixTest.h
GausDecayTest.h
GausOscTest.h
GaussianComptonProfileTest.h
GaussianTest.h
GramCharlierComptonProfileTest.h
IPeakFunctionCentreParameterNameTest.h
IPeakFunctionCentreParameterNameTest.h
IPeakFunctionIntensityTest.h
IkedaCarpenterPVTest.h
LeBailFitTest.h
......@@ -282,6 +284,7 @@ set ( TEST_FILES
NeutronBk2BkExpConvPVoigtTest.h
NormaliseByPeakAreaTest.h
PRConjugateGradientTest.h
PawleyFunctionTest.h
PeakParameterFunctionTest.h
PlotPeakByLogValueTest.h
PolynomialTest.h
......
#ifndef MANTID_CURVEFITTING_PAWLEYFUNCTION_H_
#define MANTID_CURVEFITTING_PAWLEYFUNCTION_H_
#include "MantidKernel/System.h"
#include "MantidAPI/IFunction1D.h"
#include "MantidAPI/ParamFunction.h"
#include "MantidGeometry/Crystal/PointGroup.h"
#include "MantidGeometry/Crystal/UnitCell.h"
namespace Mantid {
namespace CurveFitting {
/** PawleyFunction
The Pawley approach to obtain lattice parameters from a powder diffractogram
works by placing peak profiles at d-values (which result from the lattice
parameters and the Miller indices of each peak) and fitting the total profile
to the recorded diffractogram.
Depending on the chosen crystal system, this function exposes the appropriate
lattice parameters as parameters, as well as profile parameters of the
individual peak functions, except the peak locations, which are a direct
result of their HKLs in combination with the unit cell.
@author Michael Wedel, Paul Scherrer Institut - SINQ
@date 11/03/2015
Copyright © 2015 PSI-NXMM
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PawleyFunction : public API::IFunction1D,
public API::ParamFunction {
public:
PawleyFunction();
virtual ~PawleyFunction() {}
std::string name() const { return "PawleyFunction"; }
void setAttribute(const std::string &attName, const Attribute &attValue);
Geometry::PointGroup::CrystalSystem getCrystalSystem() const;
void function1D(double *out, const double *xValues, const size_t nData) const;
void functionDeriv1D(API::Jacobian *out, const double *xValues,
const size_t nData);
void functionDeriv(const API::FunctionDomain &domain,
API::Jacobian &jacobian);
protected:
void init();
void setCrystalSystem(const std::string &crystalSystem);
Geometry::PointGroup::CrystalSystem m_crystalSystem;
Geometry::UnitCell m_unitCell;
};
} // namespace CurveFitting
} // namespace Mantid
#endif /* MANTID_CURVEFITTING_PAWLEYFUNCTION_H_ */
#include "MantidCurveFitting/PawleyFunction.h"
#include <boost/algorithm/string.hpp>
namespace Mantid {
namespace CurveFitting {
using namespace API;
using namespace Geometry;
PawleyFunction::PawleyFunction()
: ParamFunction(), m_crystalSystem(PointGroup::Triclinic), m_unitCell() {}
void PawleyFunction::setAttribute(const std::string &attName,
const Attribute &attValue) {
if (attName == "CrystalSystem") {
setCrystalSystem(attValue.asString());
}
ParamFunction::setAttribute(attName, attValue);
}
PointGroup::CrystalSystem PawleyFunction::getCrystalSystem() const {
return m_crystalSystem;
}
void PawleyFunction::function1D(double *out, const double *xValues,
const size_t nData) const {
UNUSED_ARG(out);
UNUSED_ARG(xValues);
UNUSED_ARG(nData);
}
void PawleyFunction::functionDeriv1D(Jacobian *out, const double *xValues,
const size_t nData) {
UNUSED_ARG(out);
UNUSED_ARG(xValues);
UNUSED_ARG(nData);
}
void PawleyFunction::functionDeriv(const FunctionDomain &domain,
Jacobian &jacobian) {
calNumericalDeriv(domain, jacobian);
}
void PawleyFunction::init() {
declareAttribute("CrystalSystem", IFunction::Attribute("Triclinic"));
}
void PawleyFunction::setCrystalSystem(const std::string &crystalSystem) {
std::string crystalSystemLC = boost::algorithm::to_lower_copy(crystalSystem);
if (crystalSystemLC == "cubic") {
m_crystalSystem = PointGroup::Cubic;
} else if (crystalSystemLC == "tetragonal") {
m_crystalSystem = PointGroup::Tetragonal;
} else if (crystalSystemLC == "hexagonal") {
m_crystalSystem = PointGroup::Hexagonal;
} else if (crystalSystemLC == "trigonal") {
m_crystalSystem = PointGroup::Trigonal;
} else if (crystalSystemLC == "orthorhombic") {
m_crystalSystem = PointGroup::Orthorhombic;
} else if (crystalSystemLC == "monoclinic") {
m_crystalSystem = PointGroup::Monoclinic;
} else if (crystalSystemLC == "triclinic") {
m_crystalSystem = PointGroup::Triclinic;
} else {
throw std::invalid_argument("Not a valid crystal system: '" +
crystalSystem + "'.");
}
}
} // namespace CurveFitting
} // namespace Mantid
#ifndef MANTID_CURVEFITTING_PAWLEYFUNCTIONTEST_H_
#define MANTID_CURVEFITTING_PAWLEYFUNCTIONTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidCurveFitting/PawleyFunction.h"
#include "MantidGeometry/Crystal/PointGroup.h"
using Mantid::CurveFitting::PawleyFunction;
using namespace Mantid::API;
using namespace Mantid::Geometry;
class PawleyFunctionTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static PawleyFunctionTest *createSuite() { return new PawleyFunctionTest(); }
static void destroySuite(PawleyFunctionTest *suite) { delete suite; }
void testCrystalSystem() {
PawleyFunction fn;
fn.initialize();
TS_ASSERT(fn.hasAttribute("CrystalSystem"));
// Cubic, check case insensitivity
TS_ASSERT_THROWS_NOTHING(fn.setAttributeValue("CrystalSystem", "cubic"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Cubic);
TS_ASSERT_THROWS_NOTHING(fn.setAttributeValue("CrystalSystem", "Cubic"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Cubic);
TS_ASSERT_THROWS_NOTHING(fn.setAttributeValue("CrystalSystem", "CUBIC"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Cubic);
// Tetragonal
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "tetragonal"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Tetragonal);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "Tetragonal"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Tetragonal);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "TETRAGONAL"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Tetragonal);
// Hexagonal
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "hexagonal"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Hexagonal);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "Hexagonal"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Hexagonal);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "HEXAGONAL"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Hexagonal);
// Orthorhombic
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "orthorhombic"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Orthorhombic);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "Orthorhombic"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Orthorhombic);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "ORTHORHOMBIC"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Orthorhombic);
// Monoclinic
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "monoclinic"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Monoclinic);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "Monoclinic"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Monoclinic);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "MONOCLINIC"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Monoclinic);
// Triclinic
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "triclinic"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Triclinic);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "Triclinic"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Triclinic);
TS_ASSERT_THROWS_NOTHING(
fn.setAttributeValue("CrystalSystem", "TRICLINIC"));
TS_ASSERT_EQUALS(fn.getCrystalSystem(), PointGroup::Triclinic);
// invalid string
TS_ASSERT_THROWS(fn.setAttributeValue("CrystalSystem", "invalid"),
std::invalid_argument);
}
};
#endif /* MANTID_CURVEFITTING_PAWLEYFUNCTIONTEST_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment