cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
FunctionalExprTk.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2013-2021 Laurent Forthomme
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include <exprtk.hpp>
20
21
#include "
CepGen/Core/Exception.h
"
22
#include "
CepGen/Modules/FunctionalFactory.h
"
23
#include "
CepGen/Utils/Functional.h
"
24
#include "
CepGen/Utils/String.h
"
25
26
namespace
cepgen
{
27
namespace
utils {
28
class
FunctionalExprTk
final :
public
Functional
{
29
public
:
30
explicit
FunctionalExprTk
(
const
ParametersList
&);
31
double
eval
()
const override
;
32
33
static
ParametersDescription
description
();
34
35
private
:
36
exprtk::symbol_table<double> symbols_;
37
exprtk::expression<double> expr_;
38
exprtk::parser<double> parser_;
39
};
40
41
FunctionalExprTk::FunctionalExprTk
(
const
ParametersList
& params) :
Functional
(params) {
42
for
(
size_t
i = 0; i <
vars_
.size(); ++i)
43
symbols_.add_variable(
vars_
[i],
values_
[i]);
44
symbols_.add_constants();
45
expr_.register_symbol_table(symbols_);
46
auto
expr =
replaceAll
(
expression_
, {{
"**"
,
"^"
}});
47
if
(!parser_.compile(expr, expr_))
48
throw
CG_WARNING
(
"FunctionalExprTk"
) <<
"Failed to compile expression \""
<<
expression
() <<
"\"."
;
49
}
50
51
double
FunctionalExprTk::eval
()
const
{
return
expr_.value(); }
52
53
ParametersDescription
FunctionalExprTk::description
() {
54
auto
desc =
Functional::description
();
55
desc.setDescription(
"ExprTk functional evaluator"
);
56
return
desc;
57
}
58
}
// namespace utils
59
}
// namespace cepgen
60
typedef
cepgen::utils::FunctionalExprTk
ExprTkFunctional
;
61
REGISTER_FUNCTIONAL
(
"ExprTk"
,
ExprTkFunctional
);
Exception.h
ExprTkFunctional
cepgen::utils::FunctionalExprTk ExprTkFunctional
Definition
FunctionalExprTk.cpp:60
FunctionalFactory.h
REGISTER_FUNCTIONAL
#define REGISTER_FUNCTIONAL(name, obj)
Add a generic functional object builder definition.
Definition
FunctionalFactory.h:25
Functional.h
CG_WARNING
#define CG_WARNING(mod)
Definition
Message.h:228
String.h
cepgen::ParametersDescription
A description object for parameters collection.
Definition
ParametersDescription.h:26
cepgen::ParametersList
Definition
ParametersList.h:52
cepgen::utils::FunctionalExprTk
Definition
FunctionalExprTk.cpp:28
cepgen::utils::FunctionalExprTk::eval
double eval() const override
Compute the functional for a given value of the variables.
Definition
FunctionalExprTk.cpp:51
cepgen::utils::FunctionalExprTk::FunctionalExprTk
FunctionalExprTk(const ParametersList &)
Definition
FunctionalExprTk.cpp:41
cepgen::utils::FunctionalExprTk::description
static ParametersDescription description()
Definition
FunctionalExprTk.cpp:53
cepgen::utils::Functional
A string-to-functional parser.
Definition
Functional.h:32
cepgen::utils::Functional::expression
const std::string & expression() const
String expression held by this functional parser.
Definition
Functional.h:52
cepgen::utils::Functional::vars_
std::vector< std::string > vars_
Computer-readable variable to be reached.
Definition
Functional.h:62
cepgen::utils::Functional::expression_
std::string expression_
Computer-readable expression.
Definition
Functional.h:63
cepgen::utils::Functional::description
static ParametersDescription description()
Definition
Functional.cpp:57
cepgen::utils::Functional::values_
std::vector< double > values_
Last arguments list fed to the functional.
Definition
Functional.h:64
cepgen::utils::replaceAll
size_t replaceAll(std::string &str, const std::string &from, const std::string &to)
Replace all occurrences of a text by another.
Definition
String.cpp:118
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGenAddOns
Functionals
FunctionalExprTk.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7