Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:23

0001 #include "Grid1D.h"
0002 #include "Grid3D.h"
0003 #include <cassert>
0004 
0005 namespace {
0006   bool testGrid1D(Grid1D const& grid) {
0007     bool ok = true;
0008 
0009     Grid1D::Scalar f;
0010     int i = grid.index(7.2, f);
0011     ok &= grid.inRange(i);
0012 
0013     ok &= (8 == i);
0014     ok &= (0.6 == f);
0015 
0016     return ok;
0017   }
0018 }  // namespace
0019 
0020 #include <iostream>
0021 #include <cstdlib>
0022 #include <cstdio>
0023 
0024 namespace {
0025   void print(Grid1D grid, Grid1D::Scalar a) {
0026     Grid1D::Scalar f;
0027     int i = grid.index(a, f);
0028     ::printf("%i %f %a\n", i, f, f);
0029     grid.normalize(i, f);
0030     ::printf("%i %f %a\n", i, f, f);
0031   }
0032 }  // namespace
0033 
0034 int grid1d_t() {
0035   bool ok = true;
0036   Grid1D grid(-10., 10., 11);
0037 
0038   print(grid, 7.2);
0039   print(grid, 10.);
0040   print(grid, -10.2);
0041   print(grid, 10.2);
0042 
0043   ok &= testGrid1D(grid);
0044 
0045   assert(ok ? 0 : 1);
0046   return ok ? 0 : 1;
0047 }
0048 
0049 namespace {
0050 
0051   Grid3D const* factory() {
0052     Grid1D ga(0., 10., 5);
0053     Grid1D gb(-10., 10., 11);
0054     Grid1D gc(-10., 10., 11);
0055 
0056     std::vector<Grid3D::BVector> data;
0057     data.reserve(ga.nodes() * gb.nodes() * gc.nodes());
0058     for (int i = 0; i < ga.nodes(); ++i)
0059       for (int j = 0; j < gb.nodes(); ++j)
0060         for (int k = 0; k < gc.nodes(); ++k) {
0061           data.push_back(Grid3D::BVector(10 * ga.node(i), 10 * gb.node(j), 10 * gc.node(k)));
0062         }
0063 
0064     return new Grid3D(ga, gb, gc, data);
0065   }
0066 
0067 }  // namespace
0068 
0069 #include "LinearGridInterpolator3D.h"
0070 #include <iostream>
0071 
0072 int grid3d_t() {
0073   Grid3D const* grid = factory();
0074 
0075   LinearGridInterpolator3D inter(*grid);
0076 
0077   std::cout << inter.interpolate(7.5, 7.2, -3.4) << std::endl;
0078   std::cout << inter.interpolate(-0.5, 10.2, -3.4) << std::endl;
0079 
0080   delete grid;
0081   return 0;
0082 }