Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JSphere3D.cc File Reference

Example program to test 3D integration of sphere. 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/JToolsToolkit.hh"
#include "JTools/JFunctionalMap.hh"
#include "Jeep/JPrint.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 3D integration of sphere.

Author
mdejong

Definition in file JSphere3D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file JSphere3D.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1493
static const double PI
Constants.
Definition: JConstants.hh:20
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
int debug
debug level
Definition: JSirene.cc:61
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:518
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.