Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JSphereND.cc File Reference

Example program to test integration of sphere in any number of dimensions. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JTools/JMapList.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JMultiFunction.hh"
#include "JTools/JMultipleMap.hh"
#include "JTools/JMultiGrid.hh"
#include "JTools/JToolsToolkit.hh"
#include "JTools/JFunctionalMap.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test integration of sphere in any number of dimensions.

Author
mdejong

Definition in file JSphereND.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 109 of file JSphereND.cc.

110{
111 using namespace std;
112 using namespace JPP;
113
114 unsigned int numberOfBins;
115 double precision;
116 int debug;
117
118 try {
119
120 JParser<> zap("Example program to test integration of sphere in any number of dimensions.");
121
122 zap['N'] = make_field(numberOfBins) = 11;
123 zap['e'] = make_field(precision) = 1.0e-2;
124 zap['d'] = make_field(debug) = 2;
125
126 zap(argc, argv);
127 }
128 catch(const exception &error) {
129 FATAL(error.what() << endl);
130 }
131
132
133 const int N = 7;
134 const double R = 1.0;
135
136 typedef JGridPolint1Function1D_t JFunction1D_t;
137 typedef JMultipleMap<N-2, JPolint1FunctionalGridMap>::typelist JMaplist_t;
138 typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
139
140
141 const JGrid<double> grid(numberOfBins, -R * 1.05, +R * 1.05);
142
143 JMultiFunction_t gs;
144
145 gs.configure(make_multigrid<N-2>(grid));
146
147 for (JMultiFunction_t::super_iterator i = gs.super_begin(); i != gs.super_end(); ++i) {
148
149 const double x = sqrt(getLengthSquared(i.getKey()));
150
151 for (int __i = 0; __i != grid.getSize(); ++__i) {
152
153 const double y = grid.getX(__i);
154 const double z = R*R - x*x - y*y;
155
156 if (z > 0.0)
157 i.getValue()[y] = 2.0 * sqrt(z);
158 else
159 i.getValue()[y] = 0.0;
160 }
161 }
162
163 gs.compile();
164
165 const double U = JVolume<N>::get(R);
166
167 JTimer timer("integrator");
168
169 timer.start();
170
171 const double W = getIntegral(gs);
172
173 timer.stop();
174
175 NOTICE("Sphere " << N << "D" << endl);
176 NOTICE("Volume (real) " << SCIENTIFIC(12,4) << U << endl);
177 NOTICE("Volume (calc) " << SCIENTIFIC(12,4) << W << endl);
178
179 NOTICE(timer);
180
181 ASSERT(fabs(U - W) < precision * U);
182
183 return 0;
184}
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2140
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:75
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
Utility class to parse command line options.
Definition JParser.hh:1697
Multidimensional interpolation method.
Template class for polynomial interpolation in 1D.
Definition JPolint.hh:1095
Functional map with polynomial interpolation.
Definition JPolint.hh:1153
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.
Simple data structure for an abstract collection of equidistant abscissa values.
Definition JGrid.hh:40
List of identical maps.
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488