From 6578af993779a0b7bfe7d7aed7d6f70b857a823d Mon Sep 17 00:00:00 2001 From: Thomas Kittelmann Date: Mon, 19 Aug 2024 10:28:13 +0200 Subject: [PATCH] import from dgcode ncrystaldev git: candidate for version 3.9.2 --- CHANGELOG | 33 ++++++++++++------- CMakeLists.txt | 2 +- NCrystal/__init__.py | 2 +- NCrystal/_mmc.py | 27 ++++++++++++--- VERSION | 2 +- ncrystal_core/include/NCrystal/NCVersion.hh | 6 ++-- .../include/NCrystal/internal/NCMMC_Defs.hh | 2 +- .../NCrystal/internal/NCMMC_StdTallies.hh | 7 ++-- ncrystal_core/include/NCrystal/ncrystal.h | 6 ++-- 9 files changed, 60 insertions(+), 27 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4fb5094d..d49373a2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +v3.9.2 2024-08-19 + * Prevent rare error in the MiniMC framework, which happened when acos was + evaluated on a value which due to numerical instabilities was ever so + slightly larger than one. + * Minor tweaks to MMC parsing and plotting code. + v3.9.1 2024-08-16 * Add missing _hklobjects.py file which was left out by mistake. Thus making the newly introduced info.hklObjects() function actually work. @@ -64,11 +70,12 @@ v3.9.0 2024-08-12 show all output from NCrystal in some dedicated text box). * NCrystal has been updated to work with latest versions of Numpy, Clang, GCC, Python, Gemmi, and Spglib. Additionally work has started to support - Intel OneAPI compilers and Microsoft VSCode, although more work is needed - to finalise this. As part of these efforts, the ABI had to be broken in - some places, since for instance Microsoft VSCode did not support all the - data structures used previously (for instance, VSCode's `std::vector` - does not accept move-only objects like `std::unique_ptr`). + Intel OneAPI compilers and Microsoft VisualStudio, although more work is + needed to finalise this. As part of these efforts, the ABI had to be + broken in some places, since for instance Microsoft VisualStudio did not + support all the data structures used previously (for instance, + VisualStudio `std::vector` does not accept move-only objects like + `std::unique_ptr`). * This concludes the highlights in this changelog entry - refer to the following items for more detailed information about specific changes. * Several speedups of the phonon convolution calculation code was @@ -87,15 +94,16 @@ v3.9.0 2024-08-12 function, the NCrystal.enableFactoryThreads Python function, or the ncrystal_enable_factory_threadpool C function. * Build NCrystal library with -fno-math-errno (github issue #169). - * Several non-trivial fixes were implemented to prepare for MS VSCode and - Intel oneapi compilation support. This breaks ABI. + * Several non-trivial fixes were implemented to prepare for MS VisualStudio + and Intel oneapi compilation support. This breaks ABI. * Apply -fp-model=precise for intel oneapi compiler. * Change C++ DynamicInfoList type from std::vector> to typedef - SmallVector,4>, since VSCode apparently does - not support std::vector's with move-only objects. This in principle - breaks the ABI and API, but is deemed necessary. A few other types in - internal non-API headers were changed as well for the same reason. + SmallVector,4>, since VisualStudio + apparently does not support std::vector's with move-only objects. This in + principle breaks the ABI and API, but is deemed necessary. A few other + types in internal non-API headers were changed as well for the same + reason. * Fix build error due to ODR violation in the TopLvlVar type. * Removed noexcept from C++ functions where it should not have been added (e.g. those used for streaming to std::ostream). @@ -134,6 +142,9 @@ v3.9.0 2024-08-12 feature is for now kept out of the documentation, but can be tested with: "nctool --bench --help". * Updated year in copyright notice in all files. + * Info objects gets a new .hklObjects() method which returns HKL list + information in a more object oriented and convenient format than the + existing .hklList(). See issue #164 for more details. v3.8.2 2024-04-30 * Add importlib_metadata as python build dependency for Python < 3.8. diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eca489c..5d55e323 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,7 @@ endif() cmake_policy( SET CMP0048 NEW )#Not sure if this is really needed -project( NCrystal VERSION 3.9.1 ${_project_metadata} ) +project( NCrystal VERSION 3.9.2 ${_project_metadata} ) unset( _project_metadata ) diff --git a/NCrystal/__init__.py b/NCrystal/__init__.py index aa79dc03..0aaba61c 100644 --- a/NCrystal/__init__.py +++ b/NCrystal/__init__.py @@ -54,7 +54,7 @@ #NB: Synchronize meta-data below with fields in setup.py+template_setup.py.in meta data: __license__ = "Apache 2.0, http://www.apache.org/licenses/LICENSE-2.0" -__version__ = '3.9.1' +__version__ = '3.9.2' __status__ = "Production" __author__ = "NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)" __copyright__ = "Copyright 2015-2024 %s"%__author__ diff --git a/NCrystal/_mmc.py b/NCrystal/_mmc.py index 54f59137..ad4c8170 100644 --- a/NCrystal/_mmc.py +++ b/NCrystal/_mmc.py @@ -439,7 +439,14 @@ def calcfrac(h): if title: plt.title(title) - plt.suptitle(self.cfgstr) + suptitle_fs = 'medium' + if len(self.cfgstr)>40: + suptitle_fs = 'small' + if len(self.cfgstr)>80: + suptitle_fs = 'x-small' + if len(self.cfgstr)>101: + suptitle_fs = 'xx-small' + plt.suptitle(self.cfgstr,fontsize=suptitle_fs) absfracstr = 'unknown fraction' if tot_integral_with_absorption and tot_integral: @@ -448,6 +455,7 @@ def calcfrac(h): plt.plot([], [], ' ', label="Absorbed %s"%absfracstr) legargs = {} + _plt_final(do_grid = do_grid, do_legend = do_legend, do_show = do_show, @@ -505,10 +513,14 @@ def _parse_unit(valstr,unitmap): def _parse_energy( valstr ): v,u,uv = _parse_unit( valstr, _energy_units ) + if v is not None and u is None and uv is None: + from .exceptions import NCBadInput + raise NCBadInput('Invalid energy specification (missing unit' + f' like Aa or eV): "{valstr}"') if v is None: from .exceptions import NCBadInput raise NCBadInput(f'Invalid energy specification: "{valstr}"') - if u.lower() in ('aa','angstrom'): + if u is not None and u.lower() in ('aa','angstrom'): from .constants import wl2ekin return wl2ekin(v) v *= uv @@ -516,6 +528,11 @@ def _parse_energy( valstr ): def _parse_length( valstr, mfp = None ): v,u,uv = _parse_unit( valstr, _length_units ) + if v is not None and u is None and uv is None: + from .exceptions import NCBadInput + _ex0="mfp" if mfp is not None else "mm" + raise NCBadInput('Invalid length specification (missing unit like ' + f'{_ex0} or cm): "{valstr}"') if v is None: from .exceptions import NCBadInput raise NCBadInput(f'Invalid length specification: "{valstr}"') @@ -564,7 +581,8 @@ def _round2digits(x): def quick_diffraction_pattern( cfgstr, *, neutron_energy, material_thickness, - nstat = 'auto' ): + nstat = 'auto', + nthreads = 'auto' ): ### TODO: change c-api and use: ### from .misc import MaterialSource @@ -598,7 +616,8 @@ def simfct( n, cfgstr ): geomcfg = f'sphere;r={r_meter}', srccfg = (f'constant;ekin={neutron_energy_eV}' f';n={n};z={-r_meter*(1-1e-13)}'), - tally_detail_lvl = 2 + tally_detail_lvl = 2, + nthreads = nthreads ) t1 = time.time() return t1-t0, res diff --git a/VERSION b/VERSION index 6bd10744..2009c7df 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.9.1 +3.9.2 diff --git a/ncrystal_core/include/NCrystal/NCVersion.hh b/ncrystal_core/include/NCrystal/NCVersion.hh index c32683b8..31990952 100644 --- a/ncrystal_core/include/NCrystal/NCVersion.hh +++ b/ncrystal_core/include/NCrystal/NCVersion.hh @@ -39,9 +39,9 @@ #define NCRYSTAL_VERSION_MAJOR 3 #define NCRYSTAL_VERSION_MINOR 9 -#define NCRYSTAL_VERSION_PATCH 1 -#define NCRYSTAL_VERSION 3009001 /* (1000000*MAJOR+1000*MINOR+PATCH) */ -#define NCRYSTAL_VERSION_STR "3.9.1" +#define NCRYSTAL_VERSION_PATCH 2 +#define NCRYSTAL_VERSION 3009002 /* (1000000*MAJOR+1000*MINOR+PATCH) */ +#define NCRYSTAL_VERSION_STR "3.9.2" #include "NCrystal/ncapi.h" #include diff --git a/ncrystal_core/include/NCrystal/internal/NCMMC_Defs.hh b/ncrystal_core/include/NCrystal/internal/NCMMC_Defs.hh index 2d76512d..f4e9c729 100644 --- a/ncrystal_core/include/NCrystal/internal/NCMMC_Defs.hh +++ b/ncrystal_core/include/NCrystal/internal/NCMMC_Defs.hh @@ -55,7 +55,7 @@ namespace NCRYSTAL_NAMESPACE { #ifndef NDEBUG #define NCRYSTAL_DEBUGMMCMSG(msg) ::NCRYSTAL_NAMESPACE::Msg::detail:: \ outputMsgMS( ::NCRYSTAL_NAMESPACE::Msg::detail::MsgStream() << "MMC:" << msg, \ - ::NCRYSTAL_NAMESPACE::MsgType::Warning ); + ::NCRYSTAL_NAMESPACE::MsgType::Info ); #else # define NCRYSTAL_DEBUGMMCMSG(msg) {} #endif diff --git a/ncrystal_core/include/NCrystal/internal/NCMMC_StdTallies.hh b/ncrystal_core/include/NCrystal/internal/NCMMC_StdTallies.hh index ae85c398..384edc5e 100644 --- a/ncrystal_core/include/NCrystal/internal/NCMMC_StdTallies.hh +++ b/ncrystal_core/include/NCrystal/internal/NCMMC_StdTallies.hh @@ -99,8 +99,11 @@ namespace NCRYSTAL_NAMESPACE { const std::size_t n = b.size(); NCRYSTAL_DEBUGMMCMSG("Got result basket with size "< -(1.0+1e-14) ); + nc_assert( b.neutrons.uz[i] < (1.0+1e-14) ); + exit_angle[i] = std::acos( ncclamp(b.neutrons.uz[i],-1.0,1.0) ); + } for ( std::size_t i = 0; i < n; ++i ) exit_angle[i] *= kToDeg; for ( std::size_t i = 0; i < n; ++i ) diff --git a/ncrystal_core/include/NCrystal/ncrystal.h b/ncrystal_core/include/NCrystal/ncrystal.h index 0a06c7a4..63d8238f 100644 --- a/ncrystal_core/include/NCrystal/ncrystal.h +++ b/ncrystal_core/include/NCrystal/ncrystal.h @@ -1201,9 +1201,9 @@ extern "C" { #endif #define NCRYSTAL_VERSION_MAJOR 3 #define NCRYSTAL_VERSION_MINOR 9 -#define NCRYSTAL_VERSION_PATCH 1 -#define NCRYSTAL_VERSION 3009001 /* (1000000*MAJOR+1000*MINOR+PATCH) */ -#define NCRYSTAL_VERSION_STR "3.9.1" +#define NCRYSTAL_VERSION_PATCH 2 +#define NCRYSTAL_VERSION 3009002 /* (1000000*MAJOR+1000*MINOR+PATCH) */ +#define NCRYSTAL_VERSION_STR "3.9.2" NCRYSTAL_API int ncrystal_version(void); /* returns NCRYSTAL_VERSION */ NCRYSTAL_API const char * ncrystal_version_str(void); /* returns NCRYSTAL_VERSION_STR */