From b44dd61850c30a49b93d356efe07f2df71c05109 Mon Sep 17 00:00:00 2001 From: Walter Van Herck <w.van.herck@fz-juelich.de> Date: Tue, 7 May 2013 16:08:51 +0200 Subject: [PATCH] Added performance test and removed sin(alpha) term in matrix calculation --- .../.launches/GISASFW DWBA Formfactor.launch | 23 ----------- .../.launches/GISASFW Diffuse.launch | 23 ----------- .../.launches/GISASFW Formfactor.launch | 23 ----------- .../.launches/GISASFW Fresnel.launch | 39 ------------------- .settings/org.eclipse.cdt.core.prefs | 2 +- App/inc/TestPerformance.h | 14 ++++++- App/src/TestPerformance.cpp | 28 ++++++++++++- Core/Algorithms/inc/SpecularMatrix.h | 1 + Core/Algorithms/src/OpticalFresnel.cpp | 2 +- Core/Algorithms/src/SpecularMatrix.cpp | 19 +++++---- dev-tools/log/perf_history.txt | 4 +- 11 files changed, 56 insertions(+), 122 deletions(-) delete mode 100644 .metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW DWBA Formfactor.launch delete mode 100644 .metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Diffuse.launch delete mode 100644 .metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Formfactor.launch delete mode 100644 .metadata/.plugins/org.eclipse.debug.core/.launches/GISASFW Fresnel.launch 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 ba2c97ca0cf..00000000000 --- 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 7c6526ed0d2..00000000000 --- 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 c0f5397733d..00000000000 --- 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 80a990b6ba3..00000000000 --- 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 e9636c6db4e..7b2358a59ea 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/inc/TestPerformance.h b/App/inc/TestPerformance.h index b1a90edc7e8..b456a8adfa7 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/src/TestPerformance.cpp b/App/src/TestPerformance.cpp index dc6b0a58d86..ca49bee1f3a 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/Core/Algorithms/inc/SpecularMatrix.h b/Core/Algorithms/inc/SpecularMatrix.h index 70b8cec3580..b0b988bbb02 100644 --- a/Core/Algorithms/inc/SpecularMatrix.h +++ b/Core/Algorithms/inc/SpecularMatrix.h @@ -41,6 +41,7 @@ public: 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 diff --git a/Core/Algorithms/src/OpticalFresnel.cpp b/Core/Algorithms/src/OpticalFresnel.cpp index 824f49b70dc..172dc5dd222 100644 --- a/Core/Algorithms/src/OpticalFresnel.cpp +++ b/Core/Algorithms/src/OpticalFresnel.cpp @@ -160,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 index f078ad3790c..07b0c097f6b 100644 --- a/Core/Algorithms/src/SpecularMatrix.cpp +++ b/Core/Algorithms/src/SpecularMatrix.cpp @@ -38,25 +38,28 @@ void SpecularMatrix::calculateEigenvalues(const MultiLayer& sample, 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)/sinalpha; + coeff[i].lambda = std::sqrt(rindex*rindex - r2cosalpha2); } } void SpecularMatrix::calculateTransferMatrices(const MultiLayer& sample, const kvector_t& k, MultiLayerCoeff_t& coeff) const { - double ksinalpha = k.mag()*std::abs( k.cosTheta() ); // 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 coskdsinlambda = std::cos(ksinalpha*sample.getLayer(i)->getThickness()*lambda); - complex_t sinkdsinlambda = std::sin(ksinalpha*sample.getLayer(i)->getThickness()*lambda); - coeff[i].l(0,0) = coskdsinlambda; - coeff[i].l(0,1) = -complex_t(0.0, 1.0)*lambda*sinkdsinlambda; - coeff[i].l(1,0) = -complex_t(0.0, 1.0)*sinkdsinlambda/lambda; - coeff[i].l(1,1) = coskdsinlambda; + 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: diff --git a/dev-tools/log/perf_history.txt b/dev-tools/log/perf_history.txt index d0d52e739f7..cf9e623a2a2 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 | -- GitLab