CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
CUBAwrapper.h
Go to the documentation of this file.
1 /*******************************************************************
2  * Copyright (C) 2010 by Federico Marulli *
3  * federico.marulli3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) 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 *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  *******************************************************************/
20 
35 #ifndef __CUBAwrap__
36 #define __CUBAwrap__
37 
38 #include "cuba.h"
39 #include "Kernel.h"
40 
41 namespace cbl {
42 
43  namespace wrapper {
44 
51  namespace cuba {
52 
56  struct STR_CUBA_inputs {
57 
59  int NDIM = 1;
60 
62  int NCOMP = 1;
63 
65  std::shared_ptr<void> USERDATA = NULL;
66 
68  int NVEC = 1;
69 
71  double EPSREL = 1e-4;
72 
74  double EPSABS = 1e-12;
75 
77  int VERBOSE = 0;
78 
80  int LAST = 4;
81 
83  int SEED = 0;
84 
86  int MINEVAL = 0;
87 
89  int MAXEVAL = 50000;
90 
92  int NSTART = 1000;
93 
95  int NINCREASE = 500;
96 
98  int NBATCH = 1000;
99 
101  int GRIDNO = 0;
102 
104  char *STATEFILE = NULL;
105 
107  std::shared_ptr<void> SPIN = NULL;
108 
110  int NNEW = 1000;
111 
113  int NMIN = 2;
114 
116  double FLATNESS = 25.;
117 
119  int KEY1 = 47;
120 
122  int KEY2 = 1;
123 
125  int KEY3 = 1;
126 
128  int MAXPASS = 5;
129 
131  double BORDER = 0.;
132 
134  double MAXCHISQ = 10.;
135 
137  double MINDEVIATION = 0.25;
138 
140  int NGIVEN = 0;
141 
143  int LDXGIVEN = NDIM;
144 
146  int NEXTRA = 0;
147 
149  int KEY = 0;
150  };
151 
152 
157  {
160 
162  std::vector<std::vector<double>> integration_limits;
163  };
164 
175  int CUBAIntegrand (const int *ndim, const cubareal xx[], const int *ncomp, cubareal ff[], void *userdata);
176 
187  class CUBAwrapper {
188 
189  protected:
190 
193 
195  int m_ndim;
196 
199 
200  public:
201 
205  CUBAwrapper () = default;
206 
215  CUBAwrapper (FunctionDoubleVectorPtrVectorRef func, const std::shared_ptr<void> function_parameters, std::vector<double> &parameters, const int ndim);
216 
222  CUBAwrapper (FunctionDoubleVector func, const int ndim);
223 
227  ~CUBAwrapper () = default;
228 
237  void set_integrand (FunctionDoubleVectorPtrVectorRef func, const std::shared_ptr<void> function_parameters, std::vector<double> &parameters, const int ndim);
238 
244  void set_integrand (FunctionDoubleVector func, const int ndim);
245 
252  void set_limits (std::vector<std::vector<double>> integration_limits)
253  { (void)integration_limits; ErrorCBL("", "set_limits", "CUBAwrapper.h", glob::ExitCode::_workInProgress_); };
254 
255 
261 
271  double IntegrateVegas (std::vector<std::vector<double>> integration_limits, const bool parallelize=true);
272 
282  double IntegrateSuave (std::vector<std::vector<double>> integration_limits, const bool parallelize=true);
283 
293  double IntegrateDivonne (std::vector<std::vector<double>> integration_limits, const bool parallelize=true);
294 
304  double IntegrateCuhre (std::vector<std::vector<double>> integration_limits, const bool parallelize=true);
305 
306  };
307  }
308  }
309 }
310 
311 #endif
Useful generic functions.
The class CUBAwrapper.
Definition: CUBAwrapper.h:187
STR_CUBA_inputs & inputs()
return reference to integration parameters
Definition: CUBAwrapper.h:260
double IntegrateSuave(std::vector< std::vector< double >> integration_limits, const bool parallelize=true)
integrate using the Suave routine
void set_limits(std::vector< std::vector< double >> integration_limits)
set integration limits
Definition: CUBAwrapper.h:252
CUBAwrapper()=default
default constructor
int m_ndim
integral dimension
Definition: CUBAwrapper.h:195
double IntegrateDivonne(std::vector< std::vector< double >> integration_limits, const bool parallelize=true)
integrate using the Divonne routine
double IntegrateCuhre(std::vector< std::vector< double >> integration_limits, const bool parallelize=true)
integrate using the Cuhre routine
STR_CUBA_inputs m_inputs
CUBA integration inputs.
Definition: CUBAwrapper.h:198
void set_integrand(FunctionDoubleVectorPtrVectorRef func, const std::shared_ptr< void > function_parameters, std::vector< double > &parameters, const int ndim)
set the integrand
Definition: CUBAwrapper.cpp:83
~CUBAwrapper()=default
default destructor
double IntegrateVegas(std::vector< std::vector< double >> integration_limits, const bool parallelize=true)
integrate using the Vegas routine
FunctionDoubleVector m_integrand
integrand
Definition: CUBAwrapper.h:192
@ _workInProgress_
error due to work in progress
int CUBAIntegrand(const int *ndim, const cubareal xx[], const int *ncomp, cubareal ff[], void *userdata)
generic CUBA integrand
Definition: CUBAwrapper.cpp:45
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
std::function< double(std::vector< double >)> FunctionDoubleVector
typedef of a function returning a double with a vector in input
Definition: Kernel.h:690
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
Definition: Kernel.h:780
std::function< double(std::vector< double >, std::shared_ptr< void >, std::vector< double > &)> FunctionDoubleVectorPtrVectorRef
typedef of a function returning a double with a vector, a pointer and a vector reference in input
Definition: Kernel.h:702
struct to manage cuba parameters
Definition: CUBAwrapper.h:56
std::shared_ptr< void > SPIN
CUBA SPIN parameter.
Definition: CUBAwrapper.h:107
int NINCREASE
CUBA NINCREASE parameter.
Definition: CUBAwrapper.h:95
std::shared_ptr< void > USERDATA
CUBA USERDATA parameter.
Definition: CUBAwrapper.h:65
int KEY2
CUBA KEY2 parameter.
Definition: CUBAwrapper.h:122
int SEED
CUBA SEED parameter.
Definition: CUBAwrapper.h:83
int GRIDNO
CUBA GRIDNO parameter.
Definition: CUBAwrapper.h:101
int LAST
CUBA LAST parameter.
Definition: CUBAwrapper.h:80
int NCOMP
CUBA NCOMP parameter.
Definition: CUBAwrapper.h:62
int VERBOSE
CUBA VERBOSE parameter.
Definition: CUBAwrapper.h:77
char * STATEFILE
CUBA STATEFILE parameter.
Definition: CUBAwrapper.h:104
double MINDEVIATION
CUBA MINDEVIATION parameter.
Definition: CUBAwrapper.h:137
int LDXGIVEN
CUBA LDXGIVEN parameter.
Definition: CUBAwrapper.h:143
int NDIM
CUBA NDIM parameter.
Definition: CUBAwrapper.h:59
double EPSREL
CUBA EPSREL parameter.
Definition: CUBAwrapper.h:71
int MAXEVAL
CUBA MAXEVAL parameter.
Definition: CUBAwrapper.h:89
double BORDER
CUBA parameter.
Definition: CUBAwrapper.h:131
int MAXPASS
CUBA MAXPASS parameter.
Definition: CUBAwrapper.h:128
double FLATNESS
CUBA FLATNESS parameter.
Definition: CUBAwrapper.h:116
int KEY3
CUBA KEY3 parameter.
Definition: CUBAwrapper.h:125
double EPSABS
CUBA EPSABS parameter.
Definition: CUBAwrapper.h:74
int NNEW
CUBA NNEW parameter.
Definition: CUBAwrapper.h:110
int NVEC
CUBA NVEC parameter.
Definition: CUBAwrapper.h:68
int NBATCH
CUBA NBATCH parameter.
Definition: CUBAwrapper.h:98
int KEY
CUBA KEY parameter.
Definition: CUBAwrapper.h:149
int MINEVAL
CUBA MINEVAL parameter.
Definition: CUBAwrapper.h:86
int NGIVEN
CUBA NGIVEN parameter.
Definition: CUBAwrapper.h:140
int KEY1
CUBA KEY1 parameter.
Definition: CUBAwrapper.h:119
int NSTART
CUBA NSTART parameter.
Definition: CUBAwrapper.h:92
int NEXTRA
CUBA NEXTRA parameter.
Definition: CUBAwrapper.h:146
double MAXCHISQ
CUBA MAXCHISQ parameter.
Definition: CUBAwrapper.h:134
int NMIN
CUBA NMIN parameter.
Definition: CUBAwrapper.h:113
support object for cuba integrand
Definition: CUBAwrapper.h:157
FunctionDoubleVector func
function to be integrated
Definition: CUBAwrapper.h:159
std::vector< std::vector< double > > integration_limits
limits of the integration
Definition: CUBAwrapper.h:162