diff --git a/.cproject b/.cproject index f14a6cda202e8ed90ad22bc2eec27057b9692d4a..3a590a0c23a6f5a487d90bc8c0148b8325d90ffe 100644 --- a/.cproject +++ b/.cproject @@ -153,20 +153,20 @@ </storageModule> <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> <storageModule moduleId="scannerConfiguration"> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600;cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600.;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1651719834;cdt.managedbuild.tool.gnu.c.compiler.input.485220512"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/> + </scannerConfigBuildInfo> <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.45089428;cdt.managedbuild.toolchain.gnu.macosx.base.45089428.834509647;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.44819609;cdt.managedbuild.tool.gnu.c.compiler.input.44052800"> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/> </scannerConfigBuildInfo> <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.45089428;cdt.managedbuild.toolchain.gnu.macosx.base.45089428.834509647;cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.1362645889;cdt.managedbuild.tool.gnu.cpp.compiler.input.2060403592"> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/> </scannerConfigBuildInfo> - <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600;cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600.;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1651719834;cdt.managedbuild.tool.gnu.c.compiler.input.485220512"> - <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/> - </scannerConfigBuildInfo> <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600;cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600.;cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.1382053189;cdt.managedbuild.tool.gnu.cpp.compiler.input.913383985"> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/> </scannerConfigBuildInfo> </storageModule> - <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> </cproject> diff --git a/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW DWBA Formfactor.launch b/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW DWBA Formfactor.launch deleted file mode 100644 index ba2c97ca0cf674625fed56568913d8eaa3e6e4ef..0000000000000000000000000000000000000000 --- a/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW DWBA Formfactor.launch +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType"> -<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/> -<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/> -<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="dwba"/> -<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="/Users/herck/Development/git/GISASFW/App/App"/> -<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="GISASFW"/> -<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/> -<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/> -<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/GISASFW"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="4"/> -</listAttribute> -<mapAttribute key="org.eclipse.debug.core.environmentVariables"> -<mapEntry key="DYLD_LIBRARY_PATH" value="/Users/herck/Development/git/GISASFW/lib:/opt/local/lib/root"/> -</mapAttribute> -<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> -<listEntry value="org.eclipse.debug.ui.launchGroup.run"/> -</listAttribute> -</launchConfiguration> diff --git a/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Diffuse.launch b/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Diffuse.launch deleted file mode 100644 index 7c6526ed0d2296b5064858d00ed014b1149e4c82..0000000000000000000000000000000000000000 --- a/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Diffuse.launch +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType"> -<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/> -<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/> -<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="diffuse"/> -<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="/Users/herck/Development/git/GISASFW/App/App"/> -<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="GISASFW"/> -<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/> -<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/> -<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/GISASFW"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="4"/> -</listAttribute> -<mapAttribute key="org.eclipse.debug.core.environmentVariables"> -<mapEntry key="DYLD_LIBRARY_PATH" value="/Users/herck/Development/git/GISASFW/lib:/opt/local/lib/root"/> -</mapAttribute> -<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> -<listEntry value="org.eclipse.debug.ui.launchGroup.run"/> -</listAttribute> -</launchConfiguration> diff --git a/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Formfactor.launch b/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Formfactor.launch deleted file mode 100644 index c0f5397733d0e8210225757c048ab297d0e0ba95..0000000000000000000000000000000000000000 --- a/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Formfactor.launch +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType"> -<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/> -<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/> -<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="formfactor"/> -<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="/Users/herck/Development/git/GISASFW/App/App"/> -<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="GISASFW"/> -<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/> -<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/> -<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/GISASFW"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="4"/> -</listAttribute> -<mapAttribute key="org.eclipse.debug.core.environmentVariables"> -<mapEntry key="DYLD_LIBRARY_PATH" value="/Users/herck/Development/git/GISASFW/lib:/opt/local/lib/root"/> -</mapAttribute> -<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> -<listEntry value="org.eclipse.debug.ui.launchGroup.run"/> -</listAttribute> -</launchConfiguration> diff --git a/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Fresnel.launch b/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Fresnel.launch deleted file mode 100644 index 80a990b6ba304465f532d6aabdd73e719df79c90..0000000000000000000000000000000000000000 --- a/.metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Fresnel.launch +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType"> -<booleanAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB" value="true"/> -<listAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB_LIST"/> -<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="gdb"/> -<booleanAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_ON_FORK" value="false"/> -<stringAttribute key="org.eclipse.cdt.dsf.gdb.GDB_INIT" value=".gdbinit"/> -<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/> -<booleanAttribute key="org.eclipse.cdt.dsf.gdb.REVERSE" value="false"/> -<listAttribute key="org.eclipse.cdt.dsf.gdb.SOLIB_PATH"/> -<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/> -<booleanAttribute key="org.eclipse.cdt.dsf.gdb.internal.ui.launching.LocalApplicationCDebuggerTab.DEFAULTS_SET" value="true"/> -<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/> -<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/> -<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_ID" value="gdb"/> -<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="run"/> -<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/> -<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/> -<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="fresnel"/> -<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="/Users/herck/Development/git/GISASFW/App/App"/> -<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="GISASFW"/> -<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/> -<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/> -<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/GISASFW"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="4"/> -</listAttribute> -<mapAttribute key="org.eclipse.debug.core.environmentVariables"> -<mapEntry key="DYLD_LIBRARY_PATH" value="/Users/herck/Development/git/GISASFW/lib:/opt/local/lib/root"/> -</mapAttribute> -<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> -<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/> -<listEntry value="org.eclipse.debug.ui.launchGroup.run"/> -</listAttribute> -<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList context="reserved-for-future-use"> <gdbmemoryBlockExpression address="4363286528" label="0x104127800"/> </memoryBlockExpressionList> "/> -</launchConfiguration> diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index e9636c6db4e5c17722dfc7124b612a52d763f04a..7b2358a59ea3351fba40219075cdf19577acb8ea 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -1,6 +1,6 @@ eclipse.preferences.version=1 environment/project/cdt.managedbuild.toolchain.gnu.macosx.base.45089428/DYLD_LIBRARY_PATH/delimiter=\: environment/project/cdt.managedbuild.toolchain.gnu.macosx.base.45089428/DYLD_LIBRARY_PATH/operation=replace -environment/project/cdt.managedbuild.toolchain.gnu.macosx.base.45089428/DYLD_LIBRARY_PATH/value=${workspace_loc\:/GISASFW/lib} +environment/project/cdt.managedbuild.toolchain.gnu.macosx.base.45089428/DYLD_LIBRARY_PATH/value=${workspace_loc\:/BornAgain/lib} environment/project/cdt.managedbuild.toolchain.gnu.macosx.base.45089428/append=true environment/project/cdt.managedbuild.toolchain.gnu.macosx.base.45089428/appendContributed=true diff --git a/App/App.pro b/App/App.pro index 288e81fd60049b8d9ed64946f4f57c025783b317..11ba003261b52e5d811d25a874e3fc07aaf814cd 100644 --- a/App/App.pro +++ b/App/App.pro @@ -77,6 +77,7 @@ SOURCES += \ src/TestPerformance.cpp \ src/TestRootTree.cpp \ src/TestRoughness.cpp \ + src/TestSpecularMatrix.cpp \ src/TestToySimulation.cpp \ src/TreeEventStructure.cpp \ src/main.cpp @@ -141,6 +142,7 @@ HEADERS += \ inc/TestPerformance.h \ inc/TestRootTree.h \ inc/TestRoughness.h \ + inc/TestSpecularMatrix.h \ inc/TestToySimulation.h \ inc/TreeEventStructure.h \ inc/Version.h \ diff --git a/App/inc/TestPerformance.h b/App/inc/TestPerformance.h index b1a90edc7e885425f4c4f498018dd01ca9ccec05..b456a8adfa72dc7792518b224e935f46e90f94f4 100644 --- a/App/inc/TestPerformance.h +++ b/App/inc/TestPerformance.h @@ -1,5 +1,5 @@ // ************************************************************************** // -// +// // BornAgain: simulate and fit scattering at grazing incidence // //! @file App/inc/TestPerformance.h @@ -75,6 +75,18 @@ class PerfTest_FresnelCoeff : public IFunctionalTest ISample *m_sample; }; +//! @class PerfTest_SpecularMatrix +//! measurement of the performance in specular matrix calculation +class PerfTest_SpecularMatrix : public IFunctionalTest +{ + public: + PerfTest_SpecularMatrix() : IFunctionalTest("SpecularMatrix"), m_sample(0){} + virtual ~PerfTest_SpecularMatrix() { } + void initialise(ProgramOptions *p_options); + void execute(); + ISample *m_sample; +}; + //! @class PerfTest_Pyramid //! measurement of the performance in pyramid form factor calculations class PerfTest_Pyramid : public IFunctionalTest diff --git a/App/inc/TestSpecularMatrix.h b/App/inc/TestSpecularMatrix.h new file mode 100644 index 0000000000000000000000000000000000000000..17f26bfb7d698824172fd708a1852ef4a3287e05 --- /dev/null +++ b/App/inc/TestSpecularMatrix.h @@ -0,0 +1,51 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file App/inc/TestSpecularMatrix.h +//! @brief Defines class TestSpecularMatrix. +//! +//! @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 TESTSPECULARMATRIX_H_ +#define TESTSPECULARMATRIX_H_ + +#include "IFunctionalTest.h" +#include "SpecularMatrix.h" +#include "MultiLayer.h" +#include "OutputData.h" + +//! Returns amplitudes for different wave components using the matrix formalism +//! for several typical multilayer samples and produce validation plots + +class TestSpecularMatrix : public IFunctionalTest +{ + public: + TestSpecularMatrix(); + + void execute(); + + private: + //! Returns amplitudes vs. alpha_i for several standard samples + void test_standard_samples(); + //! draw results of the test + void draw_standard_samples(); + + //! Returns amplitudes vs. alpha_i for set of roughnesses +// void test_roughness_set(); + //! draw result of the test +// void draw_roughness_set(); + + MultiLayer *mp_sample; //!< pointer to multilayer sample + OutputData<SpecularMatrix::MultiLayerCoeff_t > *mp_coeffs; //!< output data structure +}; + + + +#endif /* TESTSPECULARMATRIX_H_ */ diff --git a/App/src/FunctionalTestFactory.cpp b/App/src/FunctionalTestFactory.cpp index 4ce7b9451045305d1cae33fad25a3fa13fc21754..b554fffdc4f0d7003eb81b4eee4f78599d730ffc 100644 --- a/App/src/FunctionalTestFactory.cpp +++ b/App/src/FunctionalTestFactory.cpp @@ -48,6 +48,7 @@ #include "TestPerformance.h" #include "TestRootTree.h" #include "TestRoughness.h" +#include "TestSpecularMatrix.h" #include "TestToySimulation.h" #include "TBenchmark.h" @@ -298,5 +299,9 @@ void RegisterFunctionalTests(FunctionalTestFactory *p_test_factory) "FormFactors", IFactoryCreateFunction<TestFormFactors, IFunctionalTest>, "functional test: FormFactors"); + p_test_factory->registerItem( + "specularmatrix", + IFactoryCreateFunction<TestSpecularMatrix, IFunctionalTest>, + "functional test: specular reflectivity with matrix formalism"); } diff --git a/App/src/TestPerformance.cpp b/App/src/TestPerformance.cpp index dc6b0a58d86523d7692af191800d30e427763497..ca49bee1f3a7ddc76137fcc9f8ab7ae8458d1bb6 100644 --- a/App/src/TestPerformance.cpp +++ b/App/src/TestPerformance.cpp @@ -1,5 +1,5 @@ // ************************************************************************** // -// +// // BornAgain: simulate and fit scattering at grazing incidence // //! @file App/src/TestPerformance.cpp @@ -32,6 +32,7 @@ #include <sstream> #include <iomanip> #include <time.h> +#include "SpecularMatrix.h" TestPerformance::TestPerformance() { @@ -40,6 +41,7 @@ TestPerformance::TestPerformance() m_tests.push_back( new PerformanceTestInfo(new PerfTest_Pyramid(), 20) ); m_tests.push_back( new PerformanceTestInfo(new PerfTest_RotatedPyramid(), 20) ); m_tests.push_back( new PerformanceTestInfo(new PerfTest_MesoCrystal(), 2) ); + m_tests.push_back( new PerformanceTestInfo(new PerfTest_SpecularMatrix(), 200000) ); std::cout << "TestPerformance::TestPerformance() -> Info. Preparing to run " << m_tests.size() << " performance tests." << std::endl; } @@ -115,7 +117,7 @@ void TestPerformance::write_performance() file << std::left << Utils::AdjustStringLength(m_performance_info["sysinfo"],23) << get_delimeter(); for(performance_tests_t::iterator it=m_tests.begin(); it!= m_tests.end(); ++it) { std::string test_name = (*it)->m_test->getName(); - file << std::left << Utils::AdjustStringLength(m_performance_info[test_name],7) << get_delimeter(); + file << std::left << Utils::AdjustStringLength(m_performance_info[test_name],11) << get_delimeter(); } file<<std::endl; @@ -179,6 +181,28 @@ void PerfTest_FresnelCoeff::execute() FresnelCalculator.execute(*ml, kvec, coeffs); } +//! Start PerfTest_SpecularMatrix. + +void PerfTest_SpecularMatrix::initialise(ProgramOptions *p_options) +{ + IFunctionalTest::initialise(p_options); + if(m_sample) delete m_sample; + m_sample = dynamic_cast<MultiLayer *>(SampleFactory::createSample("SimpleMultilayer")); +} + +//! Run PerfTest_SpecularMatrix. + +void PerfTest_SpecularMatrix::execute() +{ + 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; + MultiLayer *ml = dynamic_cast<MultiLayer *>(m_sample); + matrixCalculator.execute(*ml, kvec, coeffs); +} + //! Start PerfTest_Pyramid. void PerfTest_Pyramid::initialise(ProgramOptions *p_options) diff --git a/App/src/TestSpecularMatrix.cpp b/App/src/TestSpecularMatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b994dc636c257c39fcfacedf800a110b3675f73c --- /dev/null +++ b/App/src/TestSpecularMatrix.cpp @@ -0,0 +1,192 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file App/src/TestSpecularMatrix.cpp +//! @brief Implements class TestSpecularMatrix. +//! +//! @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 "TestSpecularMatrix.h" + +#include "SampleFactory.h" +#include "Units.h" +#include "TCanvas.h" +#include "TGraph.h" +#include "DrawHelper.h" +#include "TH1F.h" +#include "TLegend.h" + + +TestSpecularMatrix::TestSpecularMatrix() +: mp_sample(0) +, mp_coeffs(0) +{ + std::cout << "TestSpecularMatrix::TestSpecularMatrix() -> Info." << std::endl; +} + +void TestSpecularMatrix::execute() +{ + std::cout << "TestSpecularMatrix::execute() -> Info." << std::endl; + + // calculate amplitudes for several standard multi-layer samples + test_standard_samples(); +} + +void TestSpecularMatrix::test_standard_samples() +{ + std::vector<std::string > snames; + snames.push_back("MultilayerOffspecTestcase1a"); + + // loop over standard samples defined in SampleFactory and StandardSamples + for(size_t i_sample=0; i_sample<snames.size(); i_sample++){ + mp_sample = dynamic_cast<MultiLayer *>(SampleFactory::createSample(snames[i_sample])); + + mp_coeffs = new OutputData<SpecularMatrix::MultiLayerCoeff_t >; + mp_coeffs->addAxis(std::string("alpha_i"), 2000, 0.0*Units::degree, 2.0*Units::degree); + OutputData<SpecularMatrix::MultiLayerCoeff_t >::iterator it = mp_coeffs->begin(); + while (it != mp_coeffs->end()) { + double alpha_i = mp_coeffs->getValueOfAxis("alpha_i", it.getIndex()); + kvector_t kvec; + kvec.setLambdaAlphaPhi(1.54*Units::angstrom, -alpha_i, 0.0); + + SpecularMatrix::MultiLayerCoeff_t coeffs; + SpecularMatrix matrixCalculator; + matrixCalculator.execute(*mp_sample, kvec, coeffs); + + *it = coeffs; + ++it; + + } // alpha_i + + draw_standard_samples(); + + delete mp_sample; + delete mp_coeffs; + } // i_sample +} + +void TestSpecularMatrix::draw_standard_samples() +{ + static int ncall = 0; + + size_t nlayers = mp_sample->getNumberOfLayers(); + + // graphics for R,T coefficients in layers as a function of alpha_i + size_t ncoeffs = 2; + enum key_coeffs { kCoeffR, kCoeffT}; + const char *coeffs_title[]={" |R| "," |T| "}; + int coeffs_color[] = {kBlue, kRed}; + + std::vector<std::vector<TGraph *> > gr_coeff; // [nlayers][ncoeffs] + gr_coeff.resize(nlayers); + for(size_t i_layer=0; i_layer<nlayers; i_layer++) { + gr_coeff[i_layer].resize(ncoeffs,0); + for(size_t i_coeff=0; i_coeff<ncoeffs; i_coeff++) { + gr_coeff[i_layer][i_coeff] = new TGraph(); + } + } + TGraph *gr_absSum = new TGraph(); // |R_top|+|T_bottom| + + OutputData<SpecularMatrix::MultiLayerCoeff_t >::const_iterator it = mp_coeffs->begin(); + int i_point = 0; + while (it != mp_coeffs->end()) { + double alpha_i = mp_coeffs->getValueOfAxis("alpha_i", it.getIndex()); + const SpecularMatrix::MultiLayerCoeff_t coeffs = *it++; + + // Filling graphics for R,T as a function of alpha_i + for(size_t i_layer=0; i_layer<nlayers; ++i_layer ) { + gr_coeff[i_layer][kCoeffR]->SetPoint(i_point, Units::rad2deg(alpha_i), std::abs(coeffs[i_layer].R()) ); + gr_coeff[i_layer][kCoeffT]->SetPoint(i_point, Units::rad2deg(alpha_i), std::abs(coeffs[i_layer].T()) ); + } + + // Filling graphics for |R|+|T| as a function of alpha_i taking R from the top and T from the bottom layers + int nlast = (int)nlayers - 1; + double sum; + if(coeffs[0].lambda.real()!=0.0) { + sum = std::norm(coeffs[0].R()) + std::norm(coeffs[nlast].T())*coeffs[nlast].lambda.real()/coeffs[0].lambda.real(); + } else { + sum = 1.0; + std::cout << "Re(k_{z,0}) = 0 for alpha_i = " << alpha_i << std::endl; + std::cout << " and Re(k_{z,N+1}) = " << coeffs[nlast].lambda.real() << std::endl; + } + gr_absSum->SetPoint(i_point++, Units::rad2deg(alpha_i), sum); + } + + // create name of canvas different for each new call of this method + std::ostringstream os; + os << (ncall++) << std::endl; + std::string cname = std::string("c1_test_Fresnel_sample")+os.str(); + TCanvas *c1 = new TCanvas(cname.c_str(),"Fresnel Coefficients in Multilayer",1024,768); + DrawHelper::SetMagnifier(c1); + + // estimate subdivision of canvas (we need place for 'nlayers' and for one sample picture) + int ndiv(2); + if( nlayers+1 > 4 ) ndiv = int(sqrt(nlayers+1)+1); + c1->Divide(ndiv,ndiv); + + for(size_t i_layer=0; i_layer<nlayers; i_layer++) { + c1->cd((int)i_layer+1); + gPad->SetLogy(); + + // calculating histogram limits common for all graphs on given pad + double xmin(0), ymin(0), xmax(0), ymax(0); + for(size_t i_coeff=0; i_coeff<ncoeffs; i_coeff++){ + double x1(0), y1(0), x2(0), y2(0); + gr_coeff[i_layer][kCoeffT]->ComputeRange(x1, y1, x2, y2); + if(x1 < xmin ) xmin= x1; + if(x2 > xmax ) xmax = x2; + if(y1 < ymin ) ymin = y1; + if(y2 > ymax ) ymax = y2; + } + TH1F h1ref("h1ref","h1ref",100, xmin, xmax); + h1ref.SetMinimum(1e-6); + h1ref.SetMaximum(10); + h1ref.SetStats(0); + h1ref.SetTitle(""); + h1ref.GetXaxis()->SetTitle("angle, deg"); + h1ref.GetYaxis()->SetTitle("|R|, |T|"); + h1ref.DrawCopy(); + + TLegend *leg = new TLegend(0.725,0.7,0.89,0.88); + leg->SetTextSize(0.04); + leg->SetBorderSize(1); + leg->SetFillStyle(0); + std::ostringstream os; + os << " layer #" << i_layer; + leg->SetHeader(os.str().c_str()); + + for(size_t i_coeff=0; i_coeff<ncoeffs; i_coeff++) { + TGraph *gr = gr_coeff[i_layer][i_coeff]; + gr->SetLineColor( coeffs_color[i_coeff] ); + gr->SetMarkerColor( coeffs_color[i_coeff] ); + gr->SetMarkerStyle(21); + gr->SetMarkerSize(0.2); + gr->Draw("pl same"); + leg->AddEntry(gr, coeffs_title[i_coeff],"pl"); + } + leg->Draw(); + } + TGraph *gr = gr_absSum; + gr->SetMarkerStyle(21); + gr->SetMarkerSize(0.2); + gr->SetLineColor(kMagenta); + gr->SetMarkerColor(kMagenta); + gr->Draw("pl same"); + TLegend *leg = new TLegend(0.625,0.6,0.89,0.69); + leg->SetTextSize(0.04); + leg->SetBorderSize(0); + leg->SetFillStyle(0); + leg->AddEntry(gr, "|R_top|+|T_bottom|","pl"); + leg->Draw(); + + // drawing sample geometry + c1->cd((int)nlayers+1); + DrawHelper::DrawMultilayer(mp_sample); +} diff --git a/BornAgain.pro b/BornAgain.pro index 8dc7f80ec2c797baff81636c18f3f6a31c6b07a4..b3a2923311365bd85349b932a3dfdc792571e398 100644 --- a/BornAgain.pro +++ b/BornAgain.pro @@ -16,4 +16,4 @@ SUBDIRS += Tests/UnitTests/TestCore TestCore.depends = ThirdParty/gtest TestCore.depends = ThirdParty/gtest -CONFIG += ordered # comiplation in lister order +CONFIG += ordered # compilation in lister order diff --git a/Core/Algorithms/inc/SpecularMatrix.h b/Core/Algorithms/inc/SpecularMatrix.h new file mode 100644 index 0000000000000000000000000000000000000000..b0b988bbb0272eb5da9d93edf8269cbbc9591957 --- /dev/null +++ b/Core/Algorithms/inc/SpecularMatrix.h @@ -0,0 +1,75 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Algorithms/inc/SpecularMatrix.h +//! @brief Defines class SpecularMatrix. +//! +//! @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 SPECULARMATRIX_H_ +#define SPECULARMATRIX_H_ + +#include "Types.h" +#include "ISimulation.h" +#include "MultiLayer.h" + +#include "Eigen/Core" + +//! Implements the matrix formalism for the calculation of wave amplitudes of +//! the coherent wave solution in a multilayer + +class SpecularMatrix : public ISimulation +{ +public: + SpecularMatrix() : m_use_roughness(false) { (void)m_use_roughness; } + + //! layer coefficients for matrix formalism + class LayerMatrixCoeff { + public: + LayerMatrixCoeff() : lambda(0) {} + ~LayerMatrixCoeff() {} + complex_t R() const { return (phi_psi(1)+phi_psi(0)/lambda)/2.0; } + complex_t T() const { return (phi_psi(1)-phi_psi(0)/lambda)/2.0; } + // A - amplitude of initial wave, R, T - amplitudes of reflected and transmitted waves + complex_t lambda; // positive eigenvalue of transfer matrix + Eigen::Vector2cd phi_psi; + Eigen::Matrix2cd l; + Eigen::Matrix2cd l_accumulated; + }; + + //! multi layer coefficients for matrix formalism + class MultiLayerMatrixCoeff + { + public: + inline LayerMatrixCoeff& operator[](size_t i) { return m_data[i]; } + inline const LayerMatrixCoeff& operator[](size_t i) const { return m_data[i]; } + inline size_t size() const { return m_data.size(); } + inline void clear() { m_data.clear(); } + inline void resize(size_t size) { m_data.resize(size); } + complex_t R; // total reflection coefficient + Eigen::Matrix2cd L; + private: + std::vector<LayerMatrixCoeff > m_data; + }; + + typedef MultiLayerMatrixCoeff MultiLayerCoeff_t; // set of layer coefficients for matrix formalism + + //! Returns Fresnel coefficients for given multi layer and kvector + void execute(const MultiLayer& sample, const kvector_t& k, MultiLayerCoeff_t& coeff); + +private: + bool m_use_roughness; + + void calculateEigenvalues(const MultiLayer& sample, const kvector_t& k, MultiLayerCoeff_t& coeff) const; + void calculateTransferMatrices(const MultiLayer& sample, const kvector_t& k, MultiLayerCoeff_t& coeff) const; + void calculateBoundaryValues(MultiLayerCoeff_t& coeff) const; +}; + +#endif /* SPECULARMATRIX_H_ */ diff --git a/Core/Algorithms/src/OpticalFresnel.cpp b/Core/Algorithms/src/OpticalFresnel.cpp index c1e136345c14e6a8d11ce3ddfda5140be2f69fc1..172dc5dd22264b98bff2d95d1b8669e93f190e8d 100644 --- a/Core/Algorithms/src/OpticalFresnel.cpp +++ b/Core/Algorithms/src/OpticalFresnel.cpp @@ -68,12 +68,14 @@ void OpticalFresnel::execute(const MultiLayer& sample, const kvector_t& kvec, Mu void OpticalFresnel::calculateKZ(const MultiLayer& sample, const kvector_t& kvec, MultiLayerCoeff_t& coeff) const { // z-component of reflected wave vector inside each layer - // Q_{z,j}& = 2k_{z,j} = 2\cdot \sqrt{ k^2 n_j^2 - k_x^2 } + // k is the vacuum wave number + // Q_{z,j}& = 2k_{z,j} = 2\cdot \sqrt{ k^2 n_j^2 - k_x^2 n_0^2 } + // top layer refractive index: + complex_t rindex0 = sample.getLayer(0)->getRefractiveIndex(); + complex_t rindex0_squared = rindex0*rindex0; for(size_t i=0; i<coeff.size(); ++i) { complex_t rindex = sample.getLayer(i)->getRefractiveIndex(); - //coeff[i].kz = std::sqrt( kvec.mag2()*rindex*rindex - kvec.magxy()*kvec.rho() ); - //coeff[i].kz = std::sqrt( kvec.mag2()*rindex*rindex - kvec.perp2() ); - coeff[i].kz = std::sqrt( kvec.mag2()*rindex*rindex - kvec.magxy2() ); + coeff[i].kz = std::sqrt( kvec.mag2()*rindex*rindex - kvec.magxy2()*rindex0_squared ); } } @@ -158,7 +160,7 @@ void OpticalFresnel::calculateX2(const MultiLayer& sample, MultiLayerCoeff_t& co for(int i=(int)coeff.size()-2; i>=0; --i) { // first check for infinity if(std::abs(coeff[i].r*coeff[i+1].X + complex_t(1,0)) < Numeric::double_epsilon) { - throw DivisionByZeroException("Division by zer during calculation of X_i"); + throw DivisionByZeroException("Division by zero during calculation of X_i"); } double d = i==0 ? 0.0 : sample.getLayerThickness(i); complex_t exp_factor; diff --git a/Core/Algorithms/src/SpecularMatrix.cpp b/Core/Algorithms/src/SpecularMatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..07b0c097f6b967e6269da7078c4ac09a2b936632 --- /dev/null +++ b/Core/Algorithms/src/SpecularMatrix.cpp @@ -0,0 +1,84 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file Algorithms/src/SpecularMatrix.cpp +//! @brief Implements class SpecularMatrix. +//! +//! @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 "SpecularMatrix.h" + +void SpecularMatrix::execute(const MultiLayer& sample, const kvector_t& k, + MultiLayerCoeff_t& coeff) +{ + coeff.clear(); + coeff.resize(sample.getNumberOfLayers()); + + calculateEigenvalues(sample, k, coeff); + + calculateTransferMatrices(sample, k, coeff); + + calculateBoundaryValues(coeff); +} + +void SpecularMatrix::calculateEigenvalues(const MultiLayer& sample, + const kvector_t& k, MultiLayerCoeff_t& coeff) const +{ + double sinalpha = std::abs( k.cosTheta() ); + double cosalpha2 = 1.0 - sinalpha*sinalpha; + complex_t rindex0 = sample.getLayer(0)->getRefractiveIndex(); + complex_t r2cosalpha2 = rindex0*rindex0*cosalpha2; + for(size_t i=0; i<coeff.size(); ++i) { + complex_t rindex = sample.getLayer(i)->getRefractiveIndex(); + coeff[i].lambda = std::sqrt(rindex*rindex - r2cosalpha2); + } +} + +void SpecularMatrix::calculateTransferMatrices(const MultiLayer& sample, + const kvector_t& k, MultiLayerCoeff_t& coeff) const +{ + // Layer 0 gets identity matrix: + coeff[0].l.setIdentity(); + coeff.L.setIdentity(); + for(size_t i=1; i<coeff.size()-1; ++i) { + complex_t lambda = coeff[i].lambda; + complex_t kdlambda = k.mag()*sample.getLayer(i)->getThickness()*lambda; + complex_t cosine_term = std::cos(kdlambda); + complex_t sine_term = + ( std::abs(kdlambda) < Numeric::double_epsilon ) ? + k.mag()*sample.getLayer(i)->getThickness() : + std::sin(kdlambda)/lambda; + coeff[i].l(0,0) = cosine_term; + coeff[i].l(0,1) = -complex_t(0.0, 1.0)*lambda*lambda*sine_term; + coeff[i].l(1,0) = -complex_t(0.0, 1.0)*sine_term; + coeff[i].l(1,1) = cosine_term; + coeff.L = coeff[i].l * coeff.L; + } + // Last layer also gets identity matrix: + size_t N = coeff.size(); + coeff[N-1].l.setIdentity(); +} + +void SpecularMatrix::calculateBoundaryValues(MultiLayerCoeff_t& coeff) const +{ + complex_t lambda0 = coeff[0].lambda; + size_t N = coeff.size(); + complex_t lambdaN = coeff[N-1].lambda; + complex_t denominator = (lambda0*coeff.L(0,0) + coeff.L(0,1) + lambdaN*(lambda0*coeff.L(1,0) + coeff.L(1,1))); + coeff.R = (lambda0*coeff.L(0,0) - coeff.L(0,1) + lambdaN*(lambda0*coeff.L(1,0) - coeff.L(1,1)))/denominator; + // Boundary values at bottom of top layer + // and top of first layer: + coeff[1].phi_psi(0) = coeff[0].phi_psi(0) = lambda0*(coeff.R - 1.0); + coeff[1].phi_psi(1) = coeff[0].phi_psi(1) = coeff.R + 1.0; + for(size_t i=2; i<coeff.size(); ++i) { + coeff[i].phi_psi = coeff[i-1].l*coeff[i-1].phi_psi; + } +} diff --git a/Core/Core.pro b/Core/Core.pro index 4e5d541cffe1369f33ac43f3dfe163c017841c6e..fead580a35efa7d3b2d94a3051642c7d301187fa 100644 --- a/Core/Core.pro +++ b/Core/Core.pro @@ -72,6 +72,7 @@ SOURCES += \ Algorithms/src/ResolutionFunction2DSimple.cpp \ Algorithms/src/Simulation.cpp \ Algorithms/src/SizeSpacingCorrelationApproximationStrategy.cpp \ + Algorithms/src/SpecularMatrix.cpp \ Algorithms/src/StrategyBuilder.cpp \ \ FormFactors/src/FormFactorBox.cpp \ @@ -219,6 +220,7 @@ HEADERS += \ Algorithms/inc/Simulation.h \ Algorithms/inc/SimulationParameters.h \ Algorithms/inc/SizeSpacingCorrelationApproximationStrategy.h \ + Algorithms/inc/SpecularMatrix.h \ Algorithms/inc/StrategyBuilder.h \ Algorithms/inc/ThreadInfo.h \ \ diff --git a/dev-tools/log/perf_history.txt b/dev-tools/log/perf_history.txt index d0d52e739f7ce8656e2bdc7681208d3f2f6533ed..cf9e623a2a2d08cbbf0147658288af16426caf3d 100644 --- a/dev-tools/log/perf_history.txt +++ b/dev-tools/log/perf_history.txt @@ -1,4 +1,4 @@ -# date and time | hostname | system information | FresnelCoeff Pyramid RotatedPyramid MesoCrystal +# date and time | hostname | system information | FresnelCoeff Pyramid RotatedPyramid MesoCrystal Matrix Method 2012-07-24 18:21:18 | jcnsopc73 | macosx64, 2800 MHz | 82987.5 | 4.14079 | 3.89105 | 0.23391 | 2012-07-24 18:22:36 | jcnsopc73 | macosx64, 2800 MHz | 82987.5 | 4.14938 | 3.91389 | 0.23391 | @@ -244,3 +244,5 @@ 2013-04-08 20:48:26 | jcnsops73 | macosx64, 2800 MHz | 294118 | 21.978 | 22.7273 | 6.25 | 2013-04-08 20:48:32 | jcnsops73 | macosx64, 2800 MHz | 289855 | 22.2222 | 22.7273 | 6.06061 | +# added performance method for matrix calculation of layer wave amplitudes +2013-05-07 16:05:21 | jcnsopc74 | macosx64, 2800 MHz | 294118 | 11.976 | 11.976 | 3.63636 | 1.05263e+06 | diff --git a/shared.pri b/shared.pri index bfa23a29031ff9249b349ed23ce6fbb7d92c1d48..cfa5c631b8ecfd1b1dc77dfe640b314bd55873ce 100644 --- a/shared.pri +++ b/shared.pri @@ -33,6 +33,13 @@ INCLUDEPATH *= $${GSL_INCLUDE} LIBS *= -L$${GSL_LIB} LIBS += -lgsl -lgslcblas +# --- checking eigen headers --- +EIGEN_HEADERFILE = Eigen/Core +EIGEN_HEADER_LOCATIONS = /opt/local/include /usr/local/include /usr/include +for(dir, EIGEN_HEADER_LOCATIONS): isEmpty(EIGEN_INCLUDE): exists($${dir}/$${EIGEN_HEADERFILE}): EIGEN_INCLUDE = $${dir} +isEmpty(EIGEN_INCLUDE): message("Can't find" $${EIGEN_HEADERFILE} "in" $${EIGEN_HEADER_LOCATIONS}) +INCLUDEPATH *= $${EIGEN_INCLUDE} + # --- checking fftw3 --- FFTW3_HEADERFILE = fftw3.h FFTW3_HEADER_LOCATIONS = /opt/local/include /usr/local/include /usr/include