diff --git a/App/inc/StandardSamples.h b/App/inc/StandardSamples.h index c4d5a8345f7460795b095a3c58d933d1bf6e95f0..587c67593d3b0f3a4abe2bd43fe8b2fd808f9d7f 100644 --- a/App/inc/StandardSamples.h +++ b/App/inc/StandardSamples.h @@ -31,7 +31,7 @@ ISample *MultilayerOffspecTestcase1b(); ISample *MultilayerOffspecTestcase2a(); ISample *MultilayerOffspecTestcase2b(); ISample *MultilayerSpecularMagneticTestCase(); -ISample *PolarizedDWBATestCase(); +//ISample *PolarizedDWBATestCase(); //ISample *IsGISAXS15_SSCA(); ISample *MesoCrystal1(); //ISample *MesoCrystal2(); diff --git a/App/inc/TestPerformance2.h b/App/inc/TestPerformance2.h new file mode 100644 index 0000000000000000000000000000000000000000..73227075e904c3a6bfdcac95ce502b0554c71867 --- /dev/null +++ b/App/inc/TestPerformance2.h @@ -0,0 +1,90 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file App/inc/TestPerformance2.h +//! @brief Defines classe TestPerformance2 for logging performance changes +// +//! Homepage: apps.jcns.fz-juelich.de/BornAgain +//! License: GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2013 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef TESTPERFORMANCE2_H +#define TESTPERFORMANCE2_H + +#include "IApplicationTest.h" +#include "INamed.h" + +#include <string> +#include <vector> +#include <map> +#include <iostream> + +class PerformanceTest; + +//! Run standard tests to trace changes in the performance. + +class TestPerformance2 : public IApplicationTest +{ +public: + TestPerformance2(); + virtual ~TestPerformance2(); + virtual void execute(); +private: + void write_results(); + void write_header(std::ofstream &file); + void write_performance(std::ofstream &file); + void set_sysinfo(PerformanceTest *test); + std::vector<PerformanceTest *> m_tests; +}; + + +//! class for performance measurements +class PerformanceTest : public IApplicationTest { +public: + PerformanceTest(const std::string &name, int nrepetitions) + : IApplicationTest(name) + , m_nrepetitions(nrepetitions) + , m_nthreads(0) + , m_cpu_time(0) + , m_real_time(0){} + + virtual ~PerformanceTest(){} + + virtual void execute(); + virtual void runTests(); + + double m_nrepetitions; + int m_nthreads; + double m_cpu_time; + double m_real_time; + std::string m_datime; + std::string m_hostname; + std::string m_sysinfo; +}; + + +//! custom test for specular matrix +class SpecularMatrixPerformanceTest : public PerformanceTest +{ +public: + SpecularMatrixPerformanceTest(const std::string &name, int nrepetitions) + : PerformanceTest(name, nrepetitions){} + virtual void runTests(); +}; + +//! custom test for specular magnetic +class SpecularMagneticPerformanceTest : public PerformanceTest +{ +public: + SpecularMagneticPerformanceTest(const std::string &name, int nrepetitions) + : PerformanceTest(name, nrepetitions){} + virtual void runTests(); +}; + + +#endif diff --git a/App/inc/TestPolarizedDWBA.h b/App/inc/TestPolarizedDWBA.h index dc6ea8b6fb6fa43d836f6d368492c05e644b9758..ab33c020a2ba320b6c2883c11e6a3dc915ddb2de 100644 --- a/App/inc/TestPolarizedDWBA.h +++ b/App/inc/TestPolarizedDWBA.h @@ -28,9 +28,6 @@ public: virtual ~TestPolarizedDWBA() { } virtual void execute(); - -private: - MultiLayer *mp_sample; //!< pointer to multilayer sample }; diff --git a/App/src/ApplicationTestFactory.cpp b/App/src/ApplicationTestFactory.cpp index 84822d336436ee2f539e6e63dc53988abff7525d..d11a1351a985e1189457335e61a012df5aeb49f6 100644 --- a/App/src/ApplicationTestFactory.cpp +++ b/App/src/ApplicationTestFactory.cpp @@ -33,6 +33,7 @@ #include "TestMiscellaneous.h" #include "TestMultiLayerRoughness.h" #include "TestPerformance.h" +#include "TestPerformance2.h" #include "TestPolarizedDWBA.h" #include "TestPolarizedDWBATerms.h" #include "TestPolarizedMeso.h" @@ -201,9 +202,13 @@ void RegisterApplicationTests(ApplicationTestFactory *p_test_factory) IFactoryCreateFunction<TestFittingModule3, IApplicationTest>, "functional test: fit module 4 params, 1d scans"); p_test_factory->registerItem( - "performance", + "performance1", IFactoryCreateFunction<TestPerformance, IApplicationTest>, "functional test: run performance test for several predefined tasks"); + p_test_factory->registerItem( + "performance2", + IFactoryCreateFunction<TestPerformance2, IApplicationTest>, + "functional test: run performance test for several predefined tasks"); p_test_factory->registerItem( "roughdwba", IFactoryCreateFunction<TestMultiLayerRoughness, IApplicationTest>, diff --git a/App/src/SampleFactory.cpp b/App/src/SampleFactory.cpp index b66c658ac1baf29f201af5ee4d0fb99687fb73c9..c70d110cef862789316287ec87ff471a84a5df16 100644 --- a/App/src/SampleFactory.cpp +++ b/App/src/SampleFactory.cpp @@ -57,6 +57,9 @@ SampleFactory::SampleFactory() registerItem("MesoCrystal1", StandardSamples::MesoCrystal1); // registerItem("MesoCrystal2", StandardSamples::MesoCrystal2); +// registerItem("PolarizedDWBATestCase", StandardSamples::PolarizedDWBATestCase); + + // registerItem("FormFactor_Box", StandardSamples::FormFactor_Box); // registerItem("FormFactor_Cone", StandardSamples::FormFactor_Cone); // registerItem("FormFactor_Sphere", StandardSamples::FormFactor_Sphere); diff --git a/App/src/StandardSamples.cpp b/App/src/StandardSamples.cpp index 678d89fe602e17c14e2df4f17f02c9e1b250702d..7d5b57d20bbd2d266352a71b413339cf6f2a253e 100644 --- a/App/src/StandardSamples.cpp +++ b/App/src/StandardSamples.cpp @@ -847,48 +847,48 @@ ISample *StandardSamples::MultilayerSpecularMagneticTestCase() //! Polarized DWBA test case -ISample *StandardSamples::PolarizedDWBATestCase() -{ - const IMaterial *mAmbience = - MaterialManager::getHomogeneousMaterial - ("ambience", 0.0, 0.0 ); - kvector_t magnetic_field(0.0, 1.0, 0.0); - const IMaterial *mPart = - MaterialManager::getHomogeneousMagneticMaterial - ("particle", 5e-6, 0.0, magnetic_field); +//ISample *StandardSamples::PolarizedDWBATestCase() +//{ +// const IMaterial *mAmbience = +// MaterialManager::getHomogeneousMaterial +// ("ambience", 0.0, 0.0 ); +// kvector_t magnetic_field(0.0, 1.0, 0.0); // const IMaterial *mPart = +// MaterialManager::getHomogeneousMagneticMaterial +// ("particle", 5e-6, 0.0, magnetic_field); +//// const IMaterial *mPart = +//// MaterialManager::getHomogeneousMaterial +//// ("particle", 5e-6, 0.0); +// const IMaterial *mSubstrate = // MaterialManager::getHomogeneousMaterial -// ("particle", 5e-6, 0.0); - const IMaterial *mSubstrate = - MaterialManager::getHomogeneousMaterial - ("substrate", 15e-6, 0.0 ); +// ("substrate", 15e-6, 0.0 ); - Layer lAmbience; - lAmbience.setMaterial(mAmbience, 0); +// Layer lAmbience; +// lAmbience.setMaterial(mAmbience, 0); - Layer lSubstrate; - lSubstrate.setMaterial(mSubstrate, 0); +// Layer lSubstrate; +// lSubstrate.setMaterial(mSubstrate, 0); - ParticleDecoration particle_decoration; +// ParticleDecoration particle_decoration; - particle_decoration.addParticle( - new Particle(mPart, - new FormFactorCylinder( - 5.0*Units::nanometer, - 5.0*Units::nanometer) - )); - particle_decoration.addInterferenceFunction(new InterferenceFunctionNone()); +// particle_decoration.addParticle( +// new Particle(mPart, +// new FormFactorCylinder( +// 5.0*Units::nanometer, +// 5.0*Units::nanometer) +// )); +// particle_decoration.addInterferenceFunction(new InterferenceFunctionNone()); - //LayerDecorator air_layer_decorator(air_layer, particle_decoration); - lAmbience.setDecoration(particle_decoration); +// //LayerDecorator air_layer_decorator(air_layer, particle_decoration); +// lAmbience.setDecoration(particle_decoration); - MultiLayer *mySample = new MultiLayer; +// MultiLayer *mySample = new MultiLayer; - // adding layers - mySample->addLayer(lAmbience); +// // adding layers +// mySample->addLayer(lAmbience); - mySample->addLayer(lSubstrate); +// mySample->addLayer(lSubstrate); - return mySample; -} +// return mySample; +//} diff --git a/App/src/TestPerformance.cpp b/App/src/TestPerformance.cpp index 956be1e6c335e6016c6e81e7f536f3300862294e..0eb0d01339b9d19d09c2b522b805380a608971e7 100644 --- a/App/src/TestPerformance.cpp +++ b/App/src/TestPerformance.cpp @@ -184,23 +184,9 @@ void PerfTest_SpecularMatrix::execute() void PerfTest_Pyramid::initialise(ProgramOptions *p_options) { IApplicationTest::initialise(p_options); -// // sample -// if(m_sample) delete m_sample; -// SampleBuilderFactory factory; -// m_sample = dynamic_cast<MultiLayer *>(factory.createSample("isgisaxs09")); - -// // simulation -// if(m_simulation) delete m_simulation; -// m_simulation = new Simulation(mp_options); -// m_simulation->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree, 100, 0.0*Units::degree, 2.0*Units::degree, true); -// m_simulation->setBeamParameters(1.0*Units::angstrom, 0.2*Units::degree, 0.0*Units::degree); -// m_simulation->setSample(*m_sample); - SimulationRegistry registry; m_simulation = registry.createSimulation("isgisaxs09a"); m_simulation->setProgramOptions(p_options); - - } //! Run PerfTest_Pyramid. @@ -215,24 +201,9 @@ void PerfTest_Pyramid::execute() void PerfTest_RotatedPyramid::initialise(ProgramOptions *p_options) { IApplicationTest::initialise(p_options); -// // sample -// if(m_sample) delete m_sample; -// SampleBuilderFactory factory; -// m_sample = dynamic_cast<MultiLayer *>(factory.createSample("isgisaxs09_rotated")); - -// // simulation -// if(m_simulation) delete m_simulation; -// m_simulation = new Simulation(p_options); -// m_simulation->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree, 100, 0.0*Units::degree, 2.0*Units::degree, true); -// m_simulation->setBeamParameters(1.0*Units::angstrom, 0.2*Units::degree, 0.0*Units::degree); -// m_simulation->setSample(*m_sample); - SimulationRegistry registry; m_simulation = registry.createSimulation("isgisaxs09b"); m_simulation->setProgramOptions(p_options); - - - } //! Run PerfTest_RotatedPyramid @@ -247,22 +218,9 @@ void PerfTest_RotatedPyramid::execute() void PerfTest_MesoCrystal::initialise(ProgramOptions *p_options) { IApplicationTest::initialise(p_options); -// // sample -// if(m_sample) delete m_sample; -// m_sample = dynamic_cast<MultiLayer *>(SampleFactory::createSample("MesoCrystal1")); - -// // simulation -// m_simulation = new Simulation(p_options); -// m_simulation->setSample(*m_sample); -// m_simulation->setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree, 100, 0.0*Units::degree, 2.0*Units::degree, true); -// m_simulation->setBeamParameters(0.77*Units::angstrom, 0.4*Units::degree, 0.0*Units::degree); - - SimulationRegistry registry; m_simulation = registry.createSimulation("mesocrystal01"); m_simulation->setProgramOptions(p_options); - - } //! Run PerfTest_MesoCrystal. diff --git a/App/src/TestPerformance2.cpp b/App/src/TestPerformance2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..460c22ce2463a12e23afb0d4029539f7a980f988 --- /dev/null +++ b/App/src/TestPerformance2.cpp @@ -0,0 +1,212 @@ +#include "TestPerformance2.h" +#include "SimulationRegistry.h" +#include "Utils.h" +#include "ProgramOptions.h" +#include "Units.h" +#include "SpecularMatrix.h" +#include "SampleFactory.h" +#include "SpecularMagnetic.h" + +#include "TDatime.h" +#include "TSystem.h" +#include "TBenchmark.h" +#include <sstream> +#include <fstream> +#include <iomanip> +#include <boost/format.hpp> + + + +TestPerformance2::TestPerformance2() +{ + m_tests.push_back(new PerformanceTest("isgisaxs02",2)); + m_tests.push_back(new PerformanceTest("isgisaxs06a",50)); + m_tests.push_back(new PerformanceTest("isgisaxs09b",50)); + m_tests.push_back(new PerformanceTest("isgisaxs11",50)); + m_tests.push_back(new PerformanceTest("isgisaxs15",20)); + m_tests.push_back(new PerformanceTest("mesocrystal01",1)); + m_tests.push_back(new SpecularMatrixPerformanceTest("specmatrix", 500000)); + m_tests.push_back(new SpecularMagneticPerformanceTest("specmagnetic", 500000)); + m_tests.push_back(new PerformanceTest("magcyl2",50)); + std::cout << "TestPerformance::TestPerformance() -> Info. Preparing to run " << m_tests.size() << " performance tests." << std::endl; + +} + + +TestPerformance2::~TestPerformance2() +{ + for(size_t i=0; i<m_tests.size(); ++i) delete m_tests[i]; +} + + + + + +void TestPerformance2::execute() +{ + for(size_t i=0; i<m_tests.size(); ++i) { + PerformanceTest *test = m_tests[i]; + set_sysinfo(test); + + std::cout << "Running test: " << std::setw(20) << std::left << test->getName() << " ... "; + std::cout.flush(); + test->execute(); + std::cout << boost::format("OK: %-6.3f (real sec), %-6.3f (cpu sec) ") % test->m_real_time % test->m_cpu_time << std::endl; + } + + write_results(); +} + + + +void TestPerformance2::write_results() +{ + std::string filename("perf_history.txt"); + std::ofstream file; + file.open(filename.c_str(), std::ios_base::app); + if( !file.is_open() ) { + throw FileNotIsOpenException("TestPerformance::execute() -> Error. Can't open file '"+filename+"' for writing."); + } + + write_header(file); + write_performance(file); + + file.close(); + + std::cout << "TestPerformance::write_performance() -> Info. File '" << filename << "' is updated." << std::endl; +} + + +//! write header in file +void TestPerformance2::write_header(std::ofstream &file) +{ + file << std::endl; + file << boost::format("| %-19s | %-10s | %-13s | %2s | %-8s |") % "date " % "hostname" % "sysinfo" % "tr" % "total"; + for(size_t i=0; i<m_tests.size(); ++i) { + file << boost::format(" %-12s |") % Utils::AdjustStringLength(m_tests[i]->getName(),12); + } + file << std::endl; +} + +//! write results of performance measurements +void TestPerformance2::write_performance(std::ofstream &file) +{ + PerformanceTest *test0 = m_tests[0]; + file << boost::format("| %-19s | %-10s | %-13s | %-2d |") % test0->m_datime % test0->m_hostname % test0->m_sysinfo % test0->m_nthreads; + double sum_real(0), sum_cpu(0); + for(size_t i=0; i<m_tests.size(); ++i) { + sum_real += m_tests[i]->m_real_time; + sum_cpu += m_tests[i]->m_cpu_time; + } + file << boost::format(" %-8.3f |") % sum_real; + + for(size_t i=0; i<m_tests.size(); ++i) { + file << boost::format(" %-12.3f |") % m_tests[i]->m_real_time; + } + file << std::endl; +} + + +//! read sustem information and store it in the test +void TestPerformance2::set_sysinfo(PerformanceTest *test) +{ + test->initialise(mp_options); + + // saving date and time + TDatime td; + test->m_datime = std::string(td.AsSQLString()); + + // saving host name + std::string hostname(gSystem->HostName()); + // stripping host name after first '.' (somehost.jcns.frm2 -> somehost) + std::string::size_type pos = hostname.find_first_of('.'); + if(pos != std::string::npos) { + hostname.erase(pos,hostname.size()-pos); + } + test->m_hostname = hostname; + + // saving hardware information + SysInfo_t sys_info; + int status = gSystem->GetSysInfo(&sys_info); + if( status == -1) { + test->m_sysinfo = std::string("Unknown hardware"); + }else{ + std::ostringstream os; + os << std::string(gSystem->GetBuildArch()); + //os << std::string(gSystem->GetBuildArch()) << ", "<< sys_info.fCpuSpeed << " MHz"; + //os << ", " << sys_info.fL2Cache << " Kb"; + test->m_sysinfo = os.str(); + } + + if (mp_options->find("threads")) { + test->m_nthreads = (*mp_options)["threads"].as<int>(); + } +} + + +// ----------------------------------------------------------------------------- +// General PerformanceTest +// ----------------------------------------------------------------------------- + +//! run performance measurements +void PerformanceTest::execute() +{ + TBenchmark mb; + mb.Start( getName().c_str() ); + + runTests(); + + mb.Stop( getName().c_str() ); + + m_cpu_time = mb.GetCpuTime(getName().c_str()); + m_real_time = mb.GetRealTime(getName().c_str()); +} + + +//! run standard simulation +void PerformanceTest::runTests() +{ + SimulationRegistry registry; + Simulation *simulation = registry.createSimulation(getName()); + simulation->setProgramOptions(mp_options); + for(int i=0; i<m_nrepetitions; i++){ + simulation->runSimulation(); + } + delete simulation; +} + +// ----------------------------------------------------------------------------- +// custom PerformanceTest's +// ----------------------------------------------------------------------------- + +void SpecularMatrixPerformanceTest::runTests() +{ + MultiLayer *ml = dynamic_cast<MultiLayer *>(SampleFactory::createSample("SimpleMultilayer")); + + for(int i=0; i<m_nrepetitions; i++){ + static double alpha_i = -0.3; + kvector_t kvec; + kvec.setLambdaAlphaPhi(1.54*Units::angstrom, -alpha_i, 0.0); + SpecularMatrix::MultiLayerCoeff_t coeffs; + SpecularMatrix matrixCalculator; + matrixCalculator.execute(*ml, kvec, coeffs); + } + delete ml; +} + +void SpecularMagneticPerformanceTest::runTests() +{ + MultiLayer *ml = dynamic_cast<MultiLayer *>(SampleFactory::createSample("MultilayerSpecularMagneticTestCase")); + + for(int i=0; i<m_nrepetitions; i++){ + static double alpha_i = -0.3; + kvector_t kvec; + kvec.setLambdaAlphaPhi(1.54*Units::angstrom, -alpha_i, 0.0); + SpecularMagnetic::MultiLayerCoeff_t coeffs; + SpecularMagnetic magneticCalculator; + magneticCalculator.execute(*ml, kvec, coeffs); + } + delete ml; +} + + diff --git a/App/src/TestPolarizedDWBA.cpp b/App/src/TestPolarizedDWBA.cpp index 49a992d5e4366bde2cb1418f2f927d5ebf791391..498b5cfb6bce8802843a013f06cc16c09079774e 100644 --- a/App/src/TestPolarizedDWBA.cpp +++ b/App/src/TestPolarizedDWBA.cpp @@ -18,10 +18,12 @@ #include "SampleFactory.h" #include "Units.h" #include "IsGISAXSTools.h" +#include "SimulationRegistry.h" +#include "OutputDataIOFactory.h" +#include "FileSystem.h" TestPolarizedDWBA::TestPolarizedDWBA() -: mp_sample(0) { std::cout << "TestPolarizedDWBA::TestPolarizedDWBA() -> Info." << std::endl; @@ -31,29 +33,47 @@ void TestPolarizedDWBA::execute() { std::cout << "TestPolarizedDWBA::execute() -> Info." << std::endl; - // create sample - mp_sample = dynamic_cast<MultiLayer *>(SampleFactory::createSample( - "PolarizedDWBATestCase")); + SimulationRegistry sim_registry; + Simulation *simulation = sim_registry.createSimulation("magcyl2"); + simulation->setProgramOptions(mp_options); - // calculate scattered intensity from sample - Simulation simulation(mp_options); - simulation.setDetectorParameters( - 100, -1.0*Units::degree, 1.0*Units::degree, 100, - 0.0*Units::degree, 2.0*Units::degree, true); - simulation.setBeamParameters( - 1.0*Units::angstrom, 0.2*Units::degree, 0.0*Units::degree); - simulation.setBeamIntensity(1e7); - // Run simulation - simulation.setSample(*mp_sample); - simulation.runSimulation(); + simulation->runSimulation(); + simulation->normalize(); - simulation.normalize(); - - IsGISAXSTools::drawLogOutputDataPol(*simulation.getPolarizedOutputData(), + IsGISAXSTools::drawLogOutputDataPol(*simulation->getPolarizedOutputData(), "c1_polDWBA", "Polarized DWBA", "CONT4 Z", "Polarized DWBA"); - delete mp_sample; +// OutputDataIOFactory::writeIntensityData(*simulation->getPolarizedIntensityData(0,0),"magcyl2_reference_00.txt"); +// OutputDataIOFactory::writeIntensityData(*simulation->getPolarizedIntensityData(0,1),"magcyl2_reference_01.txt"); +// OutputDataIOFactory::writeIntensityData(*simulation->getPolarizedIntensityData(1,0),"magcyl2_reference_10.txt"); +// OutputDataIOFactory::writeIntensityData(*simulation->getPolarizedIntensityData(1,1),"magcyl2_reference_11.txt"); + + +// OutputData<double> *reference00 = OutputDataIOFactory::readIntensityData(Utils::FileSystem::GetReferenceDataDir()+ "magcyl2_reference_00.txt.gz"); +// OutputData<double> *reference01 = OutputDataIOFactory::readIntensityData(Utils::FileSystem::GetReferenceDataDir()+ "magcyl2_reference_01.txt.gz"); +// OutputData<double> *reference10 = OutputDataIOFactory::readIntensityData(Utils::FileSystem::GetReferenceDataDir()+ "magcyl2_reference_10.txt.gz"); +// OutputData<double> *reference11 = OutputDataIOFactory::readIntensityData(Utils::FileSystem::GetReferenceDataDir()+ "magcyl2_reference_11.txt.gz"); + +// IsGISAXSTools::drawOutputDataComparisonResults( +// *simulation->getPolarizedIntensityData(0,0), *reference00, "00", "found params"); + +// IsGISAXSTools::drawOutputDataComparisonResults( +// *simulation->getPolarizedIntensityData(0,1), *reference01, "01", "found params"); + +// IsGISAXSTools::drawOutputDataComparisonResults( +// *simulation->getPolarizedIntensityData(1,0), *reference10, "10", "found params"); + +// IsGISAXSTools::drawOutputDataComparisonResults( +// *simulation->getPolarizedIntensityData(1,1), *reference11, "11", "found params"); + + +// delete reference00; +// delete reference01; +// delete reference10; +// delete reference11; + + delete simulation; } diff --git a/Core/Algorithms/src/Instrument.cpp b/Core/Algorithms/src/Instrument.cpp index c45090ef2e7051b6dac42c93a12d051ea0c36bbf..1c434e091b6cc09b4ebd9fda7a2704748a115119 100644 --- a/Core/Algorithms/src/Instrument.cpp +++ b/Core/Algorithms/src/Instrument.cpp @@ -48,6 +48,12 @@ void Instrument::setDetectorParameters( size_t n_alpha, double alpha_f_min, double alpha_f_max, bool isgisaxs_style) { + if(phi_f_max <= phi_f_min) { + throw LogicErrorException("Instrument::setDetectorParameters() -> Error! phi_f_max <= phi_f_min"); + } + if(alpha_f_max <= alpha_f_min) { + throw LogicErrorException("Instrument::setDetectorParameters() -> Error! alpha_f_max <= alpha_f_min"); + } AxisParameters phi_params; phi_params.m_name = BornAgain::PHI_AXIS_NAME; phi_params.m_range = TSampledRange<double>(n_phi, phi_f_min, phi_f_max); diff --git a/Core/PythonAPI/src/ParticleDecoration.pypp.cpp b/Core/PythonAPI/src/ParticleDecoration.pypp.cpp index 3b1680cac23a6ea978db607b9e4cded68d0e8cbb..780a3b774da25a21859ef5e5a9dc80d24ab48466 100644 --- a/Core/PythonAPI/src/ParticleDecoration.pypp.cpp +++ b/Core/PythonAPI/src/ParticleDecoration.pypp.cpp @@ -25,6 +25,13 @@ struct ParticleDecoration_wrapper : ParticleDecoration, bp::wrapper< ParticleDec } + ParticleDecoration_wrapper(::Particle const & p_particle, double depth=0.0, double abundance=1.0e+0 ) + : ParticleDecoration( boost::ref(p_particle), depth, abundance ) + , bp::wrapper< ParticleDecoration >(){ + // constructor + + } + virtual ::ParticleDecoration * clone( ) const { if( bp::override func_clone = this->get_override( "clone" ) ) return func_clone( ); @@ -268,6 +275,7 @@ void register_ParticleDecoration_class(){ typedef bp::class_< ParticleDecoration_wrapper, bp::bases< IDecoration >, boost::noncopyable > ParticleDecoration_exposer_t; ParticleDecoration_exposer_t ParticleDecoration_exposer = ParticleDecoration_exposer_t( "ParticleDecoration", bp::init< >() ); bp::scope ParticleDecoration_scope( ParticleDecoration_exposer ); + ParticleDecoration_exposer.def( bp::init< Particle const &, bp::optional< double, double > >(( bp::arg("p_particle"), bp::arg("depth")=0.0, bp::arg("abundance")=1.0e+0 )) ); { //::ParticleDecoration::addInterferenceFunction typedef void ( ::ParticleDecoration::*addInterferenceFunction_function_type )( ::IInterferenceFunction const & ) ; diff --git a/Core/StandardSamples/FunctionalTestRegistry.cpp b/Core/StandardSamples/FunctionalTestRegistry.cpp index b120596f23105961cc86b98ebcbd4a5e7fdc644a..226a5293ebc28267a63e72b8b81351b3078e2a01 100644 --- a/Core/StandardSamples/FunctionalTestRegistry.cpp +++ b/Core/StandardSamples/FunctionalTestRegistry.cpp @@ -49,13 +49,13 @@ FunctionalTestRegistry::Catalogue::Catalogue() "2D paracrystal", "isgisaxs04_reference_2DDLh.ima.gz", 2e-10); - add("isgisaxs06_lattice1", + add("isgisaxs06a", "2D lattice with disorders", "isgisaxs06_reference_lattice.ima.gz", 2e-10); - add("isgisaxs06_lattice2", + add("isgisaxs06b", "2D lattice centered", "isgisaxs06_reference_centered.ima.gz", 2e-10); - add("isgisaxs06_lattice3", + add("isgisaxs06c", "2D lattice rotated", "isgisaxs06_reference_rotated.ima.gz", 2e-10); // this test is complicated for given Registry, see Tests/FunctionalTest/TesCore/IsGISAXS06L4 @@ -97,9 +97,13 @@ FunctionalTestRegistry::Catalogue::Catalogue() "Mesocrystals of cylindrical shape composed by spherical nanoparticles", "mesocrystal1_reference_v2_nphi2.txt.gz", 1e-10); - add("PolarizedDWBAZeroMag", + add("magcyl1", "Polarized DWBA with zero magnetic field", "isgi_cylinder_DWBA.ima.gz", 1e-10); + // this test is complicated for given Registry +// add("magcyl2", +// "Polarized DWBA with zero magnetic field", +// "isgi_cylinder_DWBA.ima.gz", 1e-10); add("LayerWithRoughness", "Layers with correlated roughness", diff --git a/Core/StandardSamples/IFunctionalTest.cpp b/Core/StandardSamples/IFunctionalTest.cpp index 5481b99bc9098d36c13f37ace1c741061dd051c9..609cb9862c2014bd9565bf6f906460c174a6a804 100644 --- a/Core/StandardSamples/IFunctionalTest.cpp +++ b/Core/StandardSamples/IFunctionalTest.cpp @@ -49,7 +49,6 @@ void FunctionalTest::runTest() int FunctionalTest::analyseResults() { assert(m_simulation); -// assert(m_result); assert(m_reference); double diff = OutputDataFunctions::GetDifference(*getResult(),*m_reference); diff --git a/Core/StandardSamples/PolarizedDWBAMagCylindersBuilder.cpp b/Core/StandardSamples/PolarizedDWBAMagCylindersBuilder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06b9989da967343d6b07d572c418f56e9d1cd483 --- /dev/null +++ b/Core/StandardSamples/PolarizedDWBAMagCylindersBuilder.cpp @@ -0,0 +1,127 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file StandardSamples/PolarizedDWBAZeroMagBuilder.cpp +//! @brief Implements class PolarizedDWBAZeroMagBuilder +//! +//! @homepage http://apps.jcns.fz-juelich.de/BornAgain +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2013 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "PolarizedDWBAMagCylindersBuilder.h" +#include "MultiLayer.h" +#include "ParticleDecoration.h" +#include "MaterialManager.h" +#include "FormFactorCylinder.h" +#include "Units.h" +#include "InterferenceFunctionNone.h" + + +// ---------------------------------------------------------------------------- +// Magnetic cylinders and zero magnetic field +// ---------------------------------------------------------------------------- + +PolarizedDWBAMagCylinders1Builder::PolarizedDWBAMagCylinders1Builder() + : m_cylinder_height(5*Units::nanometer) + , m_cylinder_radius(5*Units::nanometer) +{ + init_parameters(); +} + + +void PolarizedDWBAMagCylinders1Builder::init_parameters() +{ + clearParameterPool(); + registerParameter("cylinder_height", &m_cylinder_height); + registerParameter("cylinder_raduis", &m_cylinder_radius); +} + + +ISample *PolarizedDWBAMagCylinders1Builder::buildSample() const +{ + MultiLayer *multi_layer = new MultiLayer(); + + kvector_t magnetic_field(0.0, 0.0, 0.0); + const IMaterial *p_air_material = + MaterialManager::getHomogeneousMaterial("Air", 0.0, 0.0); + const IMaterial *p_substrate_material = + MaterialManager::getHomogeneousMaterial("Substrate", 6e-6, 2e-8); + Layer air_layer; + air_layer.setMaterial(p_air_material); + Layer substrate_layer; + substrate_layer.setMaterial(p_substrate_material); + const IMaterial *particle_material = + MaterialManager::getHomogeneousMagneticMaterial( + "MagParticle", 6e-4, 2e-8, magnetic_field); + + ParticleDecoration particle_decoration( + new Particle(particle_material, + new FormFactorCylinder(m_cylinder_height, + m_cylinder_radius))); + + particle_decoration.addInterferenceFunction(new InterferenceFunctionNone()); + + air_layer.setDecoration(particle_decoration); + + multi_layer->addLayer(air_layer); + multi_layer->addLayer(substrate_layer); + return multi_layer; +} + +// ---------------------------------------------------------------------------- +// Magnetic cylinders and non-zero magnetic field +// ---------------------------------------------------------------------------- +PolarizedDWBAMagCylinders2Builder::PolarizedDWBAMagCylinders2Builder() + : m_cylinder_height(5*Units::nanometer) + , m_cylinder_radius(5*Units::nanometer) +{ + init_parameters(); +} + + +void PolarizedDWBAMagCylinders2Builder::init_parameters() +{ + clearParameterPool(); + registerParameter("cylinder_height", &m_cylinder_height); + registerParameter("cylinder_raduis", &m_cylinder_radius); +} + + +ISample *PolarizedDWBAMagCylinders2Builder::buildSample() const +{ + MultiLayer *multi_layer = new MultiLayer(); + + kvector_t magnetic_field(0.0, 1.0, 0.0); + const IMaterial *p_air_material = + MaterialManager::getHomogeneousMaterial("Air", 0.0, 0.0); + const IMaterial *p_substrate_material = + MaterialManager::getHomogeneousMaterial("Substrate", 15e-6, 0.0); + const IMaterial *particle_material = + MaterialManager::getHomogeneousMagneticMaterial( + "MagParticle2", 5e-6, 0.0, magnetic_field); + + + Layer air_layer; + air_layer.setMaterial(p_air_material); + Layer substrate_layer; + substrate_layer.setMaterial(p_substrate_material); + + ParticleDecoration particle_decoration( + new Particle(particle_material, + new FormFactorCylinder(m_cylinder_height, + m_cylinder_radius))); + + particle_decoration.addInterferenceFunction(new InterferenceFunctionNone()); + + air_layer.setDecoration(particle_decoration); + + multi_layer->addLayer(air_layer); + multi_layer->addLayer(substrate_layer); + return multi_layer; +} + diff --git a/Core/StandardSamples/PolarizedDWBAMagCylindersBuilder.h b/Core/StandardSamples/PolarizedDWBAMagCylindersBuilder.h new file mode 100644 index 0000000000000000000000000000000000000000..91c4cbdc705e2f26e30ef0a9082695fd4caef4b5 --- /dev/null +++ b/Core/StandardSamples/PolarizedDWBAMagCylindersBuilder.h @@ -0,0 +1,58 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file StandardSamples/PolarizedDWBAMagCylindersBuilder.h +//! @brief Defines class PolarizedDWBAMagCylinders1Builder +//! +//! @homepage http://apps.jcns.fz-juelich.de/BornAgain +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2013 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef POLARIZEDDWBAMAGCYLINDERSBUILDER_H +#define POLARIZEDDWBAMAGCYLINDERSBUILDER_H + +#include "ISampleBuilder.h" + +//! @class PolarizedDWBAMagCylinders1Builder +//! @ingroup standard_samples +//! @brief Builds sample: cylinders with magnetic material and zero magnetic field. + +class BA_CORE_API_ PolarizedDWBAMagCylinders1Builder : public ISampleBuilder +{ +public: + PolarizedDWBAMagCylinders1Builder(); + ISample *buildSample() const; + +protected: + void init_parameters(); + +private: + double m_cylinder_height; + double m_cylinder_radius; +}; + +//! @class PolarizedDWBAMagCylinders2Builder +//! @ingroup standard_samples +//! @brief Builds sample: cylinders with magnetic material and non-zero magnetic field. + +class BA_CORE_API_ PolarizedDWBAMagCylinders2Builder : public ISampleBuilder +{ +public: + PolarizedDWBAMagCylinders2Builder(); + ISample *buildSample() const; + +protected: + void init_parameters(); + +private: + double m_cylinder_height; + double m_cylinder_radius; +}; + + +#endif // POLARIZEDDWBAMAGCYLINDERSBUILDER_H diff --git a/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.cpp b/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.cpp deleted file mode 100644 index 9486a7949b7c8dd4aa4f899b17e2bb341347aa70..0000000000000000000000000000000000000000 --- a/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file StandardSamples/PolarizedDWBAZeroMagBuilder.cpp -//! @brief Implements class PolarizedDWBAZeroMagBuilder -//! -//! @homepage http://apps.jcns.fz-juelich.de/BornAgain -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#include "PolarizedDWBAZeroMagBuilder.h" -#include "MultiLayer.h" -#include "ParticleDecoration.h" -#include "MaterialManager.h" -#include "FormFactorCylinder.h" -#include "Units.h" -#include "InterferenceFunctionNone.h" - -PolarizedDWBAZeroMagBuilder::PolarizedDWBAZeroMagBuilder() - : m_cylinder_height(5*Units::nanometer) - , m_cylinder_radius(5*Units::nanometer) -{ - init_parameters(); -} - - -void PolarizedDWBAZeroMagBuilder::init_parameters() -{ - clearParameterPool(); - registerParameter("cylinder_height", &m_cylinder_height); - registerParameter("cylinder_raduis", &m_cylinder_radius); -} - - -ISample *PolarizedDWBAZeroMagBuilder::buildSample() const -{ - MultiLayer *multi_layer = new MultiLayer(); - - kvector_t magnetic_field(0.0, 0.0, 0.0); - const IMaterial *p_air_material = - MaterialManager::getHomogeneousMaterial("Air", 0.0, 0.0); - const IMaterial *p_substrate_material = - MaterialManager::getHomogeneousMaterial("Substrate", 6e-6, 2e-8); - Layer air_layer; - air_layer.setMaterial(p_air_material); - Layer substrate_layer; - substrate_layer.setMaterial(p_substrate_material); - const IMaterial *particle_material = - MaterialManager::getHomogeneousMagneticMaterial( - "MagParticle", 6e-4, 2e-8, magnetic_field); - - ParticleDecoration particle_decoration( - new Particle(particle_material, - new FormFactorCylinder(m_cylinder_height, - m_cylinder_radius))); - - particle_decoration.addInterferenceFunction(new InterferenceFunctionNone()); - - air_layer.setDecoration(particle_decoration); - - multi_layer->addLayer(air_layer); - multi_layer->addLayer(substrate_layer); - return multi_layer; -} - diff --git a/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.h b/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.h deleted file mode 100644 index 7d69aa7220f721b5eb74cbe7fc3cb4142285510a..0000000000000000000000000000000000000000 --- a/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.h +++ /dev/null @@ -1,39 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file StandardSamples/PolarizedDWBAZeroMagBuilder.h -//! @brief Defines class PolarizedDWBAZeroMagBuilder -//! -//! @homepage http://apps.jcns.fz-juelich.de/BornAgain -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2013 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#ifndef POLARIZEDDWBAZEROMAGBUILDER_H -#define POLARIZEDDWBAZEROMAGBUILDER_H - -#include "ISampleBuilder.h" - -//! @class PolarizedDWBAZeroMagBuilder -//! @ingroup standard_samples -//! @brief Builds sample: cylinders with magnetic material and zero magnetic field. - -class BA_CORE_API_ PolarizedDWBAZeroMagBuilder : public ISampleBuilder -{ -public: - PolarizedDWBAZeroMagBuilder(); - ISample *buildSample() const; - -protected: - void init_parameters(); - -private: - double m_cylinder_height; - double m_cylinder_radius; -}; - -#endif // ISGISAXS01BUILDER_H diff --git a/Core/StandardSamples/SampleBuilderFactory.cpp b/Core/StandardSamples/SampleBuilderFactory.cpp index 922513e1b9e0b49d245628beba72ea1af3c31ed2..3844f7a0d0b6b43433c03b1197801b0046815ad4 100644 --- a/Core/StandardSamples/SampleBuilderFactory.cpp +++ b/Core/StandardSamples/SampleBuilderFactory.cpp @@ -26,7 +26,7 @@ #include "IsGISAXS11Builder.h" #include "IsGISAXS15Builder.h" #include "MesoCrystal01Builder.h" -#include "PolarizedDWBAZeroMagBuilder.h" +#include "PolarizedDWBAMagCylindersBuilder.h" #include "LayerRoughnessBuilder.h" #include "Ripple2Builder.h" #include "Ripple1Builder.h" @@ -67,19 +67,19 @@ SampleBuilderFactory::SampleBuilderFactory() "IsGISAXS04 example, 2DDL structure factor"); registerItem( - "isgisaxs06_lattice1", + "isgisaxs06a", IFactoryCreateFunction<IsGISAXS06Lattice1Builder, ISampleBuilder>, "2D lattice with disorder"); registerItem( - "isgisaxs06_lattice2", + "isgisaxs06b", IFactoryCreateFunction<IsGISAXS06Lattice2Builder, ISampleBuilder>, "2D lattice centered"); registerItem( - "isgisaxs06_lattice3", + "isgisaxs06c", IFactoryCreateFunction<IsGISAXS06Lattice3Builder, ISampleBuilder>, "2D lattice rotated"); registerItem( - "isgisaxs06_lattice4", + "isgisaxs06d", IFactoryCreateFunction<IsGISAXS06Lattice4Builder, ISampleBuilder>, "2D lattice variants"); @@ -128,9 +128,13 @@ SampleBuilderFactory::SampleBuilderFactory() "Mesocrystals of cylindrical shape composed by spherical nanoparticles"); registerItem( - "PolarizedDWBAZeroMag", - IFactoryCreateFunction<PolarizedDWBAZeroMagBuilder, ISampleBuilder>, + "magcyl1", + IFactoryCreateFunction<PolarizedDWBAMagCylinders1Builder, ISampleBuilder>, "Polarized DWBA with zero magnetic field"); + registerItem( + "magcyl2", + IFactoryCreateFunction<PolarizedDWBAMagCylinders2Builder, ISampleBuilder>, + "Polarized DWBA with non-zero magnetic field"); registerItem( "LayerWithRoughness", diff --git a/Core/StandardSamples/SimulationRegistry.cpp b/Core/StandardSamples/SimulationRegistry.cpp index 0e76a8da69a840d8845aea63c7b0044f11efe3b7..73311707c46e2f2ab336dcaa26d5a4a94cf74b17 100644 --- a/Core/StandardSamples/SimulationRegistry.cpp +++ b/Core/StandardSamples/SimulationRegistry.cpp @@ -45,16 +45,16 @@ SimulationRegistry::SimulationRegistry() "IsGISAXS04 example, 2DDL structure factor"); registerItem( - "isgisaxs06_lattice1", StandardSimulations::IsGISAXS06L1, + "isgisaxs06a", StandardSimulations::IsGISAXS06L1, "2D lattice with disorders"); registerItem( - "isgisaxs06_lattice2", StandardSimulations::IsGISAXS06L2, + "isgisaxs06b", StandardSimulations::IsGISAXS06L2, "2D lattice centered"); registerItem( - "isgisaxs06_lattice3", StandardSimulations::IsGISAXS06L3, + "isgisaxs06c", StandardSimulations::IsGISAXS06L3, "2D lattice rotated"); registerItem( - "isgisaxs06_lattice4", StandardSimulations::IsGISAXS06L4, + "isgisaxs06d", StandardSimulations::IsGISAXS06L4, "2D lattice variants"); registerItem( @@ -91,9 +91,12 @@ SimulationRegistry::SimulationRegistry() "mesocrystal01", StandardSimulations::MesoCrystal01, "Mesocrystals of cylindrical shape composed by spherical nanoparticles"); - registerItem( - "PolarizedDWBAZeroMag", StandardSimulations::PolarizedDWBAZeroMag, + registerItem( + "magcyl1", StandardSimulations::PolarizedDWBAMagCylinders1, "Polarized DWBA with zero magnetic field"); + registerItem( + "magcyl2", StandardSimulations::PolarizedDWBAMagCylinders2, + "Polarized DWBA with non-zero magnetic field"); registerItem( "LayerWithRoughness", StandardSimulations::LayerWithRoughness, diff --git a/Core/StandardSamples/StandardSimulations.cpp b/Core/StandardSamples/StandardSimulations.cpp index 55a6ca41345344d311ac56d9a2cf0f41284f47ca..19d577989fcfe884c6ace8a7aa0f9375acfee782 100644 --- a/Core/StandardSamples/StandardSimulations.cpp +++ b/Core/StandardSamples/StandardSimulations.cpp @@ -149,7 +149,7 @@ Simulation *StandardSimulations::IsGISAXS042DDL() Simulation *StandardSimulations::IsGISAXS06L1() { SampleBuilderFactory factory; - SampleBuilder_t builder = factory.createBuilder("isgisaxs06_lattice1"); + SampleBuilder_t builder = factory.createBuilder("isgisaxs06a"); Simulation *result = new Simulation(); @@ -172,7 +172,7 @@ Simulation *StandardSimulations::IsGISAXS06L1() Simulation *StandardSimulations::IsGISAXS06L2() { SampleBuilderFactory factory; - SampleBuilder_t builder = factory.createBuilder("isgisaxs06_lattice2"); + SampleBuilder_t builder = factory.createBuilder("isgisaxs06b"); Simulation *result = new Simulation(); @@ -195,7 +195,7 @@ Simulation *StandardSimulations::IsGISAXS06L2() Simulation *StandardSimulations::IsGISAXS06L3() { SampleBuilderFactory factory; - SampleBuilder_t builder = factory.createBuilder("isgisaxs06_lattice3"); + SampleBuilder_t builder = factory.createBuilder("isgisaxs06c"); Simulation *result = new Simulation(); @@ -218,7 +218,7 @@ Simulation *StandardSimulations::IsGISAXS06L3() Simulation *StandardSimulations::IsGISAXS06L4() { SampleBuilderFactory factory; - SampleBuilder_t builder = factory.createBuilder("isgisaxs06_lattice4"); + SampleBuilder_t builder = factory.createBuilder("isgisaxs06d"); Simulation *result = new Simulation(); @@ -405,10 +405,10 @@ Simulation *StandardSimulations::MesoCrystal01() } -Simulation *StandardSimulations::PolarizedDWBAZeroMag() +Simulation *StandardSimulations::PolarizedDWBAMagCylinders1() { SampleBuilderFactory factory; - SampleBuilder_t builder = factory.createBuilder("PolarizedDWBAZeroMag"); + SampleBuilder_t builder = factory.createBuilder("magcyl1"); Simulation *result = new Simulation(); @@ -423,6 +423,28 @@ Simulation *StandardSimulations::PolarizedDWBAZeroMag() return result; } + +Simulation *StandardSimulations::PolarizedDWBAMagCylinders2() +{ + SampleBuilderFactory factory; + SampleBuilder_t builder = factory.createBuilder("magcyl2"); + + Simulation *result = new Simulation(); + + + result->setDetectorParameters( + 100, -1.0*Units::degree, 1.0*Units::degree, 100, + 0.0*Units::degree, 2.0*Units::degree, true); + result->setBeamParameters( + 1.0*Units::angstrom, 0.2*Units::degree, 0.0*Units::degree); + result->setBeamIntensity(1e7); + + result->setSampleBuilder( builder ); + + return result; +} + + Simulation *StandardSimulations::LayerWithRoughness() { SampleBuilderFactory factory; diff --git a/Core/StandardSamples/StandardSimulations.h b/Core/StandardSamples/StandardSimulations.h index 49de98d46040b2436c29cc8695a1e04429bdab2d..036cb37713e5f70026857d2956a102c53f366133 100644 --- a/Core/StandardSamples/StandardSimulations.h +++ b/Core/StandardSamples/StandardSimulations.h @@ -43,7 +43,8 @@ Simulation *IsGISAXS10(); Simulation *IsGISAXS11(); Simulation *IsGISAXS15(); Simulation *MesoCrystal01(); -Simulation *PolarizedDWBAZeroMag(); +Simulation *PolarizedDWBAMagCylinders1(); +Simulation *PolarizedDWBAMagCylinders2(); Simulation *LayerWithRoughness(); Simulation *Ripple2(); Simulation *Ripple1(); diff --git a/Tests/FunctionalTests/TestCore/CMakeLists.txt b/Tests/FunctionalTests/TestCore/CMakeLists.txt index 446894723753ee6b9e9ea03415dd314d40e5c473..04773072944867f38cc2ea6456f58c893eb8fe3d 100644 --- a/Tests/FunctionalTests/TestCore/CMakeLists.txt +++ b/Tests/FunctionalTests/TestCore/CMakeLists.txt @@ -26,7 +26,8 @@ set(list_of_tests "IsGISAXS15" "FormFactors" "MesoCrystal1" - "PolarizedDWBAZeroMag" + "PolDWBAMagCylinders1" + "PolDWBAMagCylinders2" "LayerRoughness" "Ripple2" "Ripple1" diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS06L1/IsGISAXS06L1.cpp b/Tests/FunctionalTests/TestCore/IsGISAXS06L1/IsGISAXS06L1.cpp index f61817056d4ad1ea669e46c73d815c1336510eab..a3949dd16304c101b44d8029005a29d8cbea5a0c 100644 --- a/Tests/FunctionalTests/TestCore/IsGISAXS06L1/IsGISAXS06L1.cpp +++ b/Tests/FunctionalTests/TestCore/IsGISAXS06L1/IsGISAXS06L1.cpp @@ -4,6 +4,6 @@ int main(int argc, char **argv) { if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); - return FUNCTIONAL_TEST("isgisaxs06_lattice1"); + return FUNCTIONAL_TEST("isgisaxs06a"); } diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS06L2/IsGISAXS06L2.cpp b/Tests/FunctionalTests/TestCore/IsGISAXS06L2/IsGISAXS06L2.cpp index 34b753bc1b722129575acd0c47047beeebc79ef8..a9da58d5af2f236024a47a8bf9ba578d334256b7 100644 --- a/Tests/FunctionalTests/TestCore/IsGISAXS06L2/IsGISAXS06L2.cpp +++ b/Tests/FunctionalTests/TestCore/IsGISAXS06L2/IsGISAXS06L2.cpp @@ -4,5 +4,5 @@ int main(int argc, char **argv) { if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); - return FUNCTIONAL_TEST("isgisaxs06_lattice2"); + return FUNCTIONAL_TEST("isgisaxs06b"); } diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS06L3/IsGISAXS06L3.cpp b/Tests/FunctionalTests/TestCore/IsGISAXS06L3/IsGISAXS06L3.cpp index 33223ff2fd6b81c55266f0d8448289b91a726968..5d8233e480e2eeeafc18aa39fdf313b7f488d535 100644 --- a/Tests/FunctionalTests/TestCore/IsGISAXS06L3/IsGISAXS06L3.cpp +++ b/Tests/FunctionalTests/TestCore/IsGISAXS06L3/IsGISAXS06L3.cpp @@ -4,5 +4,5 @@ int main(int argc, char **argv) { if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); - return FUNCTIONAL_TEST("isgisaxs06_lattice3"); + return FUNCTIONAL_TEST("isgisaxs06c"); } diff --git a/Tests/FunctionalTests/TestCore/IsGISAXS06L4/IsGISAXS06L4.cpp b/Tests/FunctionalTests/TestCore/IsGISAXS06L4/IsGISAXS06L4.cpp index da40bb13fc0e80f8dd06ddc1ea242bc6b9592372..20c6a975c4a60028b0b8ccbd4c5c1e759a641046 100644 --- a/Tests/FunctionalTests/TestCore/IsGISAXS06L4/IsGISAXS06L4.cpp +++ b/Tests/FunctionalTests/TestCore/IsGISAXS06L4/IsGISAXS06L4.cpp @@ -10,7 +10,7 @@ int main(int argc, char **argv) if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); SimulationRegistry sim_registry; - Simulation* simulation = sim_registry.createSimulation("isgisaxs06_lattice4"); + Simulation* simulation = sim_registry.createSimulation("isgisaxs06d"); // loading reference data std::string filename = Utils::FileSystem::GetReferenceDataDir() + "isgisaxs06_reference_variants.ima.gz"; diff --git a/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.cpp b/Tests/FunctionalTests/TestCore/PolDWBAMagCylinders1/PolDWBAMagCylinders1.cpp similarity index 75% rename from Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.cpp rename to Tests/FunctionalTests/TestCore/PolDWBAMagCylinders1/PolDWBAMagCylinders1.cpp index 7047f5df93291eb96fe64ef49386ff1449de5baf..217180eb3eacd8a179b547711079a16424f09aa7 100644 --- a/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.cpp +++ b/Tests/FunctionalTests/TestCore/PolDWBAMagCylinders1/PolDWBAMagCylinders1.cpp @@ -4,5 +4,5 @@ int main(int argc, char **argv) { if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); - return FUNCTIONAL_TEST("PolarizedDWBAZeroMag"); + return FUNCTIONAL_TEST("magcyl1"); } diff --git a/Tests/FunctionalTests/TestCore/PolDWBAMagCylinders2/PolDWBAMagCylinders2.cpp b/Tests/FunctionalTests/TestCore/PolDWBAMagCylinders2/PolDWBAMagCylinders2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b89233340d168f8bc08be0c574e691f10d21970 --- /dev/null +++ b/Tests/FunctionalTests/TestCore/PolDWBAMagCylinders2/PolDWBAMagCylinders2.cpp @@ -0,0 +1,43 @@ +#include "FunctionalTestRegistry.h" +#include "FileSystem.h" +#include "OutputDataFunctions.h" +#include "OutputDataIOFactory.h" +#include "SimulationRegistry.h" + +int main(int argc, char **argv) +{ + if(argc == 2) Utils::FileSystem::SetReferenceDataDir(argv[1]); + + SimulationRegistry sim_registry; + Simulation* simulation = sim_registry.createSimulation("magcyl2"); + simulation->runSimulation(); + simulation->normalize(); + + OutputData<double> *reference00 = OutputDataIOFactory::readIntensityData(Utils::FileSystem::GetReferenceDataDir()+ "magcyl2_reference_00.txt.gz"); + OutputData<double> *reference01 = OutputDataIOFactory::readIntensityData(Utils::FileSystem::GetReferenceDataDir()+ "magcyl2_reference_01.txt.gz"); + OutputData<double> *reference10 = OutputDataIOFactory::readIntensityData(Utils::FileSystem::GetReferenceDataDir()+ "magcyl2_reference_10.txt.gz"); + OutputData<double> *reference11 = OutputDataIOFactory::readIntensityData(Utils::FileSystem::GetReferenceDataDir()+ "magcyl2_reference_11.txt.gz"); + + const double threshold(2e-10); + double diff(0); + diff += OutputDataFunctions::GetDifference(*simulation->getPolarizedIntensityData(0,0),*reference00); + diff += OutputDataFunctions::GetDifference(*simulation->getPolarizedIntensityData(0,1),*reference01); + diff += OutputDataFunctions::GetDifference(*simulation->getPolarizedIntensityData(1,0),*reference10); + diff += OutputDataFunctions::GetDifference(*simulation->getPolarizedIntensityData(1,1),*reference11); + diff /= 4.; + + delete simulation; + delete reference00; + delete reference01; + delete reference10; + delete reference11; + + // Assess result. + bool status_ok(true); + if( diff > threshold ) status_ok=false; + + std::cout << " diff " << diff << std::endl; + std::cout << "magcyl2" << " " << "Magnetic cylinders with non-zero magnetic field" << " " << + (status_ok ? "[OK]" : "[FAILED]") << std::endl; + return (status_ok ? 0 : 1); +} diff --git a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt index f031c6748c86d7d3ed86be72877584d290b7ea5e..22d93defab844a4f27aa09a5cca94f6831c913f9 100644 --- a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt +++ b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt @@ -16,7 +16,8 @@ set(list_of_tests "isgisaxs11.py" "isgisaxs15.py" "mesocrystal1.py" - "polarizeddwbazeromag.py" + "polmagcylinders1.py" + "polmagcylinders2.py" "layerwithroughness.py" "ripple2.py" "ripple2a.py" diff --git a/Tests/FunctionalTests/TestPyCore/polarizeddwbazeromag.py b/Tests/FunctionalTests/TestPyCore/polmagcylinders1.py similarity index 53% rename from Tests/FunctionalTests/TestPyCore/polarizeddwbazeromag.py rename to Tests/FunctionalTests/TestPyCore/polmagcylinders1.py index 99d7d9d477ddbaa407fef0b90bca32003b300ee4..c735d0e9b9554cf2cfb5979af5023f65663937d0 100644 --- a/Tests/FunctionalTests/TestPyCore/polarizeddwbazeromag.py +++ b/Tests/FunctionalTests/TestPyCore/polmagcylinders1.py @@ -1,8 +1,10 @@ -# IsGISAXS01 example: Mixture of cylinders and prisms without interference +# Magnetic cylinders in DWBA with zero magnetic field import sys import os import numpy import gzip +from utils import get_difference +from utils import get_reference_data sys.path.append(os.path.abspath( os.path.join(os.path.split(__file__)[0], @@ -17,10 +19,10 @@ from libBornAgainCore import * # ---------------------------------- def RunSimulation(): # defining materials - mAmbience = MaterialManager.getHomogeneousMaterial("Air", 0.0, 0.0 ) - mSubstrate = MaterialManager.getHomogeneousMaterial("Substrate", 6e-6, 2e-8 ) + mAmbience = MaterialManager.getHomogeneousMaterial("Air", 0.0, 0.0) + mSubstrate = MaterialManager.getHomogeneousMaterial("Substrate", 6e-6, 2e-8) - magnetic_field = kvector_t(0,0,0) + magnetic_field = kvector_t(0, 0, 0) magParticle = MaterialManager.getHomogeneousMagneticMaterial("magParticle", 6e-4, 2e-8, magnetic_field ) # collection of particles @@ -47,58 +49,25 @@ def RunSimulation(): simulation.setSample(multi_layer) simulation.runSimulation() ## intensity data - return simulation.getIntensityData().getArray() - -# ---------------------------------- -# read reference data from file -# ---------------------------------- -def GetReferenceData(): - path = os.path.split(__file__)[0] - if path: path +="/" - f = gzip.open(path+'../../ReferenceData/BornAgain/isgi_cylinder_DWBA.ima.gz', 'rb') - reference=numpy.fromstring(f.read(),numpy.float64,sep=' ') - f.close() - return reference - - -# -------------------------------------------------------------- -# calculate numeric difference between result and reference data -# -------------------------------------------------------------- -def GetDifference(data, reference): - reference = reference.reshape(data.shape) - # calculating relative average difference - data -= reference - diff=0.0 - epsilon = sys.float_info.epsilon - for x, y in numpy.ndindex(data.shape): - v1 = data[x][y] - v2 = reference[x][y] - if v1 <= epsilon and v2 <= epsilon: - diff += 0.0 - elif(v2 <= epsilon): - diff += abs(v1/epsilon) - else: - diff += abs(v1/v2) - return diff/data.size + return simulation.getIntensityData() # -------------------------------------------------------------- # run test and analyse test results # -------------------------------------------------------------- -def runTest(): +def run_test(): result = RunSimulation() - reference = GetReferenceData() + reference = get_reference_data('isgi_cylinder_DWBA.ima.gz') - diff = GetDifference(result, reference) + diff = get_difference(result.getArray(), reference.getArray()) status = "OK" - if(diff > 2e-10 or numpy.isnan(diff)): status = "FAILED" + if diff > 2e-10: + status = "FAILED" return "PolarizedDWBAZeroMag", "functional test: polarized DWBA with zero magnetic field", status -#------------------------------------------------------------- -# main() -#------------------------------------------------------------- if __name__ == '__main__': - name,description,status = runTest() - print name,description,status - if("FAILED" in status) : exit(1) + name, description, status = run_test() + print name, description, status + if "FAILED" in status: + exit(1) diff --git a/Tests/FunctionalTests/TestPyCore/polmagcylinders2.py b/Tests/FunctionalTests/TestPyCore/polmagcylinders2.py new file mode 100644 index 0000000000000000000000000000000000000000..85923b6506c40ba9a963c6acdbb1c97c7b1f74fd --- /dev/null +++ b/Tests/FunctionalTests/TestPyCore/polmagcylinders2.py @@ -0,0 +1,78 @@ +# Magnetic cylinders in DWBA with zero magnetic field +import sys +import os +import numpy +import gzip +from utils import get_difference +from utils import get_reference_data + +sys.path.append(os.path.abspath( + os.path.join(os.path.split(__file__)[0], + '..', '..', '..', 'lib'))) + + +from libBornAgainCore import * + + +# ---------------------------------- +# describe sample and run simulation +# ---------------------------------- +def RunSimulation(): + # defining materials + mAmbience = MaterialManager.getHomogeneousMaterial("Air", 0.0, 0.0) + mSubstrate = MaterialManager.getHomogeneousMaterial("Substrate", 15e-6, 0.0) + + magnetic_field = kvector_t(0, 1, 0) + + magParticle = MaterialManager.getHomogeneousMagneticMaterial("magParticle", 5e-6, 0.0, magnetic_field ) + # collection of particles + cylinder_ff = FormFactorCylinder(5*nanometer, 5*nanometer) + cylinder = Particle(magParticle, cylinder_ff) + + particle_decoration = ParticleDecoration() + particle_decoration.addParticle(cylinder, 0.0, 1.0) + interference = InterferenceFunctionNone() + particle_decoration.addInterferenceFunction(interference) + + # air layer with particles and substrate form multi layer + air_layer = Layer(mAmbience) + air_layer.setDecoration(particle_decoration) + substrate_layer = Layer(mSubstrate, 0) + multi_layer = MultiLayer() + multi_layer.addLayer(air_layer) + multi_layer.addLayer(substrate_layer) + + # build and run experiment + simulation = Simulation() + simulation.setDetectorParameters(100, -1*degree, 1.0*degree, 100, 0.0*degree, 2.0*degree, True) + simulation.setBeamParameters(1.0*angstrom, 0.2*degree, 0.0*degree) + simulation.setSample(multi_layer) + simulation.setBeamIntensity(1e7) + simulation.runSimulation() + simulation.normalize() + return simulation + + +# -------------------------------------------------------------- +# run test and analyse test results +# -------------------------------------------------------------- +def run_test(): + simulation = RunSimulation() + + diff = 0.0 + diff += get_difference(simulation.getPolarizedIntensityData(0, 0).getArray(), get_reference_data('magcyl2_reference_00.txt.gz').getArray()) + diff += get_difference(simulation.getPolarizedIntensityData(0, 1).getArray(), get_reference_data('magcyl2_reference_01.txt.gz').getArray()) + diff += get_difference(simulation.getPolarizedIntensityData(1, 0).getArray(), get_reference_data('magcyl2_reference_10.txt.gz').getArray()) + diff += get_difference(simulation.getPolarizedIntensityData(1, 1).getArray(), get_reference_data('magcyl2_reference_11.txt.gz').getArray()) + diff /= 4.0 + status = "OK" + if diff > 2e-10: + status = "FAILED" + return "PolarizedDWBAZeroMag", "functional test: polarized DWBA with non-zero magnetic field", status + + +if __name__ == '__main__': + name, description, status = run_test() + print name, description, status + if "FAILED" in status: + exit(1) diff --git a/Tests/FunctionalTests/TestPyCore/utils.py b/Tests/FunctionalTests/TestPyCore/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..2f31c5770f992b6a9ad40ee9fbca20703c917475 --- /dev/null +++ b/Tests/FunctionalTests/TestPyCore/utils.py @@ -0,0 +1,48 @@ +""" +Collection of utils for testing +""" +import sys +import numpy +import gzip +import os +from libBornAgainCore import * + + +def get_difference(data, reference): + """ + calculate numeric difference between result and reference data + """ + reference = reference.reshape(data.shape) + data -= reference + diff = 0.0 + epsilon = sys.float_info.epsilon + for x, y in numpy.ndindex(data.shape): + v1 = data[x][y] + v2 = reference[x][y] + if v1 <= epsilon and v2 <= epsilon: + diff += 0.0 + elif v2 <= epsilon: + diff += abs(v1/epsilon) + else: + diff += abs(v1/v2) + diff = diff/data.size + if numpy.isnan(diff): + raise Exception("get_difference", "isnan") + + return diff + + +def get_reference_data(filename): + """ + read and return reference data from file + """ + path = os.path.split(__file__)[0] + if path: + path += "/" + #f = gzip.open(path+'../../ReferenceData/BornAgain/'+filename, 'rb') + #reference = numpy.fromstring(f.read(), numpy.float64, sep=' ') + #f.close() + #return reference + return OutputDataIOFactory.readIntensityData(path+'../../ReferenceData/BornAgain/'+filename) + + diff --git a/Tests/ReferenceData/BornAgain/magcyl2_reference_00.txt.gz b/Tests/ReferenceData/BornAgain/magcyl2_reference_00.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..c7a017aa4f85ee15b227ae7b100010fdf2cccddd Binary files /dev/null and b/Tests/ReferenceData/BornAgain/magcyl2_reference_00.txt.gz differ diff --git a/Tests/ReferenceData/BornAgain/magcyl2_reference_01.txt.gz b/Tests/ReferenceData/BornAgain/magcyl2_reference_01.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..421bab86f65508d61f6f080bb36c5aa4fb373881 Binary files /dev/null and b/Tests/ReferenceData/BornAgain/magcyl2_reference_01.txt.gz differ diff --git a/Tests/ReferenceData/BornAgain/magcyl2_reference_10.txt.gz b/Tests/ReferenceData/BornAgain/magcyl2_reference_10.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..28ce1f5643b7b5316cbfdc13190ffc41eac8bc43 Binary files /dev/null and b/Tests/ReferenceData/BornAgain/magcyl2_reference_10.txt.gz differ diff --git a/Tests/ReferenceData/BornAgain/magcyl2_reference_11.txt.gz b/Tests/ReferenceData/BornAgain/magcyl2_reference_11.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..471338aa097ad3c3f8ed7a1195528f823e36f811 Binary files /dev/null and b/Tests/ReferenceData/BornAgain/magcyl2_reference_11.txt.gz differ diff --git a/dev-tools/log/perf_history.txt b/dev-tools/log/perf_history.txt index 6d82ea184f84d634851ba9847b1230d765d8c095..573fc263b18275a038e5a1d062ed0f3833b845e4 100644 --- a/dev-tools/log/perf_history.txt +++ b/dev-tools/log/perf_history.txt @@ -300,3 +300,31 @@ 2013-12-19 16:11:26 | jcnsopc73 | macosx64, 2800 MHz | 21.7391 | 21.2766 | 0.0319387 | 769231 | # Release 0.9.3 2013-12-20 10:28:13 | jcnsopc73 | macosx64, 2800 MHz | 21.0526 | 20.8333 | 0.0310078 | 666667 | + +# ------------------------------------------------------------------------------------------------------------------ +# switching to another performance test +# ------------------------------------------------------------------------------------------------------------------ + +# repeating old performance measurements --performance1 +# Gennady's OpenSuse +# nthreads=8 +2014-01-13 16:30:06 | jcnsopc126 | linuxx8664gcc, 3502 MHz | 8.03213 | 8.19672 | 0.0166389 | 1e+06 | +# Gennady's Maverick +# nthreads=0 +2014-01-13 16:46:39 | jcnsopc73 | macosx64, 2800 MHz | 7.7821 | 7.75194 | 0.0174368 | 740741 | +# nthreads=1 +2014-01-13 16:53:12 | jcnsopc73 | macosx64, 2800 MHz | 14.1844 | 14.1844 | 0.0289268 | 740741 | + + +# new performance --performance2 + +# Gennady's OpenSuse +| date | hostname | sysinfo | tr | total | isgisaxs02 | isgisaxs06a | isgisaxs09b | isgisaxs11 | isgisaxs15 | mesocrystal0 | specmatrix | specmagnetic | magcyl2 | +| 2014-01-13 16:30:20 | jcnsopc126 | linuxx8664gcc | 0 | 30.329 | 2.295 | 1.813 | 1.116 | 0.675 | 5.810 | 8.452 | 0.509 | 7.759 | 1.900 | +# Gennady's Maverick +| date | hostname | sysinfo | tr | total | isgisaxs02 | isgisaxs06a | isgisaxs09b | isgisaxs11 | isgisaxs15 | mesocrystal0 | specmatrix | specmagnetic | magcyl2 | +| 2014-01-13 16:47:59 | jcnsopc73 | macosx64 | 0 | 60.978 | 5.024 | 1.488 | 1.735 | 0.976 | 11.958 | 17.915 | 0.647 | 18.293 | 2.942 | +| 2014-01-13 16:50:24 | jcnsopc73 | macosx64 | 1 | 103.614 | 11.405 | 3.240 | 3.539 | 1.832 | 26.159 | 33.044 | 0.681 | 17.896 | 5.817 | + + + diff --git a/dev-tools/python-bindings/MakePyCore.py b/dev-tools/python-bindings/MakePyCore.py index fab092aa2c13ad2187a51fe662d7894972fed2c0..da9eb1749fe8d78eacd4944cc34af3ac4689c476 100644 --- a/dev-tools/python-bindings/MakePyCore.py +++ b/dev-tools/python-bindings/MakePyCore.py @@ -234,7 +234,7 @@ def ManualClassTunings(mb): # cl = mb.class_("ParticleDecoration") - cl.constructors(lambda decl: bool(decl.arguments)).exclude() # exclude non-default constructors + #cl.constructors(lambda decl: bool(decl.arguments)).exclude() # exclude non-default constructors # cl = mb.class_("ParameterPool") cl.member_function("registerParameter").add_transformation(builder_utils.from_address_custom(1))