Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'origin/feature/8060_MullerAnsatz'
  • Loading branch information
Michael Reuter committed May 6, 2014
2 parents 989e042 + 3c2554d commit 9d76192
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 46 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Expand Up @@ -53,6 +53,7 @@ set ( SRC_FILES
src/Quantification/MDResolutionConvolutionFactory.cpp
src/Quantification/Models/QCoordinate.cpp
src/Quantification/Models/Strontium122.cpp
src/Quantification/Models/MullerAnsatz.cpp
src/Quantification/Resolution/ModeratorChopperResolution.cpp
src/Quantification/Resolution/TobyFitBMatrix.cpp
src/Quantification/Resolution/TobyFitResolutionModel.cpp
Expand Down Expand Up @@ -130,6 +131,7 @@ set ( INC_FILES
inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h
inc/MantidMDAlgorithms/Quantification/Models/QCoordinate.h
inc/MantidMDAlgorithms/Quantification/Models/Strontium122.h
inc/MantidMDAlgorithms/Quantification/Models/MullerAnsatz.h
inc/MantidMDAlgorithms/Quantification/Resolution/ModeratorChopperResolution.h
inc/MantidMDAlgorithms/Quantification/Resolution/TobyFitBMatrix.h
inc/MantidMDAlgorithms/Quantification/Resolution/TobyFitResolutionModel.h
Expand Down Expand Up @@ -197,6 +199,7 @@ set ( TEST_FILES
MinusMDTest.h
ModeratorChopperResolutionTest.h
MultiplyMDTest.h
MullerAnsatzTest.h
NotMDTest.h
OrMDTest.h
PlusMDTest.h
Expand Down
Expand Up @@ -97,6 +97,9 @@ namespace Mantid
/// Returns the form factor for the given q^2 value
double formFactor(const double qsqr) const;

/// helper function used for fast conversion from qx,qy,qz coordinate system into hkl coordinate system
static void convertToHKL(const API::ExperimentInfo & exptSetup,const double &qx,const double &qy, const double &qz,
double &qh,double &qk,double &ql,double &arlu1,double &arlu2,double &arlu3);
private:
DISABLE_COPY_AND_ASSIGN(ForegroundModel);

Expand All @@ -113,6 +116,8 @@ namespace Mantid
/// An offset for the number of parameters that were declared before this one
size_t m_parOffset;

/// the name of magnetic ion used to avoid resetting form factor table for the same ion
std::string m_MagIonName;
/// Owned pointer to magnetic form factor cache
PhysicalConstants::MagneticFormFactorTable *m_formFactorTable;
};
Expand All @@ -122,6 +127,7 @@ namespace Mantid
/// boost::shared_ptr to const typedef
typedef boost::shared_ptr<const ForegroundModel> ForegroundModel_const_sptr;


}
}

Expand Down
@@ -0,0 +1,75 @@
#ifndef MANTID_MDALGORITHMS_MULLERANSATZ_H_
#define MANTID_MDALGORITHMS_MULLERANSATZ_H_
/**
Copyright &copy; 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
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>
*/
#include "MantidMDAlgorithms/Quantification/ForegroundModel.h"

namespace Mantid
{
namespace MDAlgorithms
{

/**
* Defines the Muller Ansatz model of Ewings et al.
* This is model 300 in TobyFit.
*/
class DLLExport MullerAnsatz : public ForegroundModel
{
public:
/// possible scattering chain directions
enum ChainDirection
{
Along_a,
Along_b,
Along_c
};
/// possible magnetic form factor directions
enum MagneticFFDirection
{
NormalTo_a,
NormalTo_b,
NormalTo_c,
Isotropic
};

/// Calculates the intensity for the model for the current parameters.
double scatteringIntensity(const API::ExperimentInfo & exptDescr, const std::vector<double> & point) const;
/// Called when an attribute is set
void setAttribute(const std::string & name, const API::IFunction::Attribute& attr);
/// Returns the type of model
ModelType modelType() const { return Broad; }
/// String name of the model
std::string name() const { return "MullerAnsatz"; }
MullerAnsatz();
private:
/// Setup the model
void init();
// direction of the magnetic chain wrt the lattice vectors
ChainDirection m_ChainDirection;
// direction of the magnetic form factor wrt the lattice vectors.
MagneticFFDirection m_FFDirection;

};

}
}
#endif /* MANTID_MDALGORITHMS_STRONTIUM122_H_ */
Expand Up @@ -52,6 +52,8 @@ namespace Mantid
int m_twinType;
/// MultEps attribute
bool m_multEps;
public:
Strontium122();
};

}
Expand Down
Expand Up @@ -22,6 +22,7 @@ namespace Mantid
*/
ForegroundModel::ForegroundModel()
: API::ParamFunction(), m_fittingFunction(NULL), m_parOffset(0),
m_MagIonName(""),
m_formFactorTable(NULL)
{
addAttributes();
Expand Down Expand Up @@ -146,7 +147,15 @@ namespace Mantid
else
{
using namespace PhysicalConstants;
m_formFactorTable = new MagneticFormFactorTable(FORM_FACTOR_TABLE_LENGTH, getMagneticIon(ionType));
if(m_MagIonName != ionType)
{
if (m_formFactorTable)
{
delete m_formFactorTable;
}
m_formFactorTable = new MagneticFormFactorTable(FORM_FACTOR_TABLE_LENGTH, getMagneticIon(ionType));
m_MagIonName = ionType;
}
}
}

Expand Down Expand Up @@ -174,5 +183,59 @@ namespace Mantid
declareAttribute(FORM_FACTOR_ION, API::IFunction::Attribute("0"));
}

const double TWO_PI = 2.*M_PI;
void ForegroundModel::convertToHKL(const API::ExperimentInfo & exptSetup, const double &qx,const double &qy, const double &qz,
double &qh,double &qk,double &ql,double &arlu1,double &arlu2,double &arlu3)
{
// Transform the HKL only requires B matrix & goniometer (R) as ConvertToMD should have already
// handled addition of U matrix
// qhkl = (1/2pi)(RB)^-1(qxyz)
const Geometry::OrientedLattice & lattice = exptSetup.sample().getOrientedLattice();
const Kernel::DblMatrix & gr = exptSetup.run().getGoniometerMatrix();
const Kernel::DblMatrix & bmat = lattice.getB();

// Avoid doing inversion with Matrix class as it forces memory allocations
// M^-1 = (1/|M|)*M^T
double rb00(0.0), rb01(0.0), rb02(0.0),
rb10(0.0), rb11(0.0), rb12(0.0),
rb20(0.0), rb21(0.0), rb22(0.0);
for(unsigned int i = 0; i < 3; ++i)
{
rb00 += gr[0][i]*bmat[i][0];
rb01 += gr[0][i]*bmat[i][1];
rb02 += gr[0][i]*bmat[i][2];

rb10 += gr[1][i]*bmat[i][0];
rb11 += gr[1][i]*bmat[i][1];
rb12 += gr[1][i]*bmat[i][2];

rb20 += gr[2][i]*bmat[i][0];
rb21 += gr[2][i]*bmat[i][1];
rb22 += gr[2][i]*bmat[i][2];
}
// 2pi*determinant. The tobyFit definition of rl vector has extra 2pi factor in it
const double twoPiDet= TWO_PI*(rb00*(rb11*rb22 - rb12*rb21) -
rb01*(rb10*rb22 - rb12*rb20) +
rb02*(rb10*rb21 - rb11*rb20));

qh = ((rb11*rb22 - rb12*rb21)*qx + (rb02*rb21 - rb01*rb22)*qy + (rb01*rb12 - rb02*rb11)*qz)/twoPiDet;
qk = ((rb12*rb20 - rb10*rb22)*qx + (rb00*rb22 - rb02*rb20)*qy + (rb02*rb10 - rb00*rb12)*qz)/twoPiDet;
ql = ((rb10*rb21 - rb11*rb20)*qx + (rb01*rb20 - rb00*rb21)*qy + (rb00*rb11 - rb01*rb10)*qz)/twoPiDet;

// Lattice parameters
double ca1 = std::cos(lattice.beta1());
double ca2 = std::cos(lattice.beta2());
double ca3 = std::cos(lattice.beta3());
double sa1 = std::abs(std::sin(lattice.beta1()));
double sa2 = std::abs(std::sin(lattice.beta2()));
double sa3 = std::abs(std::sin(lattice.beta3()));

const double factor = std::sqrt(1.0 + 2.0*(ca1*ca2*ca3) - (ca1*ca1 + ca2*ca2 + ca3*ca3));
arlu1 = (TWO_PI/lattice.a())*(sa1/factor); // Lattice parameters in r.l.u
arlu2 = (TWO_PI/lattice.b())*(sa2/factor);
arlu3 = (TWO_PI/lattice.c())*(sa3/factor);


}
}
}

0 comments on commit 9d76192

Please sign in to comment.