Skip to content

Commit

Permalink
Merge branch 'feature/10282_create_scattering_function' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Nov 4, 2014
2 parents 64f7d37 + b4a8c56 commit 839270e
Show file tree
Hide file tree
Showing 20 changed files with 965 additions and 715 deletions.
27 changes: 15 additions & 12 deletions Code/Mantid/Framework/Geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
set ( SRC_FILES
src/ComponentParser.cpp
src/Crystal/BraggScatterer.cpp
src/Crystal/BraggScattererFactory.cpp
src/Crystal/BraggScattererInCrystalStructure.cpp
src/Crystal/CenteringGroup.cpp
src/Crystal/CompositeScatterer.cpp
src/Crystal/CompositeBraggScatterer.cpp
src/Crystal/ConventionalCell.cpp
src/Crystal/CrystalStructure.cpp
src/Crystal/CyclicGroup.cpp
src/Crystal/Group.cpp
src/Crystal/IScatterer.cpp
src/Crystal/IndexingUtils.cpp
src/Crystal/IsotropicAtomScatterer.cpp
src/Crystal/IsotropicAtomBraggScatterer.cpp
src/Crystal/NiggliCell.cpp
src/Crystal/OrientedLattice.cpp
src/Crystal/PointGroup.cpp
Expand All @@ -17,7 +19,6 @@ set ( SRC_FILES
src/Crystal/ReducedCell.cpp
src/Crystal/ReflectionCondition.cpp
src/Crystal/ScalarUtils.cpp
src/Crystal/ScattererFactory.cpp
src/Crystal/SpaceGroup.cpp
src/Crystal/SpaceGroupFactory.cpp
src/Crystal/SymmetryOperation.cpp
Expand Down Expand Up @@ -115,15 +116,17 @@ set ( SRC_UNITY_IGNORE_FILES src/Instrument/CompAssembly.cpp

set ( INC_FILES
inc/MantidGeometry/ComponentParser.h
inc/MantidGeometry/Crystal/BraggScatterer.h
inc/MantidGeometry/Crystal/BraggScattererFactory.h
inc/MantidGeometry/Crystal/BraggScattererInCrystalStructure.h
inc/MantidGeometry/Crystal/CenteringGroup.h
inc/MantidGeometry/Crystal/CompositeScatterer.h
inc/MantidGeometry/Crystal/CompositeBraggScatterer.h
inc/MantidGeometry/Crystal/ConventionalCell.h
inc/MantidGeometry/Crystal/CrystalStructure.h
inc/MantidGeometry/Crystal/CyclicGroup.h
inc/MantidGeometry/Crystal/Group.h
inc/MantidGeometry/Crystal/IScatterer.h
inc/MantidGeometry/Crystal/IndexingUtils.h
inc/MantidGeometry/Crystal/IsotropicAtomScatterer.h
inc/MantidGeometry/Crystal/IsotropicAtomBraggScatterer.h
inc/MantidGeometry/Crystal/NiggliCell.h
inc/MantidGeometry/Crystal/OrientedLattice.h
inc/MantidGeometry/Crystal/PointGroup.h
Expand All @@ -132,7 +135,6 @@ set ( INC_FILES
inc/MantidGeometry/Crystal/ReducedCell.h
inc/MantidGeometry/Crystal/ReflectionCondition.h
inc/MantidGeometry/Crystal/ScalarUtils.h
inc/MantidGeometry/Crystal/ScattererFactory.h
inc/MantidGeometry/Crystal/SpaceGroup.h
inc/MantidGeometry/Crystal/SpaceGroupFactory.h
inc/MantidGeometry/Crystal/SymmetryOperation.h
Expand Down Expand Up @@ -226,13 +228,16 @@ set ( TEST_FILES
AlgebraTest.h
BnIdTest.h
BoundingBoxTest.h
BraggScattererFactoryTest.h
BraggScattererInCrystalStructureTest.h
BraggScattererTest.h
CenteringGroupTest.h
CompAssemblyTest.h
ComponentHelperTest.h
ComponentParserTest.h
ComponentTest.h
CompositeBraggScattererTest.h
CompositeImplicitFunctionTest.h
CompositeScattererTest.h
ConeTest.h
ConventionalCellTest.h
ConvexPolygonTest.h
Expand All @@ -248,12 +253,11 @@ set ( TEST_FILES
IDFObjectTest.h
IMDDimensionFactoryTest.h
IMDDimensionTest.h
IScattererTest.h
IndexingUtilsTest.h
InstrumentDefinitionParserTest.h
InstrumentRayTracerTest.h
InstrumentTest.h
IsotropicAtomScattererTest.h
IsotropicAtomBraggScattererTest.h
LaszloIntersectionTest.h
LineIntersectVisitTest.h
LineTest.h
Expand Down Expand Up @@ -302,7 +306,6 @@ set ( TEST_FILES
RulesTest.h
RulesUnionTest.h
ScalarUtilsTest.h
ScattererFactoryTest.h
ShapeFactoryTest.h
SpaceGroupFactoryTest.h
SpaceGroupTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#ifndef MANTID_GEOMETRY_BRAGGSCATTERER_H_
#define MANTID_GEOMETRY_BRAGGSCATTERER_H_

#include "MantidGeometry/DllConfig.h"
#include "MantidKernel/V3D.h"


#include <complex>
#include <boost/shared_ptr.hpp>

#include "MantidKernel/PropertyManager.h"
#include "MantidKernel/TypedValidator.h"

namespace Mantid
{
namespace Geometry
{

typedef std::complex<double> StructureFactor;

/** BraggScatterer
BraggScatterer is a general interface for representing scatterers
in the unit cell of a periodic structure. Since there are many possibilities
of modelling scatterers, BraggScatterer is derived from PropertyManager.
This way, new scatterers with very different parameters can be
added easily.
New implementations must override the declareProperties method and
define any parameters there. For most applications it should be easier
to inherit from BraggScattererInCrystalStructure, which provides some
default properties that are useful in many cases. CompositeBraggScatterer
is designed to combine several scatterers.
CompositeBraggScatterer does not declare any properties by itself. For
some properties it makes sense to be equal for all scatterers in the
composite. This behavior can be achieved by calling the method
makePropertyPropagating after it has been declared. Examples are
the UnitCell and SpaceGroup properties in BraggScattererInCrystalStructure.
Construction of concrete scatterers is done through ScattererFactory.
@author Michael Wedel, Paul Scherrer Institut - SINQ
@date 20/10/2014
Copyright © 2014 PSI-MSS
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>
*/

class BraggScatterer;

typedef boost::shared_ptr<BraggScatterer> BraggScatterer_sptr;

class MANTID_GEOMETRY_DLL BraggScatterer : public Kernel::PropertyManager
{
public:
BraggScatterer();
virtual ~BraggScatterer() { }

void initialize();
bool isInitialized();

virtual std::string name() const = 0;
virtual BraggScatterer_sptr clone() const = 0;

virtual StructureFactor calculateStructureFactor(const Kernel::V3D &hkl) const = 0;

bool isPropertyExposedToComposite(const std::string &propertyName) const;
bool isPropertyExposedToComposite(Kernel::Property *property) const;

protected:
/// Base implementation does nothing, can be re-implemented by subclasses.
void afterPropertySet(const std::string &) { }

/// Base implementation does nothing - for implementing classes only.
virtual void declareProperties() { }

void exposePropertyToComposite(const std::string &propertyName);
void unexposePropertyFromComposite(const std::string &propertyName);

const std::string &getPropagatingGroupName() const;

private:
std::string m_propagatingGroupName;
bool m_isInitialized;
};

} // namespace Geometry
} // namespace Mantid

#endif /* MANTID_GEOMETRY_BRAGGSCATTERER_H_ */
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
#ifndef MANTID_GEOMETRY_SCATTERERFACTORY_H_
#define MANTID_GEOMETRY_SCATTERERFACTORY_H_
#ifndef MANTID_GEOMETRY_BRAGGSCATTERERFACTORY_H_
#define MANTID_GEOMETRY_BRAGGSCATTERERFACTORY_H_

#include "MantidGeometry/DllConfig.h"
#include "MantidKernel/DynamicFactory.h"
#include "MantidKernel/SingletonHolder.h"
#include "MantidGeometry/Crystal/IScatterer.h"
#include "MantidGeometry/Crystal/BraggScatterer.h"

namespace Mantid
{
namespace Geometry
{

/** ScattererFactory :
/** BraggScattererFactory :
This class implements a factory for concrete IScatterer classes.
When a new scatterer is derived from IScatterer, it should be registered
This class implements a factory for concrete BraggScatterer classes.
When a new scatterer is derived from BraggScatterer, it should be registered
in the factory. Like other factories in Mantid, a macro is provided for
this purpose:
DECLARE_SCATTERER(NewScattererClass)
DECLARE_BRAGGSCATTERER(NewScattererClass)
At runtime, instances of this class can be created like this:
IScatterer_sptr scatterer = ScattererFactory::Instance().createScatterer("NewScattererClass");
BraggScatterer_sptr scatterer = BraggScattererFactory::Instance().createScatterer("NewScattererClass");
The returned object is initialized, which is required for using the
Kernel::Property-based system of setting parameters for the scatterer.
To make creation of scatterers more convenient, it's possible to provide
a string with "name=value" pairs, separated by semi-colons, which assigns
property values. This is similar to the way FunctionFactory::createInitialized works:
IScatterer_sptr s = ScattererFactory::Instance()
BraggScatterer_sptr s = BraggScattererFactory::Instance()
.createScatterer(
"NewScatterer",
"SpaceGroup=F m -3 m; Position=[0.1,0.2,0.3]");
If you choose to use the raw create/createUnwrapped methods, you have to
make sure to call IScatterer::initialize() on the created instance.
make sure to call BraggScatterer::initialize() on the created instance.
@author Michael Wedel, Paul Scherrer Institut - SINQ
@date 26/10/2014
Expand All @@ -61,43 +61,43 @@ namespace Geometry
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_GEOMETRY_DLL ScattererFactoryImpl : public Kernel::DynamicFactory<IScatterer>
class MANTID_GEOMETRY_DLL BraggScattererFactoryImpl : public Kernel::DynamicFactory<BraggScatterer>
{
public:
IScatterer_sptr createScatterer(const std::string &name, const std::string &properties = "");
BraggScatterer_sptr createScatterer(const std::string &name, const std::string &properties = "");

/// Subscribes a scatterer class into the factory.
template<class C>
void subscribeScatterer()
{
Kernel::Instantiator<C, IScatterer> *instantiator = new Kernel::Instantiator<C, IScatterer>;
IScatterer_sptr scatterer = instantiator->createInstance();
Kernel::Instantiator<C, BraggScatterer> *instantiator = new Kernel::Instantiator<C, BraggScatterer>;
BraggScatterer_sptr scatterer = instantiator->createInstance();

subscribe(scatterer->name(), instantiator);
}

private:
friend struct Mantid::Kernel::CreateUsingNew<ScattererFactoryImpl>;
friend struct Mantid::Kernel::CreateUsingNew<BraggScattererFactoryImpl>;

ScattererFactoryImpl();
BraggScattererFactoryImpl();
};

// This is taken from FuncMinimizerFactory
#ifdef _WIN32
template class MANTID_GEOMETRY_DLL Mantid::Kernel::SingletonHolder<ScattererFactoryImpl>;
template class MANTID_GEOMETRY_DLL Mantid::Kernel::SingletonHolder<BraggScattererFactoryImpl>;
#endif

typedef Mantid::Kernel::SingletonHolder<ScattererFactoryImpl> ScattererFactory;
typedef Mantid::Kernel::SingletonHolder<BraggScattererFactoryImpl> BraggScattererFactory;


} // namespace Geometry
} // namespace Mantid

#define DECLARE_SCATTERER(classname) \
#define DECLARE_BRAGGSCATTERER(classname) \
namespace { \
Mantid::Kernel::RegistrationHelper register_scatterer_##classname( \
((Mantid::Geometry::ScattererFactory::Instance().subscribeScatterer<classname>()) \
((Mantid::Geometry::BraggScattererFactory::Instance().subscribeScatterer<classname>()) \
, 0)); \
}

#endif /* MANTID_GEOMETRY_ISCATTERERFACTORY_H_ */
#endif /* MANTID_GEOMETRY_BRAGGSCATTERERFACTORY_H_ */

0 comments on commit 839270e

Please sign in to comment.