Skip to content

Commit

Permalink
Re #4158. MantidPlot compiles now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 2, 2012
1 parent aa9b247 commit 985a35b
Show file tree
Hide file tree
Showing 52 changed files with 1,380 additions and 997 deletions.
15 changes: 0 additions & 15 deletions Code/Mantid/Framework/API/inc/MantidAPI/CompositeFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,11 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
std::string descriptionOfActive(size_t i)const;
/// Check if an active parameter i is actually active
bool isActive(size_t i)const;
/// Return the transformation matrix T between parameters such that p_i = T_ij * ap_j,
/// where ap_j is j-th active parameter.
virtual void getTransformationMatrix(Kernel::Matrix<double>& tm);
/// Is the transformation an identity?
virtual bool isTransformationIdentity() const;

/// Return parameter index from a parameter reference.
size_t getParameterIndex(const ParameterReference& ref)const;
/// Get the containing function
IFunction_sptr getContainingFunction(const ParameterReference& ref)const;
/// Get the containing function
//IFunction_sptr getContainingFunction(IFunction_sptr fun);

/// Apply the ties
void applyTies();
Expand Down Expand Up @@ -174,7 +167,6 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
virtual void addTie(ParameterTie* tie);

size_t paramOffset(size_t i)const{return m_paramOffsets[i];}
//size_t activeOffset(size_t i)const{return m_activeOffsets[i];}

private:

Expand All @@ -184,17 +176,10 @@ class MANTID_API_DLL CompositeFunction : public virtual IFunction
/// Pointers to the included funtions
std::vector<IFunction_sptr> m_functions;
/// Individual function parameter offsets (function index in m_functions)
/// e.g. m_functions[i]->activeParameter(m_activeOffsets[i]+1) gives second active parameter of i-th function
//std::vector<size_t> m_activeOffsets;
/// Individual function parameter offsets (function index in m_functions)
/// e.g. m_functions[i]->parameter(m_paramOffsets[i]+1) gives second declared parameter of i-th function
std::vector<size_t> m_paramOffsets;
/// Keeps the function index for each declared parameter (parameter declared index)
std::vector<size_t> m_IFunction;
/// Keeps the function index for each active parameter (parameter active index)
//std::vector<size_t> m_IFunctionActive;
/// Number of active parameters
//size_t m_nActive;
/// Total number of parameters
size_t m_nParams;
/// Function counter to be used in nextConstraint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace API
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL CompositeFunctionMD : public CompositeFunction, public IFunctionMD
class MANTID_API_DLL CompositeFunctionMD : virtual public CompositeFunction, virtual public IFunctionMD
{
public:
/// Default constructor
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/FunctionDomain1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace API
class MANTID_API_DLL FunctionDomain1D: public FunctionDomain
{
public:
FunctionDomain1D(const double x);
FunctionDomain1D(const double startX, const double endX, const size_t n);
FunctionDomain1D(const std::vector<double>& xvalues);
FunctionDomain1D(std::vector<double>::const_iterator from, std::vector<double>::const_iterator to);
Expand Down
1 change: 0 additions & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/FunctionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ namespace API
{
typeNames.push_back(*it);
}
delete func;
}
return typeNames;
}
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/FunctionValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MANTID_API_DLL FunctionValues
void setCalculated(double value);
/// get i-th calculated value. 0 <= i < size()
double getCalculated(size_t i) const {return m_calculated[i];}
double operator[](size_t i) const {return m_calculated[i];}
void addToCalculated(size_t i, double value) {m_calculated[i] += value;}
/// Get a pointer to calculated data at index i
double* getPointerToCalculated(size_t i);
Expand Down
54 changes: 31 additions & 23 deletions Code/Mantid/Framework/API/inc/MantidAPI/IFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "MantidKernel/Matrix.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/Unit.h"

#include <boost/shared_ptr.hpp>
#include <boost/variant.hpp>
#include <string>
Expand All @@ -28,6 +30,7 @@ namespace API
// Forward declaration
//----------------------------------------------------------------------
class Workspace;
class MatrixWorkspace;
class ParameterTie;
class IConstraint;
class ParameterReference;
Expand Down Expand Up @@ -230,8 +233,8 @@ class MANTID_API_DLL IFunction
/// Set the workspace.
/// @param ws :: Shared pointer to a workspace
virtual void setWorkspace(boost::shared_ptr<const Workspace> ws) {}
/// Get the workspace
//virtual boost::shared_ptr<const API::Workspace> getWorkspace()const = 0;
/// Set matrix workspace
void setMatrixWorkspace(boost::shared_ptr<const API::MatrixWorkspace> workspace,size_t wi,double startX, double endX);
/// Iinialize the function
virtual void initialize(){this->init();}

Expand Down Expand Up @@ -290,6 +293,8 @@ class MANTID_API_DLL IFunction

/// Return parameter index from a parameter reference. Usefull for constraints and ties in composite functions
virtual size_t getParameterIndex(const ParameterReference& ref)const = 0;
/// Return a vector with all parameter names
std::vector<std::string> getParameterNames() const ;
//@}

/** @name Active parameters */
Expand All @@ -304,16 +309,13 @@ class MANTID_API_DLL IFunction
virtual std::string descriptionOfActive(size_t i)const;
/// Check if an active parameter i is actually active
virtual bool isActive(size_t i)const {return !isFixed(i);}
/// Return the transformation matrix T between parameters such that p_i = T_ij * ap_j,
/// where ap_j is j-th active parameter.
virtual void getTransformationMatrix(Kernel::Matrix<double>& tm);
/// Is the transformation an identity?
virtual bool isTransformationIdentity() const {return true;}
//@}


/// Tie a parameter to other parameters (or a constant)
virtual ParameterTie* tie(const std::string& parName, const std::string& expr);
/// Add several ties
virtual void addTies(const std::string& ties);
/// Apply the ties
virtual void applyTies() = 0;
/// Removes the tie off a parameter
Expand All @@ -325,16 +327,15 @@ class MANTID_API_DLL IFunction
/// Get the tie of i-th parameter
virtual ParameterTie* getTie(size_t i)const = 0;


/// Add a list of conatraints from a string
virtual void addConstraints(const std::string& str);
/// Add a constraint to function
virtual void addConstraint(IConstraint* ic) = 0;
/// Get constraint of i-th parameter
virtual IConstraint* getConstraint(size_t i)const = 0;
/// Remove a constraint
virtual void removeConstraint(const std::string& parName) = 0;
/// Add a penalty to the output if some parameters do not satisfy constraints.
//virtual void addPenalty(FunctionDomain& domain)const; //?
/// Modify the derivatives to correct for a penalty
//virtual void addPenaltyDeriv(FunctionDomain& domain, Jacobian& jacobian)const;

/// Set the parameters of the function to satisfy the constraints of
/// of the function. For example
Expand Down Expand Up @@ -362,6 +363,9 @@ class MANTID_API_DLL IFunction
template<typename T>
void setAttributeValue(const std::string& attName,const T& value){setAttribute(attName,Attribute(value));}

/// Calculate numerical derivatives
void calNumericalDeriv(const FunctionDomain& domain, Jacobian& out);

/// Set a function handler
void setHandler(FunctionHandler* handler);
/// Return the handler
Expand All @@ -374,11 +378,15 @@ class MANTID_API_DLL IFunction
/// Declare a new parameter
virtual void declareParameter(const std::string& name, double initValue = 0, const std::string& description="") = 0;

/// Calculate numerical derivatives
void calNumericalDeriv(const FunctionDomain& domain, Jacobian& out);
/// Calculate the transformation matrix T by numeric differentiation
void calTransformationMatrixNumerically(Kernel::Matrix<double>& tm);
/// Convert a value from one unit (inUnit) to unit defined in workspace (ws)
double convertValue(double value, Kernel::Unit_sptr& inUnit,
boost::shared_ptr<const MatrixWorkspace> ws,
size_t wsIndex)const;

void convertValue(std::vector<double>& values, Kernel::Unit_sptr& outUnit,
boost::shared_ptr<const MatrixWorkspace> ws,
size_t wsIndex) const;

/// Create an instance of a tie without actually tying it to anything
//virtual ParameterTie* createTie(const std::string& parName);
/// Add a new tie
Expand All @@ -399,6 +407,11 @@ class MANTID_API_DLL IFunction
static Kernel::Logger& g_log;
};

///shared pointer to the function base class
typedef boost::shared_ptr<IFunction> IFunction_sptr;
///shared pointer to the function base class (const version)
typedef boost::shared_ptr<const IFunction> IFunction_const_sptr;

/**
* Classes inherited from FunctionHandler will handle the function.
* The intended purpose is to help with displaying nested composite
Expand All @@ -410,22 +423,17 @@ class FunctionHandler
{
public:
/// Constructor
FunctionHandler(IFunction* fun):m_fun(fun){}
FunctionHandler(IFunction_sptr fun):m_fun(fun){}
/// Virtual destructor
virtual ~FunctionHandler(){}
/// abstract init method. It is called after setting handler to the function
virtual void init() = 0;
/// Return the handled function
const IFunction* function()const{return m_fun;}
IFunction_sptr function()const{return m_fun;}
protected:
IFunction* m_fun;///< pointer to the handled function
IFunction_sptr m_fun;///< pointer to the handled function
};

///shared pointer to the function base class
typedef boost::shared_ptr<IFunction> IFunction_sptr;
///shared pointer to the function base class (const version)
typedef boost::shared_ptr<const IFunction> IFunction_const_sptr;

} // namespace API
} // namespace Mantid

Expand Down
9 changes: 0 additions & 9 deletions Code/Mantid/Framework/API/inc/MantidAPI/IFunctionMW.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ class MANTID_API_DLL IFunctionMW: public virtual IFunction
size_t getWorkspaceIndex() const {return m_workspaceIndex;}
protected:

/// Convert a value from one unit (inUnit) to unit defined in workspace (ws)
double convertValue(double value, Kernel::Unit_sptr& inUnit,
boost::shared_ptr<const MatrixWorkspace> ws,
size_t wsIndex)const;

void convertValue(std::vector<double>& values, Kernel::Unit_sptr& outUnit,
boost::shared_ptr<const MatrixWorkspace> ws,
size_t wsIndex) const;

boost::weak_ptr<const API::MatrixWorkspace> m_workspace;

size_t m_workspaceIndex;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/ParameterTie.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace API
{
public:
/// Constructor
ParameterTie(IFunction* funct,const std::string& parName,const std::string& expr);
ParameterTie(IFunction* funct,const std::string& parName,const std::string& expr = "");
/// Destructor
virtual ~ParameterTie();
/// Set the tie expression
Expand Down
65 changes: 0 additions & 65 deletions Code/Mantid/Framework/API/src/CompositeFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,71 +839,6 @@ IFunction_sptr CompositeFunction::getContainingFunction(const ParameterReference
return IFunction_sptr();
}

///**
// * @param fun :: The searched function
// * @return A function containing the argument function fun
// */
//IFunction_sptr CompositeFunction::getContainingFunction(IFunction_sptr fun)
//{
// if (fun.get() == this)
// {
// return fun;
// }
// for(size_t iFun=0;iFun<nFunctions();iFun++)
// {
// IFunction_sptr f = getFunction(iFun);
// if (f == fun)
// {
// return getFunction(iFun);
// }
// }
// return IFunction_sptr();
//}

/// Is the transformation an identity?
bool CompositeFunction::isTransformationIdentity() const
{
for(size_t iFun = 0; iFun < nFunctions(); ++iFun)
{
if ( !getFunction(iFun)->isTransformationIdentity() )
{
return false;
}
}
return true;
}

/**
* Return the transformation matrix T between parameters such that p_i = T_ij * ap_j,
* where ap_j is j-th active parameter.
* @param tm :: The output matrix
*/
void CompositeFunction::getTransformationMatrix(Kernel::Matrix<double>& tm)
{
size_t np = nParams();
tm.setMem(np, np);
tm.identityMatrix();
if ( this->isTransformationIdentity() ) return;
for(size_t iFun = 0; iFun < nFunctions(); ++iFun)
{
IFunction_sptr f = getFunction(iFun);
if ( !f->isTransformationIdentity() )
{
size_t i0 = m_paramOffsets[iFun];
size_t np1 = f->nParams();
Kernel::Matrix<double> tm1(np1,np1);
f->getTransformationMatrix(tm1);
for(size_t i = 0; i < np1; ++i)
{
for(size_t j = 0; j < np1; ++j)
{
tm[i0 + i][i0 + j] = tm1[i][j];
}
}
} // !identity
}
}


} // namespace API
} // namespace Mantid
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/API/src/FunctionDomain1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@ FunctionDomain1D::FunctionDomain1D(const double startX, const double endX, const
}
}

FunctionDomain1D::FunctionDomain1D(const double x)
{
m_X.resize(1);
m_X[0] = x;
}

} // namespace API
} // namespace Mantid

0 comments on commit 985a35b

Please sign in to comment.