Skip to content

Commit

Permalink
Import candidate for 3.8.1 from ncrystaldev repo
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Apr 11, 2024
1 parent 2bf7bac commit fb1d033
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 22 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v3.8.1 2024-04-11
* Fix rare FPE in lcbragg code (github issue #171).
* Remove a few faulty noexcept modifiers in (found by cppcheck).
* Fix NCMatCfg::textData which technically returned a reference to a
temporary (although this is not believed to have actually caused any
issues, since the "temporary" came from a longer-lived shared_ptr). This
was also found with cppcheck.

v3.8.0 2023-12-03
* Completely obsolete the ncrystal_inspectfile command in favour of the
nctool command. Trying to invoke ncrystal_inspectfile now results in an
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ endif()

cmake_policy( SET CMP0048 NEW )#Not sure if this is really needed

project( NCrystal VERSION 3.8.0 ${_project_metadata} )
project( NCrystal VERSION 3.8.1 ${_project_metadata} )

unset( _project_metadata )

Expand Down
2 changes: 1 addition & 1 deletion NCrystal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.8.0'
__version__ = '3.8.1'
__status__ = "Production"
__author__ = "NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)"
__copyright__ = "Copyright 2015-2023 %s"%__author__
Expand Down
20 changes: 15 additions & 5 deletions NCrystal/vdos.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from .constants import constant_boltzmann as _constant_boltzmann
from .constants import constant_c as _constant_c

_is_unit_test = False

vdos_units_2_eV = {
'eV' : 1.0,
'meV' : 1e-3,
Expand Down Expand Up @@ -520,13 +522,13 @@ def plot_cutoff_effects( self, thresholds, *dos_labels_or_indices, gn = None,
else:
t_parsed = self._parse_threshold( t )
lblcomments = [f'cut@{t_parsed/unitfactor:g}{unitname}']
if not regn is None:
if regn is not None:
lblcomments+=[f'npts={regn}']
lblcomment = ','.join(lblcomments)
plot_kwargs['labelfct'] = lambda lbl : f'{lbl} ({lblcomment})'
color_offset += len(selected)
o = self if t is None else self.apply_cutoff( t, *selected )
if not regn is None:
if regn is not None:
if t is None:
#Only go ahead in this case, if all selected egrids already have a cutoff:
if not all( self.dos(idx)[0][0]>0.0 for idx in selected ):
Expand Down Expand Up @@ -748,7 +750,7 @@ def __sjolanderGn_args( self, selected, n=1, masses = None, temperature = 293.15
lbl = self.__d['doslist'][idx][0]
ad = atomDB(lbl,throwOnErrors=False)
if not ad:
raise NCBadInput( f'Can not plot Gn function for label "lbl" which does'
raise NCBadInput( 'Can not plot Gn function for label "lbl" which does'
' not correspond to a known element or isotope. Either'
' change the label with .update_label(..), or directly'
' provide masses using the "masses" parameter' )
Expand Down Expand Up @@ -804,7 +806,15 @@ def __plot( self, *dos_labels_or_indices, do_newfig = True, do_show = True, logy
color = colorder[(color_offset+idx)%len(colorder)]
actual_lbl = lbl if labelfct is None else labelfct(lbl)
if gnfct:
plt.plot( gnfct[0]/unitfactor, gnfct[1],
_x,_y = gnfct[0]/unitfactor, gnfct[1]
if _is_unit_test:
def _fixup_y(y):
from ._numpy import _ensure_numpy, _np
_ensure_numpy()
assert y.min() >= 0.0
return _np.clip(y,y.max()*1e-13,None)
_y = _fixup_y(_y)#discard tiny values
plt.plot( _x,_y,
label = actual_lbl,
color = color )
else:
Expand Down Expand Up @@ -994,7 +1004,7 @@ def retry():
if not abs(round(test)-test)<1e-6:
return retry()
new_density = _np.interp(new_egrid,egrid,density, left=0.0, right=0.0)
nc_print(f'last density values in new grid: ',new_density[-5:])
nc_print('last density values in new grid:',new_density[-5:])
return new_egrid,new_density

def _parsevdosunit( name ):
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.0
3.8.1
2 changes: 1 addition & 1 deletion ncrystal_core/include/NCrystal/NCFmt.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace NCRYSTAL_NAMESPACE {
//(i.e. constexpr auto sv = ShortStr::make("foo")): For now it is NOT
//constexpr, due to limitations in C++11. This could be revisited if needed.
template<size_type N>
static ShortStr make( const char (&cdata)[N] ) noexcept
static ShortStr make( const char (&cdata)[N] )
{
return ShortStr( &cdata[0], ( cdata[N-1]=='\0' ? N-1 : N ) );
}
Expand Down
1 change: 0 additions & 1 deletion ncrystal_core/include/NCrystal/NCMatCfg.hh
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ namespace NCRYSTAL_NAMESPACE {
namespace NCRYSTAL_NAMESPACE {
inline void MatCfg::set_temp( double t ) { set_temp(Temperature{t}); }
inline MatCfg MatCfg::clone() const { return MatCfg(*this); }
inline const TextData& MatCfg::textData() const { return textDataSP(); }
inline void MatCfg::scale_density( double val )
{
if ( val!= 1.0 ) {
Expand Down
12 changes: 7 additions & 5 deletions ncrystal_core/include/NCrystal/NCMem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ namespace NCRYSTAL_NAMESPACE {
//Move/copy/assign to base class pointer (in shared_obj or std::shared_ptr)
//should be ok (only compiles if T* can be assigned from TOther*):
template<class TOther>
ncconstexpr17 shared_obj& operator=( shared_obj<TOther>&& o ) noexcept {
ncconstexpr17 shared_obj& operator=( shared_obj<TOther>&& o ) ncnoexceptndebug {
m_shptr = std::move(o).detail_consume_shptr();
#ifndef NDEBUG
check_nonnull();
#endif
return *this;
}

Expand All @@ -163,21 +165,21 @@ namespace NCRYSTAL_NAMESPACE {
}

template<class TOther>
ncconstexpr17 shared_obj( std::shared_ptr<TOther>&& sp ) noexcept : m_shptr(std::move(sp)) { check_nonnull(); }
ncconstexpr17 shared_obj( std::shared_ptr<TOther>&& sp ) : m_shptr(std::move(sp)) { check_nonnull(); }

template<class TOther>
ncconstexpr17 shared_obj( const std::shared_ptr<TOther>& sp ) noexcept : m_shptr(sp) { check_nonnull(); }
ncconstexpr17 shared_obj( const std::shared_ptr<TOther>& sp ) : m_shptr(sp) { check_nonnull(); }

template<class TOther>
ncconstexpr17 shared_obj& operator=( std::shared_ptr<TOther>&& sp ) noexcept
ncconstexpr17 shared_obj& operator=( std::shared_ptr<TOther>&& sp )
{
m_shptr = std::move(sp);
check_nonnull();
return *this;
}

template<class TOther>
ncconstexpr17 shared_obj& operator=( const std::shared_ptr<TOther>& sp ) noexcept
ncconstexpr17 shared_obj& operator=( const std::shared_ptr<TOther>& sp )
{
m_shptr = sp;
check_nonnull();
Expand Down
6 changes: 3 additions & 3 deletions ncrystal_core/include/NCrystal/NCVersion.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

#define NCRYSTAL_VERSION_MAJOR 3
#define NCRYSTAL_VERSION_MINOR 8
#define NCRYSTAL_VERSION_PATCH 0
#define NCRYSTAL_VERSION 3008000 /* (1000000*MAJOR+1000*MINOR+PATCH) */
#define NCRYSTAL_VERSION_STR "3.8.0"
#define NCRYSTAL_VERSION_PATCH 1
#define NCRYSTAL_VERSION 3008001 /* (1000000*MAJOR+1000*MINOR+PATCH) */
#define NCRYSTAL_VERSION_STR "3.8.1"

#include "NCrystal/ncapi.h"
#include <stdexcept>
Expand Down
6 changes: 5 additions & 1 deletion ncrystal_core/include/NCrystal/internal/NCCfgTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ namespace NCRYSTAL_NAMESPACE {
Derived::stream_val(os,default_value_in_varbuf());
}
struct detail_dvon {
static constexpr value_type dvon( NullOptType ) { return nc_assert_always_rv(false),*(value_type*)(nullptr); }//won't actually get called
//Next fct won't actually get called
static constexpr value_type dvon( NullOptType )
{
return nc_assert_always_rv(false),*(value_type*)(nullptr);// cppcheck-suppress nullPointer
}
static constexpr value_type dvon( const value_type& v ) { return v; }
};
constexpr static value_type default_value_or_nonsense()
Expand Down
1 change: 1 addition & 0 deletions ncrystal_core/include/NCrystal/internal/NCGaussMos.hh
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ namespace NCRYSTAL_NAMESPACE {
{
nc_assert(ip.isValid());
nc_assert(ncabs(cos_angle_indir_normal)<=1.+1e-10);
cos_angle_indir_normal = ncclamp(cos_angle_indir_normal,-1.0,1.0);
if (ip.m_Q>0.) {
double sin_angle_indir_normal = std::sqrt(1.0-cos_angle_indir_normal*cos_angle_indir_normal);//>0 since angle is in 0..pi.
return ip.m_Q * m_gos.circleIntegral( cos_angle_indir_normal, sin_angle_indir_normal, ip.m_sin_perfect_theta, ip.m_cos_perfect_theta );
Expand Down
6 changes: 3 additions & 3 deletions ncrystal_core/include/NCrystal/ncrystal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,9 @@ extern "C" {
#endif
#define NCRYSTAL_VERSION_MAJOR 3
#define NCRYSTAL_VERSION_MINOR 8
#define NCRYSTAL_VERSION_PATCH 0
#define NCRYSTAL_VERSION 3008000 /* (1000000*MAJOR+1000*MINOR+PATCH) */
#define NCRYSTAL_VERSION_STR "3.8.0"
#define NCRYSTAL_VERSION_PATCH 1
#define NCRYSTAL_VERSION 3008001 /* (1000000*MAJOR+1000*MINOR+PATCH) */
#define NCRYSTAL_VERSION_STR "3.8.1"
NCRYSTAL_API int ncrystal_version(void); /* returns NCRYSTAL_VERSION */
NCRYSTAL_API const char * ncrystal_version_str(void); /* returns NCRYSTAL_VERSION_STR */

Expand Down
11 changes: 11 additions & 0 deletions ncrystal_core/src/NCMatCfg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,19 @@ NC::MatCfg NC::MatCfg::cloneThinned() const
return cfg;
}

const NC::TextData& NC::MatCfg::textData() const {
//NB: Sync checks and messages between this fct and the next
if ( m_impl->isMultiPhase() )
NCRYSTAL_THROW(LogicError,"MatCfg::textDataSP called for multiphase object");
if ( m_textDataSP == nullptr )
NCRYSTAL_THROW(LogicError,"MatCfg::textDataSP/textData methods should not be"
" used in a MatCfg object which was thinned or moved-from.");
return *m_textDataSP;
}

NC::TextDataSP NC::MatCfg::textDataSP() const
{
//NB: Sync checks and messages between this fct and the previous
if ( m_impl->isMultiPhase() )
NCRYSTAL_THROW(LogicError,"MatCfg::textDataSP called for multiphase object");
if ( m_textDataSP == nullptr )
Expand Down

0 comments on commit fb1d033

Please sign in to comment.