Skip to content

Commit

Permalink
import from dgcode git: version 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Dec 11, 2020
1 parent a71d86e commit 7c800a1
Show file tree
Hide file tree
Showing 53 changed files with 422 additions and 1,797 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
v2.3.0 2020-12-11
* Replace span class with a fully home-grown solution. This means that all
core NCrystal code is once more fully available under the primary
license (the Apache 2.0 license).
* Cfg parameters scatfactory and absnfactory now supports exclusion of
specific named factories. This is used to (by default) exclude current
factory from consideration when globalCreateScatter/Absorption is
invoked from a factory (github issue #51).
* Replace the '$(ncrystal-config --setup)' idiom with one which works also
when entries in PATH contains spaces: 'eval $(ncrystal-config --setup)'
(github isse #52).
* Rename internal radius variable in McStas sample, to avoid clashes with
component parameter (apparently this gave issues for McStas 3.0).

v2.2.2 2020-12-11
* Bugfix for system-wide installations. Input files were
accidentally opened in RW mode rather than just readonly, causing
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if(NOT DEFINED NCRYSTAL_NOTOUCH_CMAKE_BUILD_TYPE)
endif()

#Setup project:
project(NCrystal VERSION 2.2.2 LANGUAGES CXX C)
project(NCrystal VERSION 2.3.0 LANGUAGES CXX C)

if(NOT DEFINED NCRYSTAL_NOTOUCH_CMAKE_BUILD_TYPE)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
Expand Down
3 changes: 1 addition & 2 deletions FILES
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

NOTICE : Important notice concerning attribution and licensing.
README : Brief instructions.
LICENSE : License conditions (except for the file NCSpan.hh and code
in ./ncrystal_extra/)
LICENSE : License conditions (except for code in ./ncrystal_extra/)
VERSION : File containing the version of the distribution.
CHANGELOG : Release notes.
INSTALL : Build, installation and brief usage instructions.
Expand Down
12 changes: 4 additions & 8 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ and the Technical University of Denmark (DTU). This work was supported in part
by the European Union's Horizon 2020 research and innovation programme under
grant agreement No 676548 (the BrightnESS project).

With the exception of some files in the optional ncrystal_extra/ directory and
the NCSpan.hh file, all NCrystal files are distributed under the Apache 2.0
license, available at http://www.apache.org/licenses/LICENSE-2.0. as well as in
the LICENSE file found in the NCrystal distribution.
With the exception of some files in the optional ncrystal_extra/ directory, all
NCrystal files are distributed under the Apache 2.0 license, available at
http://www.apache.org/licenses/LICENSE-2.0. as well as in the LICENSE file found
in the NCrystal distribution.

A substantial effort went into developing NCrystal. If you use it for your work,
we would appreciate it if you would use the following reference in your work:
Expand All @@ -33,7 +33,3 @@ building via CMake, these extra modules and their license requirements can be
disabled by supplying the -DBUILD_EXTRA=OFF flag. Alternatively, if integrating
NCrystal code by hand into an existing build system, one can simply ignore files
in the ncrystal_extra/ directory to obtain the same result.

The NCSpan.hh file is a distributed under the Boost Software License 1.0
(cf. http://www.boost.org/LICENSE_1_0.txt). Refer to comments at the top of the
NCSpan.hh file iself for the license text and copyright notices.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.2
2.3.0
7 changes: 5 additions & 2 deletions cmake/ncrystal-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ installation_info = dict( libdir = '@NCrystal_relpath_BINDIR2LIBDIR@',

__version__ = installation_info['version']

if installation_info.get('libdir','@').startswith('@'):
raise SystemExit('ERROR: ncrystal-config script can only be used after installation via CMake')

def hasopt(optname):
return installation_info['opt_%s'%optname]

Expand Down Expand Up @@ -178,11 +181,11 @@ def parse_cmdline():

parser.add_argument('--setup', action='store_true',
help="""emit shell code which can be used to setup environment for NCrystal usage and exit
(type "$(%(prog)s --setup)" in a shell to apply to current environment).""")
(type "eval $(%(prog)s --setup)" in a shell to apply to current environment).""")

parser.add_argument('--unsetup', action='store_true',
help="""emit shell code which can be used to undo the effect of --setup and exit (type
"$(%(prog)s --unsetup)" in a shell to apply to current environment). This might
"eval $(%(prog)s --unsetup)" in a shell to apply to current environment). This might
have unwanted side-effects if the directories of the NCrystal installation are mixed
up with files from other software packages.""")

Expand Down
2 changes: 1 addition & 1 deletion cmake/template_setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

export tmpnccfg="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/@NCrystal_BINDIR@/ncrystal-config"
if [ -f "$tmpnccfg" ]; then
$( "$tmpnccfg" --setup )
eval $( "$tmpnccfg" --setup )
unset tmpnccfg
return 0
else
Expand Down
2 changes: 1 addition & 1 deletion cmake/template_unsetup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

export tmpnccfg="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/@NCrystal_BINDIR@/ncrystal-config"
if [ -f "$tmpnccfg" ]; then
$( "$tmpnccfg" --unsetup )
eval $( "$tmpnccfg" --unsetup )
unset tmpnccfg
return 0
else
Expand Down
2 changes: 1 addition & 1 deletion examples/ncrystal_example_customphysics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SimpleIncElasScatterFactory : public NC::FactoryBase {
//100 means that we take precedence over the standard NCrystal factory:
if (!cfg.get_incoh_elas())
return 0;//incoherent-elastic disabled, do nothing
auto info =globalCreateInfo(cfg);
auto info = globalCreateInfo(cfg);
unsigned n_simpleincelas = info->countCustomSections("SIMPLEINCELAS");
if (n_simpleincelas==0)
return 0;//input file did not have @CUSTOM_SIMPLEINCELAS section, do nothing
Expand Down
1 change: 1 addition & 0 deletions ncrystal_core/include/NCrystal/NCDefs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
//so many places:
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <mutex>
Expand Down
13 changes: 8 additions & 5 deletions ncrystal_core/include/NCrystal/NCFactoryRegistry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ namespace NCrystal {
virtual RCHolder<const Scatter> createScatter( const MatCfg& ) const;
virtual RCHolder<const Absorption> createAbsorption( const MatCfg& ) const;

protected:

//TODO: We should rename the above methods or split the factory base into
//three parts. The name conflicts with the global NCrystal::createInfo
//etc. functions. For now, we provide these convenience functions which
//redirects to the global functions:
//redirects to the global functions (after inserting the current factory
//into the exclusion list of the relevant xxxfactory cfg parameter, unless
//allowself=true - MT TODO: support this for info facts as well!):

static RCHolder<const Info> globalCreateInfo( const MatCfg& cfg );
static RCHolder<const Scatter> globalCreateScatter( const MatCfg& cfg );
static RCHolder<const Absorption> globalCreateAbsorption( const MatCfg& cfg );
RCHolder<const Info> globalCreateInfo( const MatCfg& cfg ) const;
RCHolder<const Scatter> globalCreateScatter( const MatCfg& cfg, bool allowself=false ) const;
RCHolder<const Absorption> globalCreateAbsorption( const MatCfg& cfg, bool allowself=false ) const;

protected:
//Combine two Scatter objects into one. This should only be used with
//freshly created Scatter objects in a factory's createScatter method.
//(this is due to a design flaw which is planned to be fixed in a future
Expand Down
25 changes: 22 additions & 3 deletions ncrystal_core/include/NCrystal/NCMatCfg.hh
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,25 @@ namespace NCrystal {
// parameter can be used by experts to circumvent the usual
// factory selection algorithms and instead choose the factory
// for creating NCrystal::Info instances directly.
// (TODO: Mention how to set flags like expandhkl)
//
// scatfactory.: [ string, fallback value is "" ]
// Similar to infofactory, this parameter can be used to
// directly select factory with which to create
// NCrystal::Scatter instances.
// NCrystal::Scatter instances. As a special feature (needed
// for plugin development), factories can be excluded by
// adding them with a "!" in front of their name. Multiple
// entries can be added by separating them with an "@" sign
// (but at most one non-excluded entry can appear).
//
// absnfactory.: [ string, fallback value is "" ]
// Similar to infofactory, this parameter can be used to
// directly select factory with which to create
// NCrystal::Absorption instances.
// NCrystal::Absorption instances. As a special feature (needed
// for plugin development), factories can be excluded by
// adding them with a "!" in front of their name. Multiple
// entries can be added by separating them with an "@" sign
// (but at most one non-excluded entry can appear).
//
// mosprec.....: [ double, fallback value is 1.0e-3 ]
// Approximate relative precision in implementation of mosaic
Expand Down Expand Up @@ -451,10 +460,20 @@ namespace NCrystal {
void getCacheSignature( std::string& signature,
const std::set<std::string>& parameters ) const;

//Convenience interface for setting/decoding scatfactory+absnfactory parameters:
struct FactRequested {
std::string specific;
std::set<std::string> excluded;
};
FactRequested get_scatfactory_parsed() const;
FactRequested get_absnfactory_parsed() const;
void set_scatfactory(const FactRequested& );
void set_absnfactory(const FactRequested& );

private:
const std::string& get_infofactory() const;//undecoded, internal usage only
struct Impl;
RCHolder <Impl> m_impl;
RCHolder<Impl> m_impl;
void cow();

};
Expand Down
2 changes: 1 addition & 1 deletion ncrystal_core/include/NCrystal/NCMem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace NCrystal {
struct NCRYSTAL_API RCHolder {
typedef T element_type;
RCHolder() = default;
explicit RCHolder( T* t, bool ref = true ) : m_obj( t ) { if ( m_obj && ref ) m_obj->ref(); }
explicit RCHolder( T* t ) : m_obj( t ) { if ( m_obj ) m_obj->ref(); }
~RCHolder() { if ( m_obj ) m_obj->unref(); }
RCHolder( const RCHolder & o ) : m_obj(o.m_obj) { if (m_obj) m_obj->ref(); }
T* obj() { return m_obj; }
Expand Down
8 changes: 4 additions & 4 deletions ncrystal_core/include/NCrystal/NCVersion.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
////////////////////////////////////////////////////////////////////////////////

#define NCRYSTAL_VERSION_MAJOR 2
#define NCRYSTAL_VERSION_MINOR 2
#define NCRYSTAL_VERSION_PATCH 2
#define NCRYSTAL_VERSION 2002002 /* (1000000*MAJOR+1000*MINOR+PATCH) */
#define NCRYSTAL_VERSION_STR "2.2.2"
#define NCRYSTAL_VERSION_MINOR 3
#define NCRYSTAL_VERSION_PATCH 0
#define NCRYSTAL_VERSION 2003000 /* (1000000*MAJOR+1000*MINOR+PATCH) */
#define NCRYSTAL_VERSION_STR "2.3.0"

#include "NCrystal/ncapi.h"
#include <stdexcept>
Expand Down
23 changes: 11 additions & 12 deletions ncrystal_core/include/NCrystal/internal/NCGaussMos.hh
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ namespace NCrystal {
private:
friend class GaussMos;
//Frequently accessed members first:
double m_Q;//Once initialised, m_Q = m_Qprime * m_xsfact
double m_sin_perfect_theta;
double m_cos_perfect_theta;
double m_Q = 0.0;//Once initialised, m_Q = m_Qprime * m_xsfact
double m_sin_perfect_theta = 0.0;
double m_cos_perfect_theta = 0.0;
//Less often accessed
double m_wl;
double m_wl3;
double m_inv2dsp;
double m_cos_perfect_theta_sq;
double m_alpha;
double m_Qprime;
double m_xsfact;
double m_wl = -1.0;
double m_wl3 = 0.0;
double m_inv2dsp = -1.0;
double m_cos_perfect_theta_sq = 0.0;
double m_alpha = 0.0;
double m_Qprime = 0.0;
double m_xsfact = 0.0;
};

}
Expand All @@ -179,12 +179,11 @@ namespace NCrystal {
inline double GaussMos::precision() const { return m_gos.getPrecisionParameter(); }

inline GaussMos::InteractionPars::InteractionPars(double wl, double inv2dsp, double xsfact)
: m_wl(-1), m_inv2dsp(-1)
{
set(wl, inv2dsp, xsfact);
}

inline GaussMos::InteractionPars::InteractionPars() : m_wl(-1), m_inv2dsp(-1)
inline GaussMos::InteractionPars::InteractionPars()
{
}

Expand Down
3 changes: 1 addition & 2 deletions ncrystal_core/include/NCrystal/internal/NCMath.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace NCrystal {

//Check that span contains values that could be a grid. I.e. is non-empty,
//sorted, no duplicated values, no NaN/inf's.
bool nc_is_grid(span<const double>);
bool nc_is_grid(Span<const double>);

//sinus/cosine options (indicated approximate timings from 2014 thinkpad with gcc 6.3.1):
void sincos(double A,double&cosA, double& sinA);//slow cos(A) and sin(A) for any A [40ns/call]
Expand Down Expand Up @@ -237,7 +237,6 @@ namespace NCrystal {
template<class TVector, class Func>
inline TVector vectorTrf(const TVector&, const Func&);//create new vector of same type with function applied to all elements
//Access vector contents with .at() in debug builds and [] in optimised builds
//(NB: for spans, use the span_at functions from NCDefs.hh):
template <class TVector>
typename TVector::value_type& vectAt(TVector& v, typename TVector::size_type idx);
template <class TVector>
Expand Down
3 changes: 2 additions & 1 deletion ncrystal_core/include/NCrystal/internal/NCRandUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "NCrystal/NCDefs.hh"
#include "NCrystal/internal/NCSpan.hh"

namespace NCrystal {

Expand All @@ -34,7 +35,7 @@ namespace NCrystal {
double randNorm( RandomBase * );//sample single value from unit Gaussian
void randNorm( RandomBase *, double&g1, double&g2);//sample two independent values from unit Gaussian.
double randNormTail(double tail, RandomBase& rng);//sample gaussian tail (tail>=0!), like sampling randNorm until result is >=tail (but more efficient).
std::size_t pickRandIdxByWeight( RandomBase *, const VectD& commulvals);//pick index according to weights (values must be commulative)
std::size_t pickRandIdxByWeight( RandomBase *, Span<const double> commulvals);//pick index according to weights (values must be commulative)

double randExp( RandomBase& rng );//sample single positive value from exp(-x)
double randExpInterval( RandomBase& rng, double a, double b, double c );//Samples value in [a,b] from exp(-c*x)
Expand Down
22 changes: 11 additions & 11 deletions ncrystal_core/include/NCrystal/internal/NCSABUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ namespace NCrystal {
//If beta grid is defined as [0,b1,b2,..,bn] it is assumed that it is a
//space-saving shorthand for [-bn,...,-b2,-b1,0,b1,b2,..,bn]. Expand, using
//S(alpha,-beta)=S(alpha,beta):
void expandBetaAndSABToAllBetas( span<const double> halfbetagrid,
span<const double> alphagrid,
span<const double> sab_for_halfbetagrid,
void expandBetaAndSABToAllBetas( Span<const double> halfbetagrid,
Span<const double> alphagrid,
Span<const double> sab_for_halfbetagrid,
VectD& complete_betagrid,
VectD& complete_sab );

//Access S(alpha|beta_i) slice (const and non-const version):
span<const double> sliceSABAtBetaIdx_const( span<const double> sab, std::size_t nalpha, std::size_t beta_idx);
span<double> sliceSABAtBetaIdx( span<double> sab, std::size_t nalpha, std::size_t beta_idx);
Span<const double> sliceSABAtBetaIdx_const( Span<const double> sab, std::size_t nalpha, std::size_t beta_idx);
Span<double> sliceSABAtBetaIdx( Span<double> sab, std::size_t nalpha, std::size_t beta_idx);

//interpolate "loglin" (linear in log(f), fallback to linear when undefined)
double interpolate_loglin_fallbacklinlin(double a, double fa, double b, double fb, double x);
Expand Down Expand Up @@ -109,10 +109,10 @@ namespace NCrystal {
} front, back;
bool narrow = false;//if range inside single grid bin
};
TailedBreakdown createTailedBreakdown( const span<const double>& alphaGrid,
const span<const double>& sab,
const span<const double>& logsab,
const span<const double>& alphaIntegrals_cumul,
TailedBreakdown createTailedBreakdown( const Span<const double>& alphaGrid,
const Span<const double>& sab,
const Span<const double>& logsab,
const Span<const double>& alphaIntegrals_cumul,
double alpha_low, double alpha_upp,
const unsigned aidx_low, const unsigned aidx_upp );

Expand All @@ -124,13 +124,13 @@ namespace NCrystal {
// Inline implementations //
////////////////////////////

inline NCrystal::span<const double> NCrystal::SABUtils::sliceSABAtBetaIdx_const( span<const double> sab, std::size_t nalpha, std::size_t beta_idx)
inline NCrystal::Span<const double> NCrystal::SABUtils::sliceSABAtBetaIdx_const( NCrystal::Span<const double> sab, std::size_t nalpha, std::size_t beta_idx)
{
nc_assert( (beta_idx+1) * nalpha <= static_cast<std::size_t>(sab.size()) );
return {sab.begin() + beta_idx*nalpha, sab.begin() + (beta_idx+1)*nalpha};
}

inline NCrystal::span<double> NCrystal::SABUtils::sliceSABAtBetaIdx( span<double> sab, std::size_t nalpha, std::size_t beta_idx)
inline NCrystal::Span<double> NCrystal::SABUtils::sliceSABAtBetaIdx( NCrystal::Span<double> sab, std::size_t nalpha, std::size_t beta_idx)
{
nc_assert( (beta_idx+1) * nalpha <= static_cast<std::size_t>(sab.size()) );
return {sab.begin() + beta_idx*nalpha, sab.begin() + (beta_idx+1)*nalpha};
Expand Down
2 changes: 1 addition & 1 deletion ncrystal_core/include/NCrystal/internal/NCScatKnlData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace NCrystal {
//using the same functions.
ScatKnlDataView(const ScatKnlData&);
ScatKnlDataView(const SABData&);
const span<const double> alphaGrid, betaGrid, sab;
const Span<const double> alphaGrid, betaGrid, sab;
const double temperature;
const SigmaBound boundXS;
const double elementMassAMU;
Expand Down
Loading

0 comments on commit 7c800a1

Please sign in to comment.