From 9e84d43535c14a0fe7ef44524a3520391ae9fa6c Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Thu, 12 Dec 2013 15:46:43 +0100 Subject: [PATCH] ThreadInfo is cloned now in Simulation, ThreadInfo is exposed to python --- App/src/TestMiscellaneous.cpp | 33 ++++++++----- Core/Algorithms/src/Simulation.cpp | 1 + Core/PythonAPI/inc/PythonCoreList.h | 1 + Core/PythonAPI/inc/ThreadInfo.pypp.h | 11 +++++ Core/PythonAPI/src/PythonModule.cpp | 2 + Core/PythonAPI/src/ThreadInfo.pypp.cpp | 49 +++++++++++++++++++ Core/python_module.pri | 2 + .../FitSpheresInHexLattice.py | 8 +-- .../FitSpheresInHexLattice_builder.py | 5 +- dev-tools/python-bindings/MakePyCore.py | 1 + 10 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 Core/PythonAPI/inc/ThreadInfo.pypp.h create mode 100644 Core/PythonAPI/src/ThreadInfo.pypp.cpp diff --git a/App/src/TestMiscellaneous.cpp b/App/src/TestMiscellaneous.cpp index 45216c2827e..96bd138b020 100644 --- a/App/src/TestMiscellaneous.cpp +++ b/App/src/TestMiscellaneous.cpp @@ -91,10 +91,11 @@ void TestMiscellaneous::test_FunctionalTestRegistry() MaterialManager::getHomogeneousMaterial("Substrate", 6e-6, 2e-8); const IMaterial *particle_material = MaterialManager::getHomogeneousMaterial("Particle", 6e-4, 2e-8); - Layer air_layer; - air_layer.setMaterial(p_air_material); - Layer substrate_layer; - substrate_layer.setMaterial(p_substrate_material); + FormFactorFullSphere ff_cyl(5.0*Units::nanometer); + Particle particle(particle_material, ff_cyl); + + ParticleDecoration particle_decoration; + particle_decoration.addParticle(particle); Lattice2DIFParameters lattice_params; lattice_params.m_length_1 = 10.0*Units::nanometer; // L1 @@ -106,16 +107,14 @@ void TestMiscellaneous::test_FunctionalTestRegistry() new InterferenceFunction2DLattice(lattice_params); FTDistribution2DCauchy pdf(10.0*Units::nanometer, 10.0*Units::nanometer); p_interference_function->setProbabilityDistribution(pdf); - - // particles - ParticleDecoration particle_decoration; - FormFactorFullSphere ff_cyl(5.0*Units::nanometer); - Particle particle(particle_material, ff_cyl); - particle_decoration.addParticle(particle); particle_decoration.addInterferenceFunction(p_interference_function); + + Layer air_layer(p_air_material); air_layer.setDecoration(particle_decoration); + Layer substrate_layer(p_substrate_material, 0); + multi_layer->addLayer(air_layer); multi_layer->addLayer(substrate_layer); @@ -135,12 +134,22 @@ void TestMiscellaneous::test_FunctionalTestRegistry() // ---- simulation->runSimulation(); OutputData<double> *real_data = simulation->getIntensityData(); + double noise_factor(0.1); + for(size_t i=0; i<real_data->getAllocatedSize(); ++i) { + double amplitude = (*real_data)[i]; + double sigma = noise_factor*std::sqrt(amplitude); + double noisy_amplitude = MathFunctions::GenerateNormalRandom(amplitude, sigma); + if(noisy_amplitude < 0) noisy_amplitude = 0.0; + (*real_data)[i] = noisy_amplitude; + } FitSuite *fit_suite = new FitSuite(); fit_suite->addSimulationAndRealData(*simulation, *real_data); fit_suite->initPrint(10); - fit_suite->addFitParameter("*2DLattice/length_*", 8.0*Units::nanometer, 0.01*Units::nanometer, AttLimits::lowerLimited(0.01)); - fit_suite->addFitParameter("*/FormFactorFullSphere/radius", 8.0*Units::nanometer, 0.01*Units::nanometer, AttLimits::lowerLimited(0.01)); +// fit_suite->addFitParameter("*2DLattice/length_*", 8.0*Units::nanometer, 0.01*Units::nanometer, AttLimits::lowerLimited(0.01)); +// fit_suite->addFitParameter("*/FormFactorFullSphere/radius", 8.0*Units::nanometer, 0.01*Units::nanometer, AttLimits::lowerLimited(0.01)); + fit_suite->addFitParameter("*2DLattice/length_*", 8.0*Units::nanometer, 0.01*Units::nanometer, AttLimits::limited(4., 12.)); + fit_suite->addFitParameter("*/FormFactorFullSphere/radius", 8.0*Units::nanometer, 0.01*Units::nanometer, AttLimits::limited(4., 12.)); fit_suite->runFit(); diff --git a/Core/Algorithms/src/Simulation.cpp b/Core/Algorithms/src/Simulation.cpp index 266e68f9c9f..ae93487c7e0 100644 --- a/Core/Algorithms/src/Simulation.cpp +++ b/Core/Algorithms/src/Simulation.cpp @@ -47,6 +47,7 @@ Simulation::Simulation(const Simulation& other) , mp_sample_builder(other.mp_sample_builder) , m_instrument(other.m_instrument) , m_sim_params(other.m_sim_params) +, m_thread_info(other.m_thread_info) , m_intensity_map() , m_polarization_output() , m_is_normalized(other.m_is_normalized) diff --git a/Core/PythonAPI/inc/PythonCoreList.h b/Core/PythonAPI/inc/PythonCoreList.h index 4ec09c90d50..1c0b4fe6091 100644 --- a/Core/PythonAPI/inc/PythonCoreList.h +++ b/Core/PythonAPI/inc/PythonCoreList.h @@ -81,6 +81,7 @@ #include "StochasticDoubleGate.h" #include "StochasticGaussian.h" #include "StochasticSampledParameter.h" +#include "ThreadInfo.h" #include "Types.h" #include "Units.h" #include "BAVersion.h" diff --git a/Core/PythonAPI/inc/ThreadInfo.pypp.h b/Core/PythonAPI/inc/ThreadInfo.pypp.h new file mode 100644 index 00000000000..52dc1d0a16e --- /dev/null +++ b/Core/PythonAPI/inc/ThreadInfo.pypp.h @@ -0,0 +1,11 @@ +// This file has been generated by Py++. + +// BornAgain: simulate and fit scattering at grazing incidence +//! @brief automatically generated boost::python code for PythonCoreAPI + +#ifndef ThreadInfo_hpp__pyplusplus_wrapper +#define ThreadInfo_hpp__pyplusplus_wrapper + +void register_ThreadInfo_class(); + +#endif//ThreadInfo_hpp__pyplusplus_wrapper diff --git a/Core/PythonAPI/src/PythonModule.cpp b/Core/PythonAPI/src/PythonModule.cpp index 08a156af7a1..ea93bdd1d65 100644 --- a/Core/PythonAPI/src/PythonModule.cpp +++ b/Core/PythonAPI/src/PythonModule.cpp @@ -19,6 +19,7 @@ #include "AxisDouble.pypp.h" #include "IAxis.pypp.h" #include "Layer.pypp.h" +#include "ThreadInfo.pypp.h" #include "IFormFactor.pypp.h" #include "IObservable.pypp.h" #include "FormFactorParallelepiped.pypp.h" @@ -189,6 +190,7 @@ BOOST_PYTHON_MODULE(libBornAgainCore){ register_StochasticDoubleGate_class(); register_StochasticDoubleGaussian_class(); register_StochasticSampledParameter_class(); + register_ThreadInfo_class(); register_global_variables(); register_free_functions(); diff --git a/Core/PythonAPI/src/ThreadInfo.pypp.cpp b/Core/PythonAPI/src/ThreadInfo.pypp.cpp new file mode 100644 index 00000000000..e76bda361f6 --- /dev/null +++ b/Core/PythonAPI/src/ThreadInfo.pypp.cpp @@ -0,0 +1,49 @@ +// This file has been generated by Py++. + +// BornAgain: simulate and fit scattering at grazing incidence +//! @brief automatically generated boost::python code for PythonCoreAPI + +#include "Macros.h" +GCC_DIAG_OFF(unused-parameter); +GCC_DIAG_OFF(missing-field-initializers); +#include "boost/python.hpp" +GCC_DIAG_ON(unused-parameter); +GCC_DIAG_ON(missing-field-initializers); +#include "PythonCoreList.h" +#include "ThreadInfo.pypp.h" + +namespace bp = boost::python; + +void register_ThreadInfo_class(){ + + { //::ThreadInfo + typedef bp::class_< ThreadInfo > ThreadInfo_exposer_t; + ThreadInfo_exposer_t ThreadInfo_exposer = ThreadInfo_exposer_t( "ThreadInfo", bp::init< >() ); + bp::scope ThreadInfo_scope( ThreadInfo_exposer ); + { //::ThreadInfo::getBeginIndex + + typedef int ( ::ThreadInfo::*getBeginIndex_function_type )( int ) ; + + ThreadInfo_exposer.def( + "getBeginIndex" + , getBeginIndex_function_type( &::ThreadInfo::getBeginIndex ) + , ( bp::arg("total_size") ) ); + + } + { //::ThreadInfo::getEndIndex + + typedef int ( ::ThreadInfo::*getEndIndex_function_type )( int ) ; + + ThreadInfo_exposer.def( + "getEndIndex" + , getEndIndex_function_type( &::ThreadInfo::getEndIndex ) + , ( bp::arg("total_size") ) ); + + } + ThreadInfo_exposer.def_readwrite( "current_batch", &ThreadInfo::current_batch ); + ThreadInfo_exposer.def_readwrite( "current_thread", &ThreadInfo::current_thread ); + ThreadInfo_exposer.def_readwrite( "n_batches", &ThreadInfo::n_batches ); + ThreadInfo_exposer.def_readwrite( "n_threads", &ThreadInfo::n_threads ); + } + +} diff --git a/Core/python_module.pri b/Core/python_module.pri index ad5fb6536af..48b4a5b59c2 100644 --- a/Core/python_module.pri +++ b/Core/python_module.pri @@ -19,6 +19,7 @@ HEADERS += \ PythonAPI/inc/AxisDouble.pypp.h \ PythonAPI/inc/IAxis.pypp.h \ PythonAPI/inc/Layer.pypp.h \ + PythonAPI/inc/ThreadInfo.pypp.h \ PythonAPI/inc/IFormFactor.pypp.h \ PythonAPI/inc/IObservable.pypp.h \ PythonAPI/inc/FormFactorParallelepiped.pypp.h \ @@ -142,6 +143,7 @@ SOURCES += \ PythonAPI/src/ParticleDecoration.pypp.cpp \ PythonAPI/src/FormFactorSphereGaussianRadius.pypp.cpp \ PythonAPI/src/IClusteredParticles.pypp.cpp \ + PythonAPI/src/ThreadInfo.pypp.cpp \ PythonAPI/src/Particle.pypp.cpp \ PythonAPI/src/IObserver.pypp.cpp \ PythonAPI/src/Lattice.pypp.cpp \ diff --git a/Examples/python/fitting/ex003_FitSpheresInHexLattice/FitSpheresInHexLattice.py b/Examples/python/fitting/ex003_FitSpheresInHexLattice/FitSpheresInHexLattice.py index 5f21ca044d7..7af3a83205a 100644 --- a/Examples/python/fitting/ex003_FitSpheresInHexLattice/FitSpheresInHexLattice.py +++ b/Examples/python/fitting/ex003_FitSpheresInHexLattice/FitSpheresInHexLattice.py @@ -153,12 +153,12 @@ def run_fitting(): #fit_suite.setMinimizer( MinimizerFactory.createMinimizer("Minuit2","Scan")) #fit_suite.setMinimizer( MinimizerFactory.createMinimizer("GSLSimAn")) - #draw_observer = DrawObserver() - #fit_suite.attachObserver(draw_observer) + draw_observer = DrawObserver() + fit_suite.attachObserver(draw_observer) # setting fitting parameters with starting values - fit_suite.addFitParameter("*2DLattice/length_*", 8.*nanometer, 0.01*nanometer, AttLimits.lowerLimited(0.01)) # this fit parameter will change both length_1 and length_2 simultaneously - fit_suite.addFitParameter("*/FormFactorFullSphere/radius", 8.*nanometer, 0.01*nanometer, AttLimits.lowerLimited(0.01)) + fit_suite.addFitParameter("*2DLattice/length_*", 8.*nanometer, 0.01*nanometer, AttLimits.limited(4., 12.)) # this fit parameter will change both length_1 and length_2 simultaneously + fit_suite.addFitParameter("*/FormFactorFullSphere/radius", 8.*nanometer, 0.01*nanometer, AttLimits.limited(4., 12.)) # running fit fit_suite.runFit() diff --git a/Examples/python/fitting/ex003_FitSpheresInHexLattice/FitSpheresInHexLattice_builder.py b/Examples/python/fitting/ex003_FitSpheresInHexLattice/FitSpheresInHexLattice_builder.py index 74c0fccad0d..e3dd45fadaa 100644 --- a/Examples/python/fitting/ex003_FitSpheresInHexLattice/FitSpheresInHexLattice_builder.py +++ b/Examples/python/fitting/ex003_FitSpheresInHexLattice/FitSpheresInHexLattice_builder.py @@ -79,6 +79,7 @@ def get_simulation(): sim_params.me_if_approx = SimulationParameters.LMA sim_params.me_lattice_type = SimulationParameters.LATTICE simulation.setSimulationParameters(sim_params) + return simulation def create_real_data(): @@ -174,8 +175,8 @@ def run_fitting(): fit_suite.attachObserver(draw_observer) # setting fitting parameters with starting values - fit_suite.addFitParameter("*radius", 8.*nanometer, 0.01*nanometer, AttLimits.lowerLimited(0.01)) - fit_suite.addFitParameter("*lattice_constant", 8.*nanometer, 0.01*nanometer, AttLimits.lowerLimited(0.01)) + fit_suite.addFitParameter("*radius", 8.*nanometer, 0.01*nanometer, AttLimits.limited(4., 12.)) + fit_suite.addFitParameter("*lattice_constant", 8.*nanometer, 0.01*nanometer, AttLimits.limited(4., 12.)) # running fit fit_suite.runFit() diff --git a/dev-tools/python-bindings/MakePyCore.py b/dev-tools/python-bindings/MakePyCore.py index 6758655f22f..0adddedfb38 100644 --- a/dev-tools/python-bindings/MakePyCore.py +++ b/dev-tools/python-bindings/MakePyCore.py @@ -115,6 +115,7 @@ include_classes = [ "StochasticDoubleGaussian", "StochasticParameter<double>", "StochasticSampledParameter", + "ThreadInfo", "cvector_t", "kvector_t", ] -- GitLab