diff --git a/Core/PythonAPI/src/Beam.pypp.cpp b/Core/PythonAPI/src/Beam.pypp.cpp index 7be8b71bcf08266592256d4ad8d71e74f8bb25fb..b9a6fb9a58eeaa7ec01aa8a6085af928a9683646 100644 --- a/Core/PythonAPI/src/Beam.pypp.cpp +++ b/Core/PythonAPI/src/Beam.pypp.cpp @@ -132,6 +132,26 @@ void register_Beam_class(){ Beam_exposer_t Beam_exposer = Beam_exposer_t( "Beam", bp::init< >() ); bp::scope Beam_scope( Beam_exposer ); Beam_exposer.def( bp::init< Beam const & >(( bp::arg("other") )) ); + { //::Beam::SetSpinUpFraction + + typedef void ( ::Beam::*SetSpinUpFraction_function_type )( double ) ; + + Beam_exposer.def( + "SetSpinUpFraction" + , SetSpinUpFraction_function_type( &::Beam::SetSpinUpFraction ) + , ( bp::arg("up_fraction") ) ); + + } + { //::Beam::checkPolarization + + typedef bool ( ::Beam::*checkPolarization_function_type )( ::Eigen::Matrix2cd const & ) const; + + Beam_exposer.def( + "checkPolarization" + , checkPolarization_function_type( &::Beam::checkPolarization ) + , ( bp::arg("polarization") ) ); + + } { //::Beam::getCentralK typedef ::cvector_t ( ::Beam::*getCentralK_function_type )( ) const; @@ -149,6 +169,15 @@ void register_Beam_class(){ "getIntensity" , getIntensity_function_type( &::Beam::getIntensity ) ); + } + { //::Beam::getPolarization + + typedef ::Eigen::Matrix2cd ( ::Beam::*getPolarization_function_type )( ) const; + + Beam_exposer.def( + "getPolarization" + , getPolarization_function_type( &::Beam::getPolarization ) ); + } { //::Beam::operator= @@ -190,6 +219,16 @@ void register_Beam_class(){ , setIntensity_function_type( &::Beam::setIntensity ) , ( bp::arg("intensity") ) ); + } + { //::Beam::setPolarization + + typedef void ( ::Beam::*setPolarization_function_type )( ::Eigen::Matrix2cd const & ) ; + + Beam_exposer.def( + "setPolarization" + , setPolarization_function_type( &::Beam::setPolarization ) + , ( bp::arg("polarization") ) ); + } { //::IParameterized::areParametersChanged diff --git a/Core/PythonAPI/src/HomogeneousMaterial.pypp.cpp b/Core/PythonAPI/src/HomogeneousMaterial.pypp.cpp index 1e01a3ee1dc5acd5c2d0130b75c8637a36fe04ae..ae553a961747045302f059a3be2debf95d937b64 100644 --- a/Core/PythonAPI/src/HomogeneousMaterial.pypp.cpp +++ b/Core/PythonAPI/src/HomogeneousMaterial.pypp.cpp @@ -14,14 +14,50 @@ GCC_DIAG_ON(missing-field-initializers); namespace bp = boost::python; +struct HomogeneousMaterial_wrapper : HomogeneousMaterial, bp::wrapper< HomogeneousMaterial > { + + HomogeneousMaterial_wrapper(HomogeneousMaterial const & arg ) + : HomogeneousMaterial( arg ) + , bp::wrapper< HomogeneousMaterial >(){ + // copy constructor + + } + + HomogeneousMaterial_wrapper(::std::string const & name, ::complex_t const & refractive_index ) + : HomogeneousMaterial( name, boost::ref(refractive_index) ) + , bp::wrapper< HomogeneousMaterial >(){ + // constructor + + } + + HomogeneousMaterial_wrapper(::std::string const & name, double refractive_index_delta, double refractive_index_beta ) + : HomogeneousMaterial( name, refractive_index_delta, refractive_index_beta ) + , bp::wrapper< HomogeneousMaterial >(){ + // constructor + + } + + virtual bool isScalarMaterial( ) { + if( bp::override func_isScalarMaterial = this->get_override( "isScalarMaterial" ) ) + return func_isScalarMaterial( ); + else{ + return this->IMaterial::isScalarMaterial( ); + } + } + + bool default_isScalarMaterial( ) { + return IMaterial::isScalarMaterial( ); + } + +}; + void register_HomogeneousMaterial_class(){ { //::HomogeneousMaterial - typedef bp::class_< HomogeneousMaterial, bp::bases< IMaterial > > HomogeneousMaterial_exposer_t; + typedef bp::class_< HomogeneousMaterial_wrapper, bp::bases< IMaterial > > HomogeneousMaterial_exposer_t; HomogeneousMaterial_exposer_t HomogeneousMaterial_exposer = HomogeneousMaterial_exposer_t( "HomogeneousMaterial", bp::init< std::string const &, complex_t const & >(( bp::arg("name"), bp::arg("refractive_index") )) ); bp::scope HomogeneousMaterial_scope( HomogeneousMaterial_exposer ); - HomogeneousMaterial_exposer.def( bp::init< std::string const &, double, double >(( bp::arg("name"), bp::arg("refractive_index_real"), bp::arg("refractive_index_imag") )) ); - HomogeneousMaterial_exposer.def( bp::init< complex_t const & >(( bp::arg("refractive_index") )) ); + HomogeneousMaterial_exposer.def( bp::init< std::string const &, double, double >(( bp::arg("name"), bp::arg("refractive_index_delta"), bp::arg("refractive_index_beta") )) ); { //::HomogeneousMaterial::getRefractiveIndex typedef ::complex_t ( ::HomogeneousMaterial::*getRefractiveIndex_function_type )( ) const; @@ -41,6 +77,17 @@ void register_HomogeneousMaterial_class(){ , ( bp::arg("refractive_index") ) ); } + { //::IMaterial::isScalarMaterial + + typedef bool ( ::IMaterial::*isScalarMaterial_function_type )( ) ; + typedef bool ( HomogeneousMaterial_wrapper::*default_isScalarMaterial_function_type )( ) ; + + HomogeneousMaterial_exposer.def( + "isScalarMaterial" + , isScalarMaterial_function_type(&::IMaterial::isScalarMaterial) + , default_isScalarMaterial_function_type(&HomogeneousMaterial_wrapper::default_isScalarMaterial) ); + + } } } diff --git a/Core/PythonAPI/src/IMaterial.pypp.cpp b/Core/PythonAPI/src/IMaterial.pypp.cpp index 1a1997a5f361c34b79ace156dcf0633d265f56e5..87c26478ab3396e132684a4eee76153ab501b54d 100644 --- a/Core/PythonAPI/src/IMaterial.pypp.cpp +++ b/Core/PythonAPI/src/IMaterial.pypp.cpp @@ -14,13 +14,53 @@ GCC_DIAG_ON(missing-field-initializers); namespace bp = boost::python; +struct IMaterial_wrapper : IMaterial, bp::wrapper< IMaterial > { + + IMaterial_wrapper(IMaterial const & arg ) + : IMaterial( arg ) + , bp::wrapper< IMaterial >(){ + // copy constructor + + } + + IMaterial_wrapper(::std::string const & name ) + : IMaterial( name ) + , bp::wrapper< IMaterial >(){ + // constructor + + } + + virtual bool isScalarMaterial( ) { + if( bp::override func_isScalarMaterial = this->get_override( "isScalarMaterial" ) ) + return func_isScalarMaterial( ); + else{ + return this->IMaterial::isScalarMaterial( ); + } + } + + bool default_isScalarMaterial( ) { + return IMaterial::isScalarMaterial( ); + } + +}; + void register_IMaterial_class(){ { //::IMaterial - typedef bp::class_< IMaterial > IMaterial_exposer_t; + typedef bp::class_< IMaterial_wrapper > IMaterial_exposer_t; IMaterial_exposer_t IMaterial_exposer = IMaterial_exposer_t( "IMaterial", bp::init< std::string const & >(( bp::arg("name") )) ); bp::scope IMaterial_scope( IMaterial_exposer ); - IMaterial_exposer.def( bp::init< IMaterial const & >(( bp::arg("other") )) ); + { //::IMaterial::isScalarMaterial + + typedef bool ( ::IMaterial::*isScalarMaterial_function_type )( ) ; + typedef bool ( IMaterial_wrapper::*default_isScalarMaterial_function_type )( ) ; + + IMaterial_exposer.def( + "isScalarMaterial" + , isScalarMaterial_function_type(&::IMaterial::isScalarMaterial) + , default_isScalarMaterial_function_type(&IMaterial_wrapper::default_isScalarMaterial) ); + + } } } diff --git a/Core/PythonAPI/src/MaterialManager.pypp.cpp b/Core/PythonAPI/src/MaterialManager.pypp.cpp index 6fb93d93363c6a54e802c520602625a27a789ed0..945dc8ba821332a0bda3b314684e4647c3369fd8 100644 --- a/Core/PythonAPI/src/MaterialManager.pypp.cpp +++ b/Core/PythonAPI/src/MaterialManager.pypp.cpp @@ -48,7 +48,7 @@ void register_MaterialManager_class(){ MaterialManager_exposer.def( "getHomogeneousMaterial" , getHomogeneousMaterial_function_type( &::MaterialManager::getHomogeneousMaterial ) - , ( bp::arg("name"), bp::arg("refractive_index_real"), bp::arg("refractive_index_imag") ) + , ( bp::arg("name"), bp::arg("refractive_index_delta"), bp::arg("refractive_index_beta") ) , bp::return_value_policy< bp::reference_existing_object >() ); } diff --git a/Core/PythonAPI/src/PythonInterface_global_variables.pypp.cpp b/Core/PythonAPI/src/PythonInterface_global_variables.pypp.cpp index 5d1add1c3715c32e564ef88a0b5a13bcb4548e71..8342a29e6283f7a37e777d1f430278995ad33831 100644 --- a/Core/PythonAPI/src/PythonInterface_global_variables.pypp.cpp +++ b/Core/PythonAPI/src/PythonInterface_global_variables.pypp.cpp @@ -30,6 +30,8 @@ void register_global_variables(){ bp::scope().attr("degree") = Units::degree; + bp::scope().attr("gauss") = Units::gauss; + bp::scope().attr("meter") = Units::meter; bp::scope().attr("micrometer") = Units::micrometer; @@ -52,4 +54,6 @@ void register_global_variables(){ bp::scope().attr("steradian") = Units::steradian; + bp::scope().attr("tesla") = Units::tesla; + } diff --git a/Core/Samples/inc/IMaterial.h b/Core/Samples/inc/IMaterial.h index 883c734a2d67fddfec8a1330f8633f2f5f7f2439..88a1e84eb8379ce4f67967ef0202f35452aac90f 100644 --- a/Core/Samples/inc/IMaterial.h +++ b/Core/Samples/inc/IMaterial.h @@ -18,7 +18,6 @@ #include <string> #include <iostream> -//#include <typeinfo> #include "INamed.h" //! Interface to a named material. @@ -29,9 +28,6 @@ class IMaterial : public INamed //! Constructor that sets _name_. explicit IMaterial(const std::string& name) : INamed(name) {} - //! Copy constructor. TODO: test whether needed - IMaterial(const IMaterial& other) : INamed(other) {} - //! Destructor. virtual ~IMaterial() {} @@ -46,7 +42,6 @@ class IMaterial : public INamed protected: virtual void print(std::ostream& ostr) const { ostr << "IMat:" << getName() << "<" << this << ">"; } - // TODO: try ostr << typeid(*this).name() << " " << this; }; #endif // IMATERIAL_H diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs02.py b/Tests/FunctionalTests/TestPyCore/isgisaxs02.py index a12939931ac9240131b4cd628912e871c1797d83..a6db44bb9e461f6de37dd7ef38adc22449b02c0e 100644 --- a/Tests/FunctionalTests/TestPyCore/isgisaxs02.py +++ b/Tests/FunctionalTests/TestPyCore/isgisaxs02.py @@ -19,7 +19,7 @@ def RunSimulation(): # defining materials mAmbience = MaterialManager.getHomogeneousMaterial("Air", 0.0, 0.0 ) # collection of particles - n_particle = complex(6e-4, 2e-8) + n_particle = complex(1.0 - 6e-4, 2e-8) radius1 = 5.0*nanometer radius2 = 10.0*nanometer height1 = radius1 diff --git a/dev-tools/python-bindings/MakePyCore.py b/dev-tools/python-bindings/MakePyCore.py index 29095b0af1a818e5abb8e759e1503363ec311098..a1f51c606f4d5d20e2a156e261e4120bbc611ce2 100644 --- a/dev-tools/python-bindings/MakePyCore.py +++ b/dev-tools/python-bindings/MakePyCore.py @@ -26,7 +26,8 @@ include_dirs = [ '../../Core/Algorithms/inc', '../../Core/Tools/inc', '../../Core/PythonAPI/inc', - '../../Core/Geometry/inc' + '../../Core/Geometry/inc', + '../../ThirdParty/eigen3' ] include_classes = [ @@ -250,7 +251,7 @@ def MakePythonAPI(OutputTempDir): print "NOTE: If you update the source library code you need to manually delete the cache_core.xml file, or run 'python codegenerator.py clean'" xml_cached_fc = parser.create_cached_source_fc( "PythonCoreList.h", "cache_core.xml" ) #xml_cached_fc = parser.create_cached_source_fc( ["PythonCoreList.h","PythonCoreExposer.h"], "cache_core.xml" ) - mb = module_builder.module_builder_t( [xml_cached_fc], include_paths=include_dirs, gccxml_path=mygccxml, cflags="-m64") + mb = module_builder.module_builder_t( [xml_cached_fc], include_paths=include_dirs, gccxml_path=mygccxml, cflags="-m64 -msse -msse2 -fno-strict-aliasing -msse3") # ----------------- # general rules diff --git a/dev-tools/python-bindings/MakePyFit.py b/dev-tools/python-bindings/MakePyFit.py index 3329d9da21799d7fe830ec3f9cfc9ca08b4e4090..b765bb902530092b9364c286147ab747e85bada1 100644 --- a/dev-tools/python-bindings/MakePyFit.py +++ b/dev-tools/python-bindings/MakePyFit.py @@ -25,9 +25,9 @@ include_dirs = [ '../../Core/Algorithms/inc', '../../Core/Tools/inc', '../../Core/Geometry/inc', -'../../Core/Fitting/inc', '../../Fit/Factory/inc', -'../../Fit/PythonAPI/inc' +'../../Fit/PythonAPI/inc', +'../../ThirdParty/eigen3', ] include_classes = [ @@ -100,7 +100,7 @@ def MakePythonAPI(OutputTempDir): #If the cache file cache_core.xml doesn't exist it gets created, otherwise it just gets loaded print "NOTE: If you update the source library code you need to manually delete the cache_fit.xml file, or run 'python codegenerator.py clean'" xml_cached_fc = parser.create_cached_source_fc( "PythonFitList.h", "cache_fit.xml" ) - mb = module_builder.module_builder_t( [xml_cached_fc], include_paths=include_dirs, gccxml_path=mygccxml, cflags="-m64") + mb = module_builder.module_builder_t( [xml_cached_fc], include_paths=include_dirs, gccxml_path=mygccxml, cflags="-m64 -msse3") # ----------------- # general rules diff --git a/shared.pri b/shared.pri index 472e551b2d7390ac9e23d04bf2501e02a63563b9..4df3f5c229d319a65897d72c2b47aac4dc0670af 100644 --- a/shared.pri +++ b/shared.pri @@ -2,8 +2,7 @@ # Common settings for all BornAgain compilations # ----------------------------------------------------------------------------- -#CONFIG += BORNAGAIN_PYTHON # provide python bindings compilation - +CONFIG += BORNAGAIN_PYTHON # provide python bindings compilation win32 { MAKE_COMMAND = mingw32-make