Mantid
Loading...
Searching...
No Matches
MuParserUtils.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
10
11#include <gsl/gsl_sf.h>
12
13using namespace Mantid::PhysicalConstants;
14
16
17// The constant names below try to follow the naming scheme of the
18// scipy.constants Python module.
19// In addition to these, muParser defines "_e" for the Euler's number and
20// "_pi" for pi.
21const std::map<double, std::string> MUPARSER_CONSTANTS = {
22 {AtomicMassUnit, "atomic_mass"},
23 {BoltzmannConstant, "k"},
24 {E_mev_toNeutronWavenumberSq, "meV_squared_wave_number_relationship"},
25 {h, "h"},
26 {h_bar, "hbar"},
27 {g, "g"},
28 {meV, "meV"},
29 {meVtoKelvin, "meV_kelvin_relationship"},
30 {meVtoWavenumber, "meV_wave_number_relationship"},
31 {MuonGyromagneticRatio, "muon_gyromagnetic_ratio"},
32 {MuonLifetime, "muon_life_time"},
33 {N_A, "N_A"},
34 {NeutronMass, "m_n"},
35 {NeutronMassAMU, "m_n_AMU"},
36 {M_PI, "pi"}, // Another pi, without the leading '_'.
37 {StandardAtmosphere, "atm"}};
38
42void MANTID_API_DLL addDefaultConstants(mu::Parser &parser) {
43 for (const auto &constant : MUPARSER_CONSTANTS) {
44 parser.DefineConst(constant.second, constant.first);
45 }
46}
47
48using oneVarFun = double (*)(double); // pointer to a function of one variable
49const std::map<std::string, oneVarFun> MUPARSER_ONEVAR_FUNCTIONS = {{"erf", gsl_sf_erf}, {"erfc", gsl_sf_erfc}};
50
51void MANTID_API_DLL extraOneVarFunctions(mu::Parser &parser) {
52 for (const auto &function : MUPARSER_ONEVAR_FUNCTIONS) {
53 parser.DefineFun(function.first, function.second);
54 }
55}
56
57} // namespace Mantid::API::MuParserUtils
void MANTID_API_DLL extraOneVarFunctions(mu::Parser &parser)
const MANTID_API_DLL std::map< std::string, oneVarFun > MUPARSER_ONEVAR_FUNCTIONS
void MANTID_API_DLL addDefaultConstants(mu::Parser &parser)
Add a set of default constants to a muParser.
const MANTID_API_DLL std::map< double, std::string > MUPARSER_CONSTANTS
Defines convenience methods to be used with the muParser mathematical expression parser.
double(*)(double) oneVarFun
Definition: MuParserUtils.h:29
A namespace containing physical constants that are required by algorithms and unit routines.
Definition: Atom.h:14
static constexpr double MuonGyromagneticRatio
Muon gyromagnetic ratio in MHz/G Taken from CalMuonDetectorPhases and DynamicKuboToyabe on 02/02/2016...
static constexpr double StandardAtmosphere
Standard atmospheric pressure in kPa.
static constexpr double NeutronMassAMU
Mass of the neutron in AMU.
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double h
Planck constant in J*s.
static constexpr double meVtoKelvin
1 meV in Kelvin.
static constexpr double meVtoWavenumber
1 meV in wavenumber (cm-1).
static constexpr double N_A
Avagodro constant in mol-1.
static constexpr double MuonLifetime
Muon lifetime.
static constexpr double AtomicMassUnit
AMU in kg.
static constexpr double meV
1 meV in Joules.
static constexpr double h_bar
Planck constant in J*s, divided by 2 PI.
static constexpr double g
Standard acceleration due to gravity.