Mantid
Loading...
Searching...
No Matches
LatticeFunction.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
10
11namespace Mantid::CurveFitting {
12
13using namespace API;
14using namespace Geometry;
15
16DECLARE_FUNCTION(LatticeFunction)
17
19
21void LatticeFunction::functionLattice(const LatticeDomain &latticeDomain, FunctionValues &values) const {
23
24 UnitCell cell = m_cellParameters->getUnitCellFromParameters();
25 double zeroShift = m_cellParameters->getParameter("ZeroShift");
26
27 for (size_t i = 0; i < values.size(); ++i) {
28 values.setCalculated(i, cell.d(latticeDomain[i]) + zeroShift);
29 }
30}
31
34void LatticeFunction::setLatticeSystem(const std::string &crystalSystem) {
36
37 m_cellParameters->setAttributeValue("LatticeSystem", crystalSystem);
38}
39
42void LatticeFunction::setUnitCell(const std::string &unitCellString) {
44
45 m_cellParameters->setParametersFromUnitCell(strToUnitCell(unitCellString));
46}
47
51
52 m_cellParameters->setParametersFromUnitCell(unitCell);
53}
54
58
59 return m_cellParameters->getUnitCellFromParameters();
60}
61
63void LatticeFunction::init() { setDecoratedFunction("PawleyParameterFunction"); }
64
67 Functions::PawleyParameterFunction_sptr paramFn = std::dynamic_pointer_cast<Functions::PawleyParameterFunction>(fn);
68
69 if (!paramFn) {
70 throw std::invalid_argument("LatticeFunction can only decorate a PawleyParameterFunction.");
71 }
72
73 m_cellParameters = paramFn;
74}
75
76} // namespace Mantid::CurveFitting
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
void setDecoratedFunction(const std::string &wrappedFunctionName)
void throwIfNoFunctionSet() const
Throws std::runtime_error when m_wrappedFunction is not set.
A class to store values calculated by a function.
size_t size() const
Return the number of values.
void setCalculated(double value)
set all calculated values to same number
void setLatticeSystem(const std::string &crystalSystem) override
Assigns the crystal system to the internally stored function.
Geometry::UnitCell getUnitCell() const override
Returns a UnitCell object constructed from the function parameters.
void beforeDecoratedFunctionSet(const API::IFunction_sptr &fn) override
Checks that the decorated function is a PawleyParameterFunction.
Functions::PawleyParameterFunction_sptr m_cellParameters
void functionLattice(const API::LatticeDomain &latticeDomain, API::FunctionValues &values) const override
Calculates d-values using the internally stored cell parameters.
void setUnitCell(const std::string &unitCellString) override
Sets the unit cell parameters from a string that can be parsed by Geometry::strToUnitCell.
void init() override
Sets the decorated function to expose parameters.
Class to implement unit cell of crystals.
Definition: UnitCell.h:44
double d(double h, double k, double l) const
Return d-spacing ( ) for a given h,k,l coordinate.
Definition: UnitCell.cpp:700
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
std::shared_ptr< PawleyParameterFunction > PawleyParameterFunction_sptr
MANTID_GEOMETRY_DLL UnitCell strToUnitCell(const std::string &unitCellString)
Definition: UnitCell.cpp:896