Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JSphereND.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4
5#include "JTools/JMapList.hh"
10#include "JTools/JMultiGrid.hh"
13
14#include "Jeep/JPrint.hh"
15#include "Jeep/JTimer.hh"
16#include "Jeep/JParser.hh"
17#include "Jeep/JMessage.hh"
18
19
20namespace {
21
22 /**
23 * Auxiliary class to determine volume of N-dimensional sphere.
24 */
25 template<int N>
26 struct JVolume {
27 /**
28 * Get volume.
29 *
30 * \param R radius
31 * \return volume
32 */
33 static double get(const double R)
34 {
35 return 2*JTOOLS::PI*R*R * JVolume<N-2>::get(R) / N;
36 }
37 };
38
39
40 /**
41 * Specialisation of template class JVolume for 2D sphere.
42 */
43 template<>
44 struct JVolume<2> {
45 /**
46 * Get volume.
47 *
48 * \param R radius
49 * \return volume
50 */
51 static double get(const double R)
52 {
53 return JTOOLS::PI*R*R;
54 }
55 };
56
57
58 /**
59 * Specialisation of template class JVolume for 1D sphere.
60 */
61 template<>
62 struct JVolume<1> {
63 /**
64 * Get volume.
65 *
66 * \param R radius
67 * \return volume
68 */
69 static double get(const double R)
70 {
71 return 2*R;
72 }
73 };
74}
75
76
77/**
78 * \file
79 *
80 * Example program to test integration of sphere in any number of dimensions.
81 * \author mdejong
82 */
83int main(int argc, char **argv)
84{
85 using namespace std;
86
87 unsigned int numberOfBins;
88 double precision;
89 int debug;
90
91 try {
92
93 JParser<> zap("Example program to test integration of sphere in any number of dimensions.");
94
95 zap['N'] = make_field(numberOfBins) = 11;
96 zap['e'] = make_field(precision) = 1.0e-2;
97 zap['d'] = make_field(debug) = 2;
98
99 zap(argc, argv);
100 }
101 catch(const exception &error) {
102 FATAL(error.what() << endl);
103 }
104
105
106 using namespace JPP;
107
108
109 const int N = 7;
110 const double R = 1.0;
111
112 typedef JGridPolint1Function1D_t JFunction1D_t;
113 typedef JMultipleMap<N-2, JPolint1FunctionalGridMap>::typelist JMaplist_t;
114 typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
115
116
117 const JGrid<double> grid(numberOfBins, -R * 1.05, +R * 1.05);
118
119 JMultiFunction_t gs;
120
121 gs.configure(make_multigrid<N-2>(grid));
122
123 for (JMultiFunction_t::super_iterator i = gs.super_begin(); i != gs.super_end(); ++i) {
124
125 const double x = (*i).getKey().getLength();
126
127 for (int __i = 0; __i != grid.getSize(); ++__i) {
128
129 const double y = grid.getX(__i);
130 const double z = R*R - x*x - y*y;
131
132 if (z > 0.0)
133 (*i).getValue()[y] = 2.0 * sqrt(z);
134 else
135 (*i).getValue()[y] = 0.0;
136 }
137 }
138
139 gs.compile();
140
141 const double U = JVolume<N>::get(R);
142
143 JTimer timer("integrator");
144
145 timer.start();
146
147 const double W = getIntegral(gs);
148
149 timer.stop();
150
151 NOTICE("Sphere " << N << "D" << endl);
152 NOTICE("Volume (real) " << SCIENTIFIC(12,4) << U << endl);
153 NOTICE("Volume (calc) " << SCIENTIFIC(12,4) << W << endl);
154
155 NOTICE(timer);
156
157 ASSERT(fabs(U - W) < precision * U);
158
159 return 0;
160}
Various implementations of functional maps.
General purpose messaging.
#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:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
int main(int argc, char **argv)
Definition JSphereND.cc:83
This include file contains various recursive methods to operate on multi-dimensional collections.
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
void stop()
Stop timer.
Definition JTimer.hh:127
void start()
Start timer.
Definition JTimer.hh:106
Utility class to parse command line options.
Definition JParser.hh:1698
Multidimensional interpolation method.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Type definition of a 1st degree polynomial interpolation based on a JGridCollection with result type ...
Simple data structure for an abstract collection of equidistant abscissa values.
Definition JGrid.hh:40
virtual int getSize() const override
Get number of elements.
Definition JGrid.hh:75
virtual abscissa_type getX(int index) const override
Get abscissa value.
Definition JGrid.hh:87
List of identical maps.
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488