diff --git a/App/App.pro b/App/App.pro index 42b7cc5928ee28ae6903dbb29928719f70487ae6..d7b46005124df05db23d081ddac13d197d873b44 100644 --- a/App/App.pro +++ b/App/App.pro @@ -115,6 +115,15 @@ HEADERS += \ inc/TestToyExperiment.h \ inc/TreeEventStructure.h +# to through exception in the case floating point exception (gcc only) +CONFIG(DEBUG_FPE) { + HEADERS += inc/fp_exception_glibc_extension.h + SOURCES += src/fp_exception_glibc_extension.c +} + + + + # additional locations LOCATIONS = ./inc $${FUNCTIONAL_TESTS}/IsGISAXS01 INCLUDEPATH += $${LOCATIONS} diff --git a/App/inc/fp_exception_glibc_extension.h b/App/inc/fp_exception_glibc_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..c4a31fc7691adba710810a690356101d7f57429c --- /dev/null +++ b/App/inc/fp_exception_glibc_extension.h @@ -0,0 +1,64 @@ +/* + glibc floating point extension replacement for OS X. + + Title: Floating-point exception handling example + Author: David N. Williams + File: fe-handlng-example.c + License: Public Domain + Version: 0.5.0 + +*/ + +#ifndef __FENV_H_LINUX_REPLACEMENT__ +#define __FENV_H_LINUX_REPLACEMENT__ + +//#include <fenv.h> +#include <signal.h> +#ifdef __cplusplus +extern "C" { +#endif + + /* GNU C Library: + http://www.gnu.org/software/libc/manual/html_node/Control-Functions.html + + - Function: int fegetexcept (int excepts) + + The function returns a bitmask of all currently enabled + exceptions. It returns -1 in case of failure. + + The excepts argument appears in other functions in fenv.h, + and corresponds to the FE_xxx exception flag constants. It + is unclear whether the bitmask is for the flags or the masks. + We return that for the flags, which corresponds to the + excepts argument in feenableexcept(excepts) and + fedisableexcept(excepts). In GNU/Linux the argument is void, + and that's what we implement. Linux "man fegetenv" appears + to suggest that it's the mask corresponding to bits in + excepts that is returned. + */ + int fegetexcept (void) ; + int feenableexcept (unsigned int excepts) ; + int fedisableexcept (unsigned int excepts) ; + + /* SAMPLE ALTERNATE FP EXCEPTION HANDLER + + The sample handler just reports information about the + exception that invoked it, and aborts. It makes no attempt + to restore state and return to the application. + + More sophisticated handling would have to confront at least + these issues: + + * interface to the system context for restoring state + * imprecision of interrupts from hardware for the intel x87 + fpu (but not the SIMD unit, nor the ppc) + * imprecision of interrupts from system software + */ + void fhdl ( int sig, siginfo_t *sip, ucontext_t *scp ) ; + +#ifdef __cplusplus +} +#endif + + +#endif // __FENV_H_LINUX_REPLACEMENT__ diff --git a/App/src/TestFittingModule1.cpp b/App/src/TestFittingModule1.cpp index 8b233a07037231ca098bde53804c30c0531242d1..2b77aa5ba3935e09656b1ca133fdeb7b6098ffa0 100644 --- a/App/src/TestFittingModule1.cpp +++ b/App/src/TestFittingModule1.cpp @@ -58,13 +58,12 @@ void TestFittingModule1::execute() initializeRealData(); m_fitSuite->addExperimentAndRealData(*mp_experiment, *mp_real_data); -// m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Minuit2", "Migrad") ); -// m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Fumili") ); -// m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Minuit2", "Fumili") ); -// m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("GSLMultiFit") ); // LMA + m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Minuit2", "Migrad") ); + //m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Fumili") ); + //m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Minuit2", "Fumili") ); + //m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("GSLMultiFit") ); // LMA //m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("GSLSimAn") ); - // FIXME BUG genetic minimizer crashes when there are no upper limits on parameters - m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Genetic") ); + //m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Genetic") ); //m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Scan") ); m_fitSuite->attachObserver( FitSuiteObserverFactory::createPrintObserver() ); diff --git a/App/src/TestFittingModule3.cpp b/App/src/TestFittingModule3.cpp index 29b57729bfb432b65f51a5dff7724de4dad1f327..58bc60186b6c6416b673e23d9ff7189991526afc 100644 --- a/App/src/TestFittingModule3.cpp +++ b/App/src/TestFittingModule3.cpp @@ -29,6 +29,7 @@ #include "TPaveText.h" + TestFittingModule3::TestFittingModule3() : m_experiment(0) , m_sample(0) @@ -43,6 +44,7 @@ TestFittingModule3::~TestFittingModule3() delete m_experiment; delete m_sample; delete m_real_data; + delete m_fitSuite; } @@ -55,43 +57,25 @@ void TestFittingModule3::execute() // setting up fitSuite m_fitSuite = new FitSuite(); - m_fitSuite->addFitParameter("*FormFactorCylinder/height", 2.13438715e+01*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); - m_fitSuite->addFitParameter("*FormFactorCylinder/radius", 2.13438715e+01*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); - m_fitSuite->addFitParameter("*FormFactorPrism3/half_side", 5.52767780e+01*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); - m_fitSuite->addFitParameter("*FormFactorPrism3/height", 2.00000000e+00*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); -// m_fitSuite->addFitParameter("*FormFactorCylinder/height", 12*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); -// m_fitSuite->addFitParameter("*FormFactorCylinder/radius", 2*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); -// m_fitSuite->addFitParameter("*FormFactorPrism3/half_side", 12*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); -// m_fitSuite->addFitParameter("*FormFactorPrism3/height", 2*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); -// m_fitSuite->addFitParameter("*FormFactorCylinder/height", 5.0001*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); -// m_fitSuite->addFitParameter("*FormFactorCylinder/radius", 5.0001*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); -// m_fitSuite->addFitParameter("*FormFactorPrism3/half_side", 5.0001*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); -// m_fitSuite->addFitParameter("*FormFactorPrism3/height", 5.0001*Units::nanometer, 1*Units::nanometer, AttLimits::lowerLimited(0.01) ); - + m_fitSuite->addFitParameter("*FormFactorCylinder/height", 5.1*Units::nanometer, 0.04*Units::nanometer, AttLimits::lowerLimited(0.01) ); + m_fitSuite->addFitParameter("*FormFactorCylinder/radius", 5.1*Units::nanometer, 0.04*Units::nanometer, AttLimits::lowerLimited(0.01) ); + m_fitSuite->addFitParameter("*FormFactorPrism3/half_side", 5.1*Units::nanometer, 0.04*Units::nanometer, AttLimits::lowerLimited(0.01) ); + m_fitSuite->addFitParameter("*FormFactorPrism3/height", 5.1*Units::nanometer, 0.04*Units::nanometer, AttLimits::lowerLimited(0.01) ); // // setting up fitSuite // ChiSquaredModule chiModule; // chiModule.setChiSquaredFunction( SquaredFunctionWithSystematicError() ); // m_fitSuite->addExperimentAndRealData(*mp_experiment, *mp_real_data, chiModule); - // putting scans for(DataScan_t::iterator it=m_data_scans.begin(); it!= m_data_scans.end(); ++it) { m_fitSuite->addExperimentAndRealData(*m_experiment, *(*it)); } - m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Test") ); - //m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Minuit2", "Migrad") ); -// m_fitSuite->attachObserver( FitSuiteObserverFactory::createPrintObserver(1) ); -// m_fitSuite->attachObserver( FitSuiteObserverFactory::createDrawObserver(1) ); - - -// 2.13438715e+01 -// 2.13438715e+01 -// 7.82767780e+01 -// 2.00000000e+00 + m_fitSuite->setMinimizer( MinimizerFactory::createMinimizer("Minuit2", "Migrad") ); + m_fitSuite->attachObserver( FitSuiteObserverFactory::createPrintObserver() ); + m_fitSuite->attachObserver( FitSuiteObserverFactory::createDrawObserver() ); m_fitSuite->runFit(); - } @@ -121,19 +105,10 @@ void TestFittingModule3::initializeExperiment() void TestFittingModule3::initializeSample() { delete m_sample; - // 2.13438715e+01 - // 2.13438715e+01 - // 7.82767780e+01 - // 2.00000000e+00 - - double cylinder_height = 2.13438715e+01; - double cylinder_radius = 2.13438715e+01; - double prism3_half_side = 7.82767780e+01; - double prism3_height = 2.00000000e+00; -// double cylinder_height = 5.0*Units::nanometer; -// double cylinder_radius = 5.0*Units::nanometer; -// double prism3_half_side = 5.0*Units::nanometer; -// double prism3_height = 5.0*Units::nanometer; + double cylinder_height = 5.0*Units::nanometer; + double cylinder_radius = 5.0*Units::nanometer; + double prism3_half_side = 5.0*Units::nanometer; + double prism3_height = 5.0*Units::nanometer; MultiLayer *p_multi_layer = new MultiLayer(); complex_t n_air(1.0, 0.0); complex_t n_substrate(1.0-6e-6, 2e-8); diff --git a/App/src/fp_exception_glibc_extension.c b/App/src/fp_exception_glibc_extension.c new file mode 100644 index 0000000000000000000000000000000000000000..252921b76d29b934cb6abaa7815187ab3767be57 --- /dev/null +++ b/App/src/fp_exception_glibc_extension.c @@ -0,0 +1,332 @@ +/* Title: Floating-point exception handling example + Author: David N. Williams + File: fe-handlng-example.c + License: Public Domain + Version: 0.5.0 + Started: 21-Sep-09 + Revised: 22-Sep-09 + Revised: 30-Sep-09 (comment typo) + Revised: 18 Oct-12 (chnaged char* to const char * on line 228, by Richard Booth) + +This code is an example of alternate, nondefault handling of +IEEE 754 floating-point exceptions in OS X and Linux, based on +the GNU functions feenableexcept(), fedisableeexcept(), and +fegetexcept() [in libm], plus POSIX sigaction(). + +The GNU functions above are not implemented in OS X Leopard, +gcc 4.x, but are present in Linux. We implement them here for +OS X, at least until the underlying mechanism is no longer +supported by Apple. + +The mechanism is to use the POSIX functions fegetenv() and +fesetenv(), which *are* present in OS X, to manipulate the ppc +and intel floating-point control registers, after changing bits +in fields corresponding to those registers in the fenv_t data +type. + +Assembly language code to directly access the floating-point +status and control registers for ppc and intel is also included. + +This example grew out of an update to legacy code for Apple +ppc's. The original legacy code is in Listing 7-1 in "PowerPC +Numerics", 2004: + +http://lists.apple.com/archives/unix-porting/2003/May/msg00026.html + +Another version of the ppc legacy code is here: + +http://developer.apple.com/documentation/Performance/Conceptual/Mac_OSX_Numerics/Mac_OSX_Numerics.pdf + +Terry Lambert pointed out that our naive update of the legacy +example to Mac OS X Leopard made egregious unsupported use of +system context structures in the handler. See his reply to + +http://lists.apple.com/archives/Darwin-dev/2009/Sep/msg00091.html + +The example in this file is more plain vanilla, and aims at +alternate handling that does not return to the application, but +rather aborts with a diagnostic message. + +To compile it under Mac OS X, execute: + + cc -o fe-handling fe-handling-example.c + +To compile it under Linux, execute: + + cc -DLINUX -lm -o fe-handling fe-handling-example.c +*/ + +#ifdef LINUX +/* BEGIN quote +http://graphviz.sourcearchive.com/documentation/2.16/gvrender__pango_8c-source.html +*/ +/* _GNU_SOURCE is needed (supposedly) for the feenableexcept + * prototype to be defined in fenv.h on GNU systems. + * Presumably it will do no harm on other systems. + */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +/* We are not supposed to need __USE_GNU, but I can't see + * how to get the prototype for fedisableexcept from + * /usr/include/fenv.h without it. + */ +#ifndef __USE_GNU +#define __USE_GNU +#endif +/* END quote */ +#endif // LINUX + +#include <fenv.h> + +#define DEFINED_PPC (defined(__ppc__) || defined(__ppc64__)) +#define DEFINED_INTEL (defined(__i386__) || defined(__x86_64__)) + +#ifndef LINUX +#if DEFINED_PPC + +#define FE_EXCEPT_SHIFT 22 // shift flags right to get masks +#define FM_ALL_EXCEPT FE_ALL_EXCEPT >> FE_EXCEPT_SHIFT + +/* GNU C Library: +http://www.gnu.org/software/libc/manual/html_node/Control-Functions.html + + - Function: int fegetexcept (int excepts) + + The function returns a bitmask of all currently enabled + exceptions. It returns -1 in case of failure. + + The excepts argument appears in other functions in fenv.h, + and corresponds to the FE_xxx exception flag constants. It + is unclear whether the bitmask is for the flags or the masks. + We return that for the flags, which corresponds to the + excepts argument in feenableexcept(excepts) and + fedisableexcept(excepts). In GNU/Linux the argument is void, + and that's what we implement. Linux "man fegetenv" appears + to suggest that it's the mask corresponding to bits in + excepts that is returned. +*/ +int +fegetexcept (void) +{ + static fenv_t fenv; + + return ( fegetenv (&fenv) ? -1 : + ( + ( fenv & (FM_ALL_EXCEPT) ) << FE_EXCEPT_SHIFT ) + ); +} + +int +feenableexcept (unsigned int excepts) +{ + static fenv_t fenv; + unsigned int new_excepts = (excepts & FE_ALL_EXCEPT) >> FE_EXCEPT_SHIFT, + old_excepts; // all previous masks + + if ( fegetenv (&fenv) ) return -1; + old_excepts = (fenv & FM_ALL_EXCEPT) << FE_EXCEPT_SHIFT; + + fenv = (fenv & ~new_excepts) | new_excepts; + return ( fesetenv (&fenv) ? -1 : old_excepts ); +} + +int +fedisableexcept (unsigned int excepts) +{ + static fenv_t fenv; + unsigned int still_on = ~( (excepts & FE_ALL_EXCEPT) >> FE_EXCEPT_SHIFT ), + old_excepts; // previous masks + + if ( fegetenv (&fenv) ) return -1; + old_excepts = (fenv & FM_ALL_EXCEPT) << FE_EXCEPT_SHIFT; + + fenv &= still_on; + return ( fesetenv (&fenv) ? -1 : old_excepts ); +} + +#elif DEFINED_INTEL + +int +fegetexcept (void) +{ + static fenv_t fenv; + + return fegetenv (&fenv) ? -1 : (fenv.__control & FE_ALL_EXCEPT); +} + +int +feenableexcept (unsigned int excepts) +{ + static fenv_t fenv; + unsigned int new_excepts = excepts & FE_ALL_EXCEPT, + old_excepts; // previous masks + + if ( fegetenv (&fenv) ) return -1; + old_excepts = fenv.__control & FE_ALL_EXCEPT; + + // unmask + fenv.__control &= ~new_excepts; + fenv.__mxcsr &= ~(new_excepts << 7); + + return ( fesetenv (&fenv) ? -1 : old_excepts ); +} + +int +fedisableexcept (unsigned int excepts) +{ + static fenv_t fenv; + unsigned int new_excepts = excepts & FE_ALL_EXCEPT, + old_excepts; // all previous masks + + if ( fegetenv (&fenv) ) return -1; + old_excepts = fenv.__control & FE_ALL_EXCEPT; + + // mask + fenv.__control |= new_excepts; + fenv.__mxcsr |= new_excepts << 7; + + return ( fesetenv (&fenv) ? -1 : old_excepts ); +} + +#endif // PPC or INTEL enabling +#endif // not LINUX + +#if DEFINED_PPC + +#define getfpscr(x) asm volatile ("mffs %0" : "=f" (x)); +#define setfpscr(x) asm volatile ("mtfsf 255,%0" : : "f" (x)); + +typedef union { + struct { + unsigned long hi; + unsigned long lo; + } i; + double d; +} hexdouble; + +#endif // DEFINED_PPC + +#if DEFINED_INTEL + +// x87 fpu +#define getx87cr(x) asm ("fnstcw %0" : "=m" (x)); +#define setx87cr(x) asm ("fldcw %0" : "=m" (x)); +#define getx87sr(x) asm ("fnstsw %0" : "=m" (x)); + +// SIMD, gcc with Intel Core 2 Duo uses SSE2(4) +#define getmxcsr(x) asm ("stmxcsr %0" : "=m" (x)); +#define setmxcsr(x) asm ("ldmxcsr %0" : "=m" (x)); + +#endif // DEFINED_INTEL + +#include <signal.h> +#include <stdio.h> // printf() +#include <stdlib.h> // abort(), exit() + +static const char *fe_code_name[] = { + "FPE_NOOP", + "FPE_FLTDIV", "FPE_FLTINV", "FPE_FLTOVF", "FPE_FLTUND", + "FPE_FLTRES", "FPE_FLTSUB", "FPE_INTDIV", "FPE_INTOVF" + "FPE_UNKNOWN" +}; + +/* SAMPLE ALTERNATE FP EXCEPTION HANDLER + + The sample handler just reports information about the + exception that invoked it, and aborts. It makes no attempt + to restore state and return to the application. + + More sophisticated handling would have to confront at least + these issues: + + * interface to the system context for restoring state + * imprecision of interrupts from hardware for the intel x87 + fpu (but not the SIMD unit, nor the ppc) + * imprecision of interrupts from system software +*/ +void +fhdl ( int sig, siginfo_t *sip, ucontext_t *scp ) +{ + int fe_code = sip->si_code; + unsigned int excepts = fetestexcept (FE_ALL_EXCEPT); + + switch (fe_code) + { +#ifdef FPE_NOOP // occurs in OS X + case FPE_NOOP: fe_code = 0; break; +#endif + case FPE_FLTDIV: fe_code = 1; break; // divideByZero + case FPE_FLTINV: fe_code = 2; break; // invalid + case FPE_FLTOVF: fe_code = 3; break; // overflow + case FPE_FLTUND: fe_code = 4; break; // underflow + case FPE_FLTRES: fe_code = 5; break; // inexact + case FPE_FLTSUB: fe_code = 6; break; // invalid + case FPE_INTDIV: fe_code = 7; break; // overflow + case FPE_INTOVF: fe_code = 8; break; // underflow + default: fe_code = 9; + } + + if ( sig == SIGFPE ) + { +#if DEFINED_INTEL + unsigned short x87cr,x87sr; + unsigned int mxcsr; + + getx87cr (x87cr); + getx87sr (x87sr); + getmxcsr (mxcsr); + printf ("X87CR: 0x%04X\n", x87cr); + printf ("X87SR: 0x%04X\n", x87sr); + printf ("MXCSR: 0x%08X\n", mxcsr); +#endif + +#if DEFINED_PPC + hexdouble t; + + getfpscr (t.d); + printf ("FPSCR: 0x%08X\n", t.i.lo); +#endif + + printf ("signal: SIGFPE with code %s\n", fe_code_name[fe_code]); + printf ("invalid flag: 0x%04X\n", excepts & FE_INVALID); + printf ("divByZero flag: 0x%04X\n", excepts & FE_DIVBYZERO); + } + else printf ("Signal is not SIGFPE, it's %i.\n", sig); + + abort(); +} + + +/* +int main (int argc, char **argv) +{ + double s; +// struct sigaction act; +// +// //act.sa_sigaction = (void(*))fhdl; +// act.sa_sigaction = reinterpret_cast<void *>(fhdl); +// sigemptyset (&act.sa_mask); +// act.sa_flags = SA_SIGINFO; + + +// printf ("Old divByZero exception: 0x%08X\n", feenableexcept (FE_DIVBYZERO)); +// printf ("Old invalid exception: 0x%08X\n", feenableexcept (FE_INVALID)); +// printf ("New fp exception: 0x%08X\n", fegetexcept ()); + + feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); + + // set handler +// if (sigaction(SIGFPE, &act, (struct sigaction *)0) != 0) +// { +// perror("Yikes"); +// exit(-1); +// } + +// s = 1.0 / 0.0; // FE_DIVBYZERO + s = 0.0 / 0.0; // FE_INVALID + return 0; +} + +*/ diff --git a/App/src/main.cpp b/App/src/main.cpp index bd80b9500a6f61444a232f542b1fe0ac05be13a0..554814cbaa4b31711538dbb548ee82e360d634a9 100644 --- a/App/src/main.cpp +++ b/App/src/main.cpp @@ -9,9 +9,19 @@ #include "TROOT.h" #include "TApplication.h" +#ifdef DEBUG_FPE +#include <fenv.h> +#include "fp_exception_glibc_extension.h" +#endif + int main(int argc, char **argv) { - std::cout << "Hello Brave New World! It's me." << std::endl; +#ifdef DEBUG_FPE + std::cout << "main() -> Enabling floating point exception debugging" << std::endl; + feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); +#endif + + std::cout << "Hello Brave New World!" << std::endl; ProgramOptions command_line_options; AddApplicationOptions(&command_line_options); AddCoreOptions(&command_line_options); diff --git a/Core/Algorithms/inc/IOutputDataNormalizer.h b/Core/Algorithms/inc/IOutputDataNormalizer.h index 743224b959082537ce32162b49f764fa916e26c7..330ffcb156c52ab10a0d2953eba2edaebe95204f 100644 --- a/Core/Algorithms/inc/IOutputDataNormalizer.h +++ b/Core/Algorithms/inc/IOutputDataNormalizer.h @@ -20,7 +20,7 @@ /* ************************************************************************* */ // Normalize output data /* ************************************************************************* */ -class IOutputDataNormalizer : public IParameterized, public ICloneable +class IOutputDataNormalizer : public IParameterized { public: virtual ~IOutputDataNormalizer() {} diff --git a/Core/Algorithms/src/Experiment.cpp b/Core/Algorithms/src/Experiment.cpp index be7c586a8143bdb1080217ca348cfdb42d605fd3..67138efcaed01b76218c031cf56b792be7e1355d 100644 --- a/Core/Algorithms/src/Experiment.cpp +++ b/Core/Algorithms/src/Experiment.cpp @@ -1,5 +1,11 @@ #include "Experiment.h" +//#ifdef DEBUG_FPE +//#include <fenv.h> +//#include "fp_exception_glibc_extension.h" +//#endif + + Experiment::Experiment() : IParameterized("Experiment") diff --git a/Core/Algorithms/src/LayerDecoratorDWBASimulation.cpp b/Core/Algorithms/src/LayerDecoratorDWBASimulation.cpp index a974c8c6629df81c5961c3b5ea5661850b4c9399..6b83904acb8fb4ef26913700c21a665e99dcebf4 100644 --- a/Core/Algorithms/src/LayerDecoratorDWBASimulation.cpp +++ b/Core/Algorithms/src/LayerDecoratorDWBASimulation.cpp @@ -100,7 +100,6 @@ void LayerDecoratorDWBASimulation::calculateCoherentIntensity(const IInterferenc } Bin1DCVector k_f_bin = getKfBin(wavelength, alpha_bin, phi_bin); *it_intensity = p_strategy->evaluate(k_ij, k_f_bin, -m_alpha_i, alpha_f)*total_surface_density; - std::cout << "XXX " << *it_intensity << std::endl; ++it_intensity; } } diff --git a/Core/Core.pro b/Core/Core.pro index ca178b0f4635aabb75150783224839c6eef985e4..baf0da03466bb846e68e99bc5a45e1fff553cbde 100644 --- a/Core/Core.pro +++ b/Core/Core.pro @@ -300,6 +300,13 @@ contains(CONFIG, BUILD_PYTHON_BOOST_MODULE) { include($$PWD/python_module.pri) } +## to through exception in the case floating point exception (gcc only) +#CONFIG(DEBUG_FPE) { +# HEADERS += Tools/inc/fp_exception_glibc_extension.h +# SOURCES += Tools/src/fp_exception_glibc_extension.c +#} + + OBJECTS_DIR = obj # ----------------------------------------------------------------------------- diff --git a/Core/FormFactors/inc/IFormFactorBorn.h b/Core/FormFactors/inc/IFormFactorBorn.h index c33f9b682e012f33d45dda16ec04f8b891234a85..605f124668760ec1b861b2fa17f4e56370ed3265 100644 --- a/Core/FormFactors/inc/IFormFactorBorn.h +++ b/Core/FormFactors/inc/IFormFactorBorn.h @@ -76,12 +76,12 @@ inline double IFormFactorBorn::getVolume() const inline bool IFormFactorBorn::useLargeBinApproximation(const Bin1DCVector &q_bin) const { -// (void)q_bin; double delta_qr = std::abs( q_bin.getDelta().magxy() ); + double delta_qz = std::abs( q_bin.getDelta().z() ); + if(delta_qr == 0 || delta_qz == 0) return false; if ( delta_qr > M_PI/(2.0*getRadius()) ) { return true; } - double delta_qz = std::abs( q_bin.getDelta().z() ); if ( delta_qz > M_PI/(2.0*getHeight()) ) { return true; } diff --git a/Core/FormFactors/src/FormFactorDWBAConstZ.cpp b/Core/FormFactors/src/FormFactorDWBAConstZ.cpp index 442a8b0fe1067be24e013f4ffe8f03ed8348acbc..2575d2bd2e5cd69db016185439d9a36d9a4a188d 100644 --- a/Core/FormFactors/src/FormFactorDWBAConstZ.cpp +++ b/Core/FormFactors/src/FormFactorDWBAConstZ.cpp @@ -21,6 +21,7 @@ complex_t FormFactorDWBAConstZ::evaluate(const cvector_t &k_i, const Bin1DCVecto m_term_RS *= getDepthPhase(-k_iz-k_fz); m_term_SR *= getDepthPhase(k_iz+k_fz); m_term_RSR *= getDepthPhase(-k_iz+k_fz); + return m_term_S + m_term_RS + m_term_SR + m_term_RSR; } diff --git a/Core/FormFactors/src/IFormFactorBorn.cpp b/Core/FormFactors/src/IFormFactorBorn.cpp index 692ee0747970afd52e5a7eaa667b9f53f1dd2e83..1f821f2309a7aa3c676b91414fd4928856cfda54 100644 --- a/Core/FormFactors/src/IFormFactorBorn.cpp +++ b/Core/FormFactors/src/IFormFactorBorn.cpp @@ -29,7 +29,9 @@ complex_t IFormFactorBorn::bigZPart(const Bin1DCVector& q_bin) const complex_t z_phase = std::exp(complex_t(0.0, 1.0)*qH2_c); // modulus of the height of the particle + assert(effective_bin_size_h2); double z_average_intensity = (bigZPartIntegral(qH2max) - bigZPartIntegral(qH2min))/effective_bin_size_h2; + assert(z_average_intensity); double z_modulus = std::sqrt(z_average_intensity); return z_phase*z_modulus; diff --git a/Core/Tools/inc/SafePointerVector.h b/Core/Tools/inc/SafePointerVector.h index 23bc85ccbb30f87a1c1e07682789e86b65730d36..ab054db049fa1fcab3d585b8909fff93f550128f 100644 --- a/Core/Tools/inc/SafePointerVector.h +++ b/Core/Tools/inc/SafePointerVector.h @@ -15,6 +15,7 @@ //! @date Dec 10, 2012 #include <vector> +using std::size_t; //- ------------------------------------------------------------------- //! @class SafePointerVector diff --git a/Tests/UnitTests/TestCore/TestCore b/Tests/UnitTests/TestCore/TestCore index 08ed831a7a7409781de5e4f441980fbfdf121b69..f4b40650d99dec7e57818df9f176ce7c71ee17ab 100755 Binary files a/Tests/UnitTests/TestCore/TestCore and b/Tests/UnitTests/TestCore/TestCore differ diff --git a/shared.pri b/shared.pri index e67e91253b3d892b76c7ed1bbfbed159206d81b0..edbef2729bb289e8634d3d66040fbdd47757e3cd 100644 --- a/shared.pri +++ b/shared.pri @@ -115,6 +115,13 @@ CONFIG(PEDANTIC) { QMAKE_CXXFLAGS_DEBUG += -Weffc++ } +# floating point exception handling +#CONFIG+=DEBUG_FPE +CONFIG(DEBUG_FPE) { + QMAKE_CXXFLAGS_DEBUG += -DDEBUG_FPE + !macx { QMAKE_CXXFLAGS_DEBUG += -DLINUX } +} + # hints # $${VAR} to access .pro variables, $$(VAR) to access environment variables