Jpp 19.3.0-rc.5
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 83 of file JSphereND.cc.

84{
85 using namespace std;
86 using namespace JPP;
87
88 unsigned int numberOfBins;
89 double precision;
90 int debug;
91
92 try {
93
94 JParser<> zap("Example program to test integration of sphere in any number of dimensions.");
95
96 zap['N'] = make_field(numberOfBins) = 11;
97 zap['e'] = make_field(precision) = 1.0e-2;
98 zap['d'] = make_field(debug) = 2;
99
100 zap(argc, argv);
101 }
102 catch(const exception &error) {
103 FATAL(error.what() << endl);
104 }
105
106
107 const int N = 7;
108 const double R = 1.0;
109
110 typedef JGridPolint1Function1D_t JFunction1D_t;
111 typedef JMultipleMap<N-2, JPolint1FunctionalGridMap>::typelist JMaplist_t;
112 typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
113
114
115 const JGrid<double> grid(numberOfBins, -R * 1.05, +R * 1.05);
116
117 JMultiFunction_t gs;
118
119 gs.configure(make_multigrid<N-2>(grid));
120
121 for (JMultiFunction_t::super_iterator i = gs.super_begin(); i != gs.super_end(); ++i) {
122
123 const double x = (*i).getKey().getLength();
124
125 for (int __i = 0; __i != grid.getSize(); ++__i) {
126
127 const double y = grid.getX(__i);
128 const double z = R*R - x*x - y*y;
129
130 if (z > 0.0)
131 (*i).getValue()[y] = 2.0 * sqrt(z);
132 else
133 (*i).getValue()[y] = 0.0;
134 }
135 }
136
137 gs.compile();
138
139 const double U = JVolume<N>::get(R);
140
141 JTimer timer("integrator");
142
143 timer.start();
144
145 const double W = getIntegral(gs);
146
147 timer.stop();
148
149 NOTICE("Sphere " << N << "D" << endl);
150 NOTICE("Volume (real) " << SCIENTIFIC(12,4) << U << endl);
151 NOTICE("Volume (calc) " << SCIENTIFIC(12,4) << W << endl);
152
153 NOTICE(timer);
154
155 ASSERT(fabs(U - W) < precision * U);
156
157 return 0;
158}
#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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
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).
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.
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
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