Skip to content

Commit

Permalink
Refs #11551. Adding default constraints to PawleyParameterFunction
Browse files Browse the repository at this point in the history
Adding meaningful default constraints to cell parameters.
  • Loading branch information
Michael Wedel committed Apr 17, 2015
1 parent 26468df commit 6118d55
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Expand Up @@ -62,6 +62,10 @@ class DLLExport PawleyParameterFunction : virtual public API::IFunction,

void createCrystalSystemParameters(
Geometry::PointGroup::CrystalSystem crystalSystem);

void addLengthConstraint(const std::string &parameterName);
void addAngleConstraint(const std::string &parameterName);

void setCenterParameterNameFromFunction(
const API::IPeakFunction_sptr &profileFunction);

Expand Down
43 changes: 42 additions & 1 deletion Code/Mantid/Framework/CurveFitting/src/PawleyFunction.cpp
@@ -1,6 +1,9 @@
#include "MantidCurveFitting/PawleyFunction.h"

#include "MantidAPI/FunctionFactory.h"

#include "MantidCurveFitting/BoundaryConstraint.h"

#include "MantidKernel/UnitConversion.h"
#include "MantidKernel/UnitFactory.h"

Expand Down Expand Up @@ -173,7 +176,8 @@ void PawleyParameterFunction::setProfileFunction(
* This method takes the name of a crystal system (case insensitive) and stores
* it. Furthermore it creates the necessary parameters, which means that after
* calling this function, PawleyParameterFunction potentially exposes a
* different number of parameters.
* different number of parameters. The parameters are constrained to physically
* meaningful values (angles between 0 and 180 degrees, cell edges above 0).
*
* @param crystalSystem :: Crystal system, case insensitive.
*/
Expand Down Expand Up @@ -212,47 +216,84 @@ void PawleyParameterFunction::createCrystalSystemParameters(
switch (crystalSystem) {
case PointGroup::Cubic:
declareParameter("a", 1.0);
addLengthConstraint("a");
break;

case PointGroup::Hexagonal:
case PointGroup::Tetragonal:
declareParameter("a", 1.0);
declareParameter("c", 1.0);
addLengthConstraint("a");
addLengthConstraint("c");
break;

case PointGroup::Orthorhombic:
declareParameter("a", 1.0);
declareParameter("b", 1.0);
declareParameter("c", 1.0);
addLengthConstraint("a");
addLengthConstraint("b");
addLengthConstraint("c");
break;

case PointGroup::Monoclinic:
declareParameter("a", 1.0);
declareParameter("b", 1.0);
declareParameter("c", 1.0);
addLengthConstraint("a");
addLengthConstraint("b");
addLengthConstraint("c");

declareParameter("Beta", 90.0);
addAngleConstraint("Beta");
break;

case PointGroup::Trigonal:
declareParameter("a", 1.0);
declareParameter("Alpha", 90.0);
addLengthConstraint("a");
addAngleConstraint("Alpha");
break;

default:
// triclinic
declareParameter("a", 1.0);
declareParameter("b", 1.0);
declareParameter("c", 1.0);
addLengthConstraint("a");
addLengthConstraint("b");
addLengthConstraint("c");

declareParameter("Alpha", 90.0);
declareParameter("Beta", 90.0);
declareParameter("Gamma", 90.0);
addAngleConstraint("Alpha");
addAngleConstraint("Beta");
addAngleConstraint("Gamma");
break;
}

declareParameter("ZeroShift", 0.0);
}

/// Adds a default constraint so that cell edge lengths can not be less than 0.
void
PawleyParameterFunction::addLengthConstraint(const std::string &parameterName) {
BoundaryConstraint *cellEdgeConstraint =
new BoundaryConstraint(this, parameterName, 0.0, true);
cellEdgeConstraint->setPenaltyFactor(1e12);
addConstraint(cellEdgeConstraint);
}

/// Adds a default constraint so cell angles are in the range 0 to 180.
void
PawleyParameterFunction::addAngleConstraint(const std::string &parameterName) {
BoundaryConstraint *cellAngleConstraint =
new BoundaryConstraint(this, parameterName, 0.0, 180.0, true);
cellAngleConstraint->setPenaltyFactor(1e12);
addConstraint(cellAngleConstraint);
}

/// Tries to extract and store the center parameter name from the function.
void PawleyParameterFunction::setCenterParameterNameFromFunction(
const IPeakFunction_sptr &profileFunction) {
Expand Down

0 comments on commit 6118d55

Please sign in to comment.