Skip to content

Commit

Permalink
Refactor codes. Refs #7653.
Browse files Browse the repository at this point in the history
Moved some methods belonged to ThermalNeutronBk2BkExpConvPVoigt to
IPowderDiffPeakFunction because they are used by
NeutronBk2BkExpConvPVoigt, too.
  • Loading branch information
wdzhou committed Aug 8, 2013
1 parent 9837841 commit b3f4eab
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class MANTID_API_DLL IPowderDiffPeakFunction : public virtual API::ParamFunction

//--------------- ThermalNeutron peak function special ---------------------------------------
/// Set Miller Indicies
virtual void setMillerIndex(int h, int k, int l) = 0;
virtual void setMillerIndex(int h, int k, int l);

/// Get Miller Index from this peak
virtual void getMillerIndex(int& h, int &k, int &l) = 0;
virtual void getMillerIndex(int& h, int &k, int &l);

/// Get peak parameters
virtual double getPeakParameter(std::string) = 0;
Expand Down Expand Up @@ -100,7 +100,6 @@ class MANTID_API_DLL IPowderDiffPeakFunction : public virtual API::ParamFunction

/// Calculate function in a range
using IFunction1D::function;

virtual void function(std::vector<double>& out, const std::vector<double>& xValues) const = 0;

/// Get maximum value on a given set of data points
Expand Down
48 changes: 48 additions & 0 deletions Code/Mantid/Framework/API/src/IPowderDiffPeakFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,54 @@ namespace API
return max;
}

//----------------------------------------------------------------------------------------------
/** Set Miller Indices for this peak
*/
void IPowderDiffPeakFunction::setMillerIndex(int h, int k, int l)
{
// Check validity and set flag
if (mHKLSet)
{
// Throw exception if tried to reset the miller index
stringstream errss;
errss << "ThermalNeutronBk2BkExpConvPVoigt Peak cannot have (HKL) reset.";
g_log.error(errss.str());
throw runtime_error(errss.str());
}
else
{
// Set flag
mHKLSet = true;
}

// Set value
mH = static_cast<int>(h);
mK = static_cast<int>(k);
mL = static_cast<int>(l);

// Check value valid or not
if (mH*mH + mK*mK + mL*mL < 1.0E-8)
{
stringstream errmsg;
errmsg << "H = K = L = 0 is not allowed";
g_log.error(errmsg.str());
throw std::invalid_argument(errmsg.str());
}

return;
}

//----------------------------------------------------------------------------------------------
/** Get Miller Index from this peak
*/
void IPowderDiffPeakFunction::getMillerIndex(int& h, int &k, int &l)
{
h = static_cast<int>(mH);
k = static_cast<int>(mK);
l = static_cast<int>(mL);

return;
}

//----------------------------------------------------------------------------------------------
/** General implementation of the method for all peaks. Limits the peak evaluation to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,16 @@ namespace CurveFitting

//--------------- ThermalNeutron peak function special ---------------------------------------
/// Set Miller Indicies
virtual void setMillerIndex(int h, int k, int l);
// virtual void setMillerIndex(int h, int k, int l);

/// Get Miller Index from this peak
virtual void getMillerIndex(int& h, int &k, int &l);
// virtual void getMillerIndex(int& h, int &k, int &l);

/// Get peak parameters
virtual double getPeakParameter(std::string);

/// Calculate peak parameters (alpha, beta, sigma2..)
void calculateParameters(bool explicitoutput) const;
// double& dh, double& tof_h, double& eta, double& alpha, double& beta, double &H, double& sigma2,
// double &gamma, double &N,
virtual void calculateParameters(bool explicitoutput) const;

/// Core function to calcualte peak values for whole region
// void functionLocal(vector<double>& out, const vector<double> &xValues) const;
Expand All @@ -85,10 +83,10 @@ namespace CurveFitting
*/

/// Override setting a new value to the i-th parameter
void setParameter(size_t i, const double& value, bool explicitlySet=true);
virtual void setParameter(size_t i, const double& value, bool explicitlySet=true);

/// Override setting a new value to a parameter by name
void setParameter(const std::string& name, const double& value, bool explicitlySe=true);
virtual void setParameter(const std::string& name, const double& value, bool explicitlySe=true);

/// Set peak's height
virtual void setHeight(const double h);
Expand Down Expand Up @@ -187,7 +185,7 @@ inline double calCubicDSpace(double a, int h, int k, int l)
*/

/// Integral for Gamma
std::complex<double> E1(std::complex<double> z);
std::complex<double> E1X(std::complex<double> z);

} // namespace CurveFitting
} // namespace Mantid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ namespace CurveFitting

//----------------------------------------------------------------------------------------------
/** Set Miller Indices for this peak
*/
void ThermalNeutronBk2BkExpConvPVoigt::setMillerIndex(int h, int k, int l)
{
// Check validity and set flag
Expand Down Expand Up @@ -244,10 +243,10 @@ namespace CurveFitting
return;
}
*/

//----------------------------------------------------------------------------------------------
/** Get Miller Index from this peak
*/
void ThermalNeutronBk2BkExpConvPVoigt::getMillerIndex(int& h, int &k, int &l)
{
h = static_cast<int>(mH);
Expand All @@ -256,8 +255,9 @@ namespace CurveFitting
return;
}
*/

//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
/** Get peak parameters stored locally
* Get some internal parameters values including
* (a) Alpha, (b) Beta, (c) Gamma, (d) Sigma2
Expand Down Expand Up @@ -644,8 +644,8 @@ namespace CurveFitting
const double SQRT_H_5 = sqrt(H)*.5;
std::complex<double> p(alpha*x, alpha*SQRT_H_5);
std::complex<double> q(-beta*x, beta*SQRT_H_5);
double omega2a = imag(exp(p)*E1(p));
double omega2b = imag(exp(q)*E1(q));
double omega2a = imag(exp(p)*E1X(p));
double omega2b = imag(exp(q)*E1X(q));
omega2 = -1.0*N*eta*(omega2a + omega2b)*TWO_OVER_PI;
}
const double omega = omega1+omega2;
Expand Down Expand Up @@ -737,7 +737,7 @@ namespace CurveFitting
//------------------------- External Functions ---------------------------------------------------
/** Implementation of complex integral E_1
*/
std::complex<double> E1(std::complex<double> z)
std::complex<double> E1X(std::complex<double> z)
{
const double el = 0.5772156649015328;

Expand Down

0 comments on commit b3f4eab

Please sign in to comment.