Jpp  17.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSphere3D.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/JFunctionalMap.hh"
11 
12 #include "Jeep/JPrint.hh"
13 #include "Jeep/JParser.hh"
14 #include "Jeep/JMessage.hh"
15 
16 
17 /**
18  * \file
19  *
20  * Example program to test 3D integration of sphere.
21  * \author mdejong
22  */
23 int main(int argc, char **argv)
24 {
25  using namespace std;
26 
27  unsigned int numberOfBins;
28  int debug;
29 
30  try {
31 
32  JParser<> zap("Example program to test 3D integration of sphere.");
33 
34  zap['N'] = make_field(numberOfBins) = 101;
35  zap['d'] = make_field(debug) = 3;
36 
37  zap(argc, argv);
38  }
39  catch(const exception &error) {
40  FATAL(error.what() << endl);
41  }
42 
43 
44  using namespace JPP;
45 
46 
47  const double R = 1.0;
48 
49  typedef JGridPolint3Function1D_t JFunction1D_t;
50  typedef JMapList<JPolint3FunctionalGridMap> JMaplist_t;
51  typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
52 
53 
54  JMultiFunction_t ga;
55  JMultiFunction_t gb;
56 
57  const double xmin = -R * 1.05;
58  const double xmax = +R * 1.05;
59  const double dx = (xmax - xmin) / (numberOfBins - 1);
60 
61  for (double x = xmin; x < xmax + 0.5*dx; x += dx) {
62  for (double y = xmin; y < xmax + 0.5*dx; y += dx) {
63 
64  const double z = R*R - x*x - y*y;
65 
66  if (z > 0.0) {
67  ga[x][y] = -sqrt(z);
68  gb[x][y] = +sqrt(z);
69  } else {
70  ga[x][y] = 0.0;
71  gb[x][y] = 0.0;
72  }
73  }
74  }
75 
76  ga.compile();
77  gb.compile();
78 
79  cout << "Volume (real) " << SCIENTIFIC(12,4) << 4.0*PI*R*R*R/3.0 << endl;
80  cout << "Volume (calc) " << SCIENTIFIC(12,4) << getIntegral(gb) - getIntegral(ga) << endl;
81 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Various implementations of functional maps.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
This include file contains various recursive methods to operate on multi-dimensional collections...
static const double PI
Mathematical constants.
int debug
debug level
Definition: JSirene.cc:66
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
const double xmin
Definition: JQuadrature.cc:23
Utility class to parse command line options.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:67
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.