diff --git a/App/inc/StandardSamples.h b/App/inc/StandardSamples.h index 310d579b14b3dc26790f8c0528b28910a4263885..616dabbff32b673ccdb514b865fdec3c321c0e09 100644 --- a/App/inc/StandardSamples.h +++ b/App/inc/StandardSamples.h @@ -32,7 +32,7 @@ ISample *MultilayerOffspecTestcase2a(); ISample *MultilayerOffspecTestcase2b(); ISample *MultilayerSpecularMagneticTestCase(); ISample *PolarizedDWBATestCase(); -ISample *PolarizedDWBAZeroMagTestCase(); +//ISample *PolarizedDWBAZeroMagTestCase(); ISample *IsGISAXS7_morphology(); ISample *IsGISAXS8_2DDL_lattice(); diff --git a/App/inc/TestPolarizedDWBAZeroMag.h b/App/inc/TestPolarizedDWBAZeroMag.h index 54c41963eab6d55a6b5d4785e8ac76dc59f7856b..66e66f91f1254c8d53098a830575c52944bafad0 100644 --- a/App/inc/TestPolarizedDWBAZeroMag.h +++ b/App/inc/TestPolarizedDWBAZeroMag.h @@ -47,6 +47,8 @@ private: }; std::string m_data_path; + OutputData<double> *m_result; + }; #endif /* TESTPOLARIZEDDWBAZEROMAG_H_ */ diff --git a/App/src/SampleFactory.cpp b/App/src/SampleFactory.cpp index 9a500bfa6b8b784cddd4bb758c0e68df8f365f73..31b7f76dd8d54de12646afac494487b7c2f68f21 100644 --- a/App/src/SampleFactory.cpp +++ b/App/src/SampleFactory.cpp @@ -55,8 +55,8 @@ SampleFactory::SampleFactory() StandardSamples::PolarizedDWBATestCase); // cylinder DWBA form factor with matrix calculation - registerItem("PolarizedDWBAZeroMagTestCase", - StandardSamples::PolarizedDWBAZeroMagTestCase); + // registerItem("PolarizedDWBAZeroMagTestCase", + // StandardSamples::PolarizedDWBAZeroMagTestCase); // IsGISAXS7 example: particle mixture from morphology file registerItem("IsGISAXS7_mor", StandardSamples::IsGISAXS7_morphology); diff --git a/App/src/StandardSamples.cpp b/App/src/StandardSamples.cpp index 8c3b95fbab3af2eadd7bbe199b345c43762dc8a4..8bed99cc14ff5b0f3d9ddba611f378ad89f3dfee 100644 --- a/App/src/StandardSamples.cpp +++ b/App/src/StandardSamples.cpp @@ -1184,37 +1184,37 @@ ISample *StandardSamples::PolarizedDWBATestCase() return mySample; } -ISample *StandardSamples::PolarizedDWBAZeroMagTestCase() -{ - 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( - "Particle", 6e-4, 2e-8, magnetic_field); - - ParticleDecoration particle_decoration( - new Particle(particle_material, - new FormFactorCylinder(5*Units::nanometer, - 5*Units::nanometer))); - - particle_decoration.addInterferenceFunction(new InterferenceFunctionNone()); - - air_layer.setDecoration(particle_decoration); - - multi_layer->addLayer(air_layer); - multi_layer->addLayer(substrate_layer); - - return multi_layer; -} +//ISample *StandardSamples::PolarizedDWBAZeroMagTestCase() +//{ + // 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( +// "Particle", 6e-4, 2e-8, magnetic_field); +// +// ParticleDecoration particle_decoration( +// new Particle(particle_material, + // new FormFactorCylinder(5*Units::nanometer, + // 5*Units::nanometer))); +// +// 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/App/src/TestDiffuseReflection.cpp b/App/src/TestDiffuseReflection.cpp index 172143db28a4d443ee0a1e267ff503814f7328df..3c680d995bd27083ea0c42d2e57bb4137e08254a 100644 --- a/App/src/TestDiffuseReflection.cpp +++ b/App/src/TestDiffuseReflection.cpp @@ -31,6 +31,7 @@ #include "TApplication.h" #include "TStyle.h" #include "TProfile2D.h" +#include "BornAgainNamespace.h" TestDiffuseReflection::TestDiffuseReflection() @@ -93,14 +94,14 @@ void TestDiffuseReflection::execute() // offspecular reflectivity m_data_offspec = new OutputData<double >; m_data_offspec->addAxis(std::string("alpha_i"), m_npoints, m_alphaMin, m_alphaMax); - m_data_offspec->addAxis("alpha_f", m_npoints, m_alphaMin, m_alphaMax); + m_data_offspec->addAxis(BA::ALPHA_AXIS_NAME, m_npoints, m_alphaMin, m_alphaMax); OutputData<double>::iterator it = m_data_offspec->begin(); while (it != m_data_offspec->end()) { double alpha_i = m_data_offspec->getValueOfAxis("alpha_i", it.getIndex()); - double alpha_f = m_data_offspec->getValueOfAxis("alpha_f", it.getIndex()); + double alpha_f = m_data_offspec->getValueOfAxis(BA::ALPHA_AXIS_NAME, it.getIndex()); size_t index_alpha_i = m_data_offspec->getIndexOfAxis("alpha_i", it.getIndex()); - size_t index_alpha_f = m_data_offspec->getIndexOfAxis("alpha_f", it.getIndex()); + size_t index_alpha_f = m_data_offspec->getIndexOfAxis(BA::ALPHA_AXIS_NAME, it.getIndex()); ki.setLambdaAlphaPhi(1.54*Units::angstrom, -alpha_i, 0.0); kf.setLambdaAlphaPhi(1.54*Units::angstrom, alpha_f, 0.0); calc.execute(*m_sample, ki, kf); @@ -189,9 +190,9 @@ void TestDiffuseReflection::draw() OutputData<double>::const_iterator it = m_data_offspec->begin(); while (it != m_data_offspec->end()) { double alpha_i = m_data_offspec->getValueOfAxis("alpha_i", it.getIndex()); - double alpha_f = m_data_offspec->getValueOfAxis("alpha_f", it.getIndex()); + double alpha_f = m_data_offspec->getValueOfAxis(BA::ALPHA_AXIS_NAME, it.getIndex()); size_t index_alpha_i = m_data_offspec->getIndexOfAxis("alpha_i", it.getIndex()); - size_t index_alpha_f = m_data_offspec->getIndexOfAxis("alpha_f", it.getIndex()); + size_t index_alpha_f = m_data_offspec->getIndexOfAxis(BA::ALPHA_AXIS_NAME, it.getIndex()); double r = *it++; hspect.Fill(r); if(index_alpha_i==5) { diff --git a/App/src/TestFormFactor.cpp b/App/src/TestFormFactor.cpp index c0fc248a465f46990f67e37f5c1e8a67d513d0f9..d1834c3e0463f5b9d09363bcb2e5392345df0520 100644 --- a/App/src/TestFormFactor.cpp +++ b/App/src/TestFormFactor.cpp @@ -20,6 +20,7 @@ #include "TCanvas.h" #include "TH2.h" #include "TStyle.h" +#include "BornAgainNamespace.h" #include <cmath> #include <iostream> diff --git a/App/src/TestMiscellaneous.cpp b/App/src/TestMiscellaneous.cpp index ce1ff7e224a93eaf3d5018b0c5352ddbe414a537..6856f56fecb50f502b4a610224979a26f07c88bd 100644 --- a/App/src/TestMiscellaneous.cpp +++ b/App/src/TestMiscellaneous.cpp @@ -34,6 +34,7 @@ #include "SampleBuilderFactory.h" #include "SamplePrintVisitor.h" #include "MaterialManager.h" +#include "BornAgainNamespace.h" #include "TGraph.h" #include "TH2D.h" @@ -126,16 +127,16 @@ void TestMiscellaneous::test_OutputDataTo2DArray() int axis0_size = 2; int axis1_size = 4; OutputData<double> *p_output = new OutputData<double>; - p_output->addAxis("phi_f", axis0_size, 0.0, double(axis0_size)); - p_output->addAxis("alpha_f", axis1_size, 0.0, double(axis1_size)); + p_output->addAxis(BA::PHI_AXIS_NAME, axis0_size, 0.0, double(axis0_size)); + p_output->addAxis(BA::ALPHA_AXIS_NAME, axis1_size, 0.0, double(axis1_size)); p_output->setAllTo(0.0); OutputData<double>::iterator it = p_output->begin(); int nn=0; while (it != p_output->end()) { - size_t index0 = p_output->getIndexOfAxis("phi_f", it.getIndex()); - size_t index1 = p_output->getIndexOfAxis("alpha_f", it.getIndex()); + size_t index0 = p_output->getIndexOfAxis(BA::PHI_AXIS_NAME, it.getIndex()); + size_t index1 = p_output->getIndexOfAxis(BA::ALPHA_AXIS_NAME, it.getIndex()); std::cout << " index0:" << index0 << " index1:" << index1 << std::endl; *it = nn++; ++it; diff --git a/App/src/TestPolarizedDWBAZeroMag.cpp b/App/src/TestPolarizedDWBAZeroMag.cpp index eec915c8deaba30fb3ea99da800cc0f67a54ee73..6e2f572926963c083c7eff0730b4667e73d43e6a 100644 --- a/App/src/TestPolarizedDWBAZeroMag.cpp +++ b/App/src/TestPolarizedDWBAZeroMag.cpp @@ -20,6 +20,7 @@ #include "Simulation.h" #include "Units.h" #include "Utils.h" +#include "SimulationRegistry.h" TestPolarizedDWBAZeroMag::TestPolarizedDWBAZeroMag() : IFunctionalTest("TestPolarizedDWBAZeroMag") @@ -32,44 +33,52 @@ TestPolarizedDWBAZeroMag::TestPolarizedDWBAZeroMag() void TestPolarizedDWBAZeroMag::execute() { // building simulation - Simulation simulation(mp_options); - simulation.setDetectorParameters(100, 0.0*Units::degree, 2.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 simulation(mp_options); + //simulation.setDetectorParameters(100, 0.0*Units::degree, 2.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); + + SimulationRegistry sim_registry; + Simulation *simulation = sim_registry.createSimulation("PolarizedDWBAZeroMag"); + // test1 - ISample *sample = SampleFactory::createSample( - "PolarizedDWBAZeroMagTestCase"); - simulation.setSample(*sample); - simulation.runSimulation(); - OutputDataIOFactory::writeIntensityData(*simulation.getOutputData(), - "this_cylinder_DWBA_pol.ima"); - delete sample; +// ISample *sample = SampleFactory::createSample( +// "PolarizedDWBAZeroMagTestCase"); +// simulation.setSample(*sample); + + simulation->runSimulation(); + m_result = simulation->getIntensityData(); + +// OutputDataIOFactory::writeIntensityData(*m_result, +// "this_cylinder_DWBA_pol.ima"); +// delete sample; } void TestPolarizedDWBAZeroMag::finalise() { - std::vector< CompareStruct > tocompare; - tocompare.push_back( CompareStruct( - getOutputPath()+"isgi_cylinder_DWBA.ima.gz", - "this_cylinder_DWBA_pol.ima", - "Cylinder DWBA Formfactor with matrix calculation") ); - - for(size_t i=0; i<tocompare.size(); ++i) { - OutputData<double> *isgi_data = OutputDataIOFactory::readIntensityData( - tocompare[i].isginame); - OutputData<double> *our_data = OutputDataIOFactory::readIntensityData( - tocompare[i].thisname); - - IsGISAXSTools::drawOutputDataComparisonResults(*our_data, *isgi_data, - tocompare[i].descr, tocompare[i].descr); - - delete isgi_data; - delete our_data; - } +// std::vector< CompareStruct > tocompare; +// tocompare.push_back( CompareStruct( +// getOutputPath()+"isgi_cylinder_DWBA.ima.gz", +// "this_cylinder_DWBA_pol.ima", +// "Cylinder DWBA Formfactor with matrix calculation") ); + +// for(size_t i=0; i<tocompare.size(); ++i) { +// OutputData<double> *isgi_data = OutputDataIOFactory::readIntensityData( +// tocompare[i].isginame); +// OutputData<double> *our_data = OutputDataIOFactory::readIntensityData( +// tocompare[i].thisname); + + OutputData<double> *reference = OutputDataIOFactory::readIntensityData( + getOutputPath()+"isgi_cylinder_DWBA.ima.gz"); + + IsGISAXSTools::drawOutputDataComparisonResults(*m_result, *reference, + "zzz"); + + delete reference; } diff --git a/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.cpp b/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..48eb71214a558c404dac14d807e0fdc766880085 --- /dev/null +++ b/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.cpp @@ -0,0 +1,55 @@ +#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( + "Particle", 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 new file mode 100644 index 0000000000000000000000000000000000000000..60f0052ea62fb7707175a8c835c3c14fae28c43e --- /dev/null +++ b/Core/StandardSamples/PolarizedDWBAZeroMagBuilder.h @@ -0,0 +1,22 @@ +#ifndef POLARIZEDDWBAZEROMAGBUILDER_H +#define POLARIZEDDWBAZEROMAGBUILDER_H + +#include "ISampleBuilder.h" + +//! The PolarizedDWBAZeroMagBuilder class to build sample +//! without interference +class 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 099228e66c83616ebf0f8133c2db609f3fba84c4..038f2ea142822c63adf799b573b6242877e44570 100644 --- a/Core/StandardSamples/SampleBuilderFactory.cpp +++ b/Core/StandardSamples/SampleBuilderFactory.cpp @@ -6,6 +6,7 @@ #include "IsGISAXS06Builder.h" #include "IsGISAXS09Builder.h" #include "MesoCrystal01Builder.h" +#include "PolarizedDWBAZeroMagBuilder.h" SampleBuilderFactory::SampleBuilderFactory() { @@ -69,6 +70,10 @@ SampleBuilderFactory::SampleBuilderFactory() "mesocrystal01", IFactoryCreateFunction<MesoCrystal01Builder, ISampleBuilder>, "mesocrystals of cylindrical shape composed by spherical nanoparticles"); + registerItem( + "PolarizedDWBAZeroMag", + IFactoryCreateFunction<PolarizedDWBAZeroMagBuilder, ISampleBuilder>, + "polarized DWBA with zero magnetic field"); } diff --git a/Core/StandardSamples/SimulationRegistry.cpp b/Core/StandardSamples/SimulationRegistry.cpp index 5b49590bcfc350b6841af9958a94d6aa4f0727ee..37776b8a9b6c8262e4a8f5ffc14e86635ea0c83a 100644 --- a/Core/StandardSamples/SimulationRegistry.cpp +++ b/Core/StandardSamples/SimulationRegistry.cpp @@ -11,6 +11,10 @@ SimulationRegistry::SimulationRegistry() "mesocrystal01", StandardSimulations::MesoCrystal01, "mesocrystals of cylindrical shape composed by spherical nanoparticles"); + registerItem( + "PolarizedDWBAZeroMag", StandardSimulations::PolarizedDWBAZeroMag, + "polarized DWBA with zero magnetic field"); + } diff --git a/Core/StandardSamples/StandardSimulations.cpp b/Core/StandardSamples/StandardSimulations.cpp index 45dad5485e81f32468ceaee6a7501b0164016721..5e7e5f2304a474468311104be3cc905bba6151db 100644 --- a/Core/StandardSamples/StandardSimulations.cpp +++ b/Core/StandardSamples/StandardSimulations.cpp @@ -19,3 +19,22 @@ Simulation *StandardSimulations::MesoCrystal01() return result; } + + +Simulation *StandardSimulations::PolarizedDWBAZeroMag() +{ + SampleBuilderFactory factory; + ISampleBuilder *builder = factory.createBuilder("PolarizedDWBAZeroMag"); + + Simulation *result = new Simulation(); + + result->setDetectorParameters(100, 0.0*Units::degree, 2.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->setSampleBuilder( builder ); + + return result; +} diff --git a/Core/StandardSamples/StandardSimulations.h b/Core/StandardSamples/StandardSimulations.h index 95db10e89a8fa10d34dc00c2506202060d85c97e..4061e77b03d8850afbb6396f699fd1cdd9937954 100644 --- a/Core/StandardSamples/StandardSimulations.h +++ b/Core/StandardSamples/StandardSimulations.h @@ -10,6 +10,7 @@ namespace StandardSimulations{ Simulation *MesoCrystal01(); +Simulation *PolarizedDWBAZeroMag(); } diff --git a/Tests/FunctionalTests/TestCore/CMakeLists.txt b/Tests/FunctionalTests/TestCore/CMakeLists.txt index 90d2e2e1dcfa1fc5d91a77259985de8744d843c6..73b3e36ab7b5c55d6a44631f318da95ab6e01d91 100644 --- a/Tests/FunctionalTests/TestCore/CMakeLists.txt +++ b/Tests/FunctionalTests/TestCore/CMakeLists.txt @@ -17,6 +17,7 @@ set(list_of_tests "IsGISAXS11" "IsGISAXS15" # "MesoCrystal1" + "PolarizedDWBAZeroMag" ) # for some reason these flags doesn't propagated here by SetUpWindows.cmake diff --git a/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/.PolarizedDWBAZeroMag.h.swp b/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/.PolarizedDWBAZeroMag.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..6f0667f08ace2ace40599f9b661787a56c1a6301 Binary files /dev/null and b/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/.PolarizedDWBAZeroMag.h.swp differ diff --git a/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.cpp b/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.cpp new file mode 100644 index 0000000000000000000000000000000000000000..722166fb6ef638adc72dcfc8143ce6c2655666ba --- /dev/null +++ b/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.cpp @@ -0,0 +1,81 @@ +#include "PolarizedDWBAZeroMag.h" +#include "Simulation.h" +#include "ResolutionFunction2DSimple.h" +#include "OutputDataIOFactory.h" +#include "Utils.h" +#include "Units.h" +#include "Types.h" +#include "SimulationRegistry.h" + +using namespace FunctionalTests; + + + +PolarizedDWBAZeroMag::PolarizedDWBAZeroMag() +: m_name("PolarizedDWBAZeroMag") +, m_description("PolarizedDWBAZeroMag simulation") +, m_result(0) +, m_reference(0) +{ } + + +void PolarizedDWBAZeroMag::PolarizedDWBAZeroMag::run(const std::string &path_to_data) +{ + SimulationRegistry sim_registry; + Simulation *simulation = sim_registry.createSimulation("PolarizedDWBAZeroMag"); + + // loading reference data + std::string filename = path_to_data + "isgi_cylinder_DWBA.ima.gz"; + m_reference = OutputDataIOFactory::readIntensityData(filename); + + simulation->runSimulation(); + //OutputDataIOFactory::writeIntensityData(*simulation.getOutputData(), + // "this_cylinder_DWBA_pol.ima"); + + m_result = simulation->getIntensityData(); + delete simulation; +} + + +int PolarizedDWBAZeroMag::analyseResults() +{ + const double threshold(1e-10); + + // calculating average relative difference + *m_result -= *m_reference; + *m_result /= *m_reference; + + double diff(0); + for(OutputData<double>::const_iterator it=m_result->begin(); + it!=m_result->end(); ++it) { + diff+= std::fabs(*it); + } + diff /= m_result->getAllocatedSize(); + + bool status_ok(true); + if( diff > threshold || std::isnan(diff)) status_ok=false; + + std::cout << " diff " << diff << std::endl; + std::cout << m_name << " " << m_description << " " << + (status_ok ? "[OK]" : "[FAILED]") << std::endl; + return (status_ok ? 0 : 1); +} + + + +#ifdef STANDALONE +std::string GetPathToData(int argc, char **argv) +{ + if(argc == 2) return argv[1]; + //return Utils::FileSystem::GetPathToData("../../../ReferenceData/BornAgain/", argv[0]); + return Utils::FileSystem::GetPathToData("../../../ReferenceData/IsGISAXS/ex-3/", argv[0]); +} + +int main(int argc, char **argv) +{ + FunctionalTests::PolarizedDWBAZeroMag test; + test.run(GetPathToData(argc, argv)); + return test.analyseResults(); +} +#endif + diff --git a/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.h b/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.h new file mode 100644 index 0000000000000000000000000000000000000000..c3bda9aac6e4a5c97b0a33be5370d9f670ac1383 --- /dev/null +++ b/Tests/FunctionalTests/TestCore/PolarizedDWBAZeroMag/PolarizedDWBAZeroMag.h @@ -0,0 +1,38 @@ +#ifndef _TESTPOLARIZEDDWBAZEROMAG_H +#define _TESTPOLARIZEDDWBAZEROMAG_H + +#include "ISampleBuilder.h" +#include "OutputData.h" +#include <string> +#include <vector> + +class ISample; +class Simulation; +#include "OutputData.h" + + +namespace FunctionalTests { + +//! functional test: Polarized DWBA Zero magnetic field simulation + +class PolarizedDWBAZeroMag +{ +public: + PolarizedDWBAZeroMag(); + ~PolarizedDWBAZeroMag() { delete m_result; delete m_reference;} + + //! run fitting + void run(const std::string &path_to_data = std::string()); + int analyseResults(); + +private: + std::string m_name; + std::string m_description; + OutputData<double> *m_result; + OutputData<double> *m_reference; +}; + +} + + +#endif diff --git a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt index f288b9d9d1ca5a0868998d3179c6161cbfb63bf6..860daac8990acb64072394c6e6432a21b2e38d68 100644 --- a/Tests/FunctionalTests/TestPyCore/CMakeLists.txt +++ b/Tests/FunctionalTests/TestPyCore/CMakeLists.txt @@ -16,6 +16,7 @@ set(list_of_tests "isgisaxs11.py" "isgisaxs15.py" # "mesocrystal1.py" + "polarizeddwbazeromag.py" ) foreach(_test ${list_of_tests}) diff --git a/Tests/FunctionalTests/TestPyCore/TestPyCore.py b/Tests/FunctionalTests/TestPyCore/TestPyCore.py index 94afa627190f17be70e1f05c07d32640a2aef249..8cea65a16464a21227b052d20921236279e01d1e 100644 --- a/Tests/FunctionalTests/TestPyCore/TestPyCore.py +++ b/Tests/FunctionalTests/TestPyCore/TestPyCore.py @@ -18,6 +18,7 @@ import isgisaxs10 import isgisaxs11 import isgisaxs15 import mesocrystal1 +import polarizeddwbazeromag Tests = { "IsGISAXS01": isgisaxs01.runTest, @@ -31,7 +32,8 @@ Tests = { "IsGISAXS10": isgisaxs10.runTest, "IsGISAXS11": isgisaxs11.runTest, "IsGISAXS15": isgisaxs15.runTest, - "MesoCrystal1": mesocrystal1.runTest, +# "MesoCrystal1": mesocrystal1.runTest, + "PolarizedDWBAZeroMag": polarizeddwbazeromag.runTest, } test_info = [] diff --git a/Tests/FunctionalTests/TestPyCore/polarizeddwbazeromag.py b/Tests/FunctionalTests/TestPyCore/polarizeddwbazeromag.py new file mode 100644 index 0000000000000000000000000000000000000000..99d7d9d477ddbaa407fef0b90bca32003b300ee4 --- /dev/null +++ b/Tests/FunctionalTests/TestPyCore/polarizeddwbazeromag.py @@ -0,0 +1,104 @@ +# IsGISAXS01 example: Mixture of cylinders and prisms without interference +import sys +import os +import numpy +import gzip + +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", 6e-6, 2e-8 ) + + magnetic_field = kvector_t(0,0,0) + + magParticle = MaterialManager.getHomogeneousMagneticMaterial("magParticle", 6e-4, 2e-8, 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,0*degree, 2.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.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 + + +# -------------------------------------------------------------- +# run test and analyse test results +# -------------------------------------------------------------- +def runTest(): + result = RunSimulation() + reference = GetReferenceData() + + diff = GetDifference(result, reference) + status = "OK" + if(diff > 2e-10 or numpy.isnan(diff)): 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) diff --git a/Tests/ReferenceData/BornAgain/isgi_cylinder_DWBA.ima.gz b/Tests/ReferenceData/BornAgain/isgi_cylinder_DWBA.ima.gz new file mode 100644 index 0000000000000000000000000000000000000000..7f25aa77500d72cf43e0bd0f660d5c6c23026ab5 Binary files /dev/null and b/Tests/ReferenceData/BornAgain/isgi_cylinder_DWBA.ima.gz differ