BinArray Class Referenceabstract

Base class for all bin arrays. More...

#include <sample_point_container.h>

+ Inheritance diagram for BinArray:

Public Member Functions

 BinArray (Mesh *mesh_pt, const Vector< std::pair< double, double >> &min_and_max_coordinates, const Vector< unsigned > &dimensions_of_bin_array, const bool &use_eulerian_coordinates_during_setup, const bool &ignore_halo_elements_during_locate_zeta_search, const unsigned &nsample_points_generated_per_element)
 Constructor. More...
 
 BinArray ()
 
 BinArray (const BinArray &data)=delete
 Broken copy constructor. More...
 
void operator= (const BinArray &)=delete
 Broken assignment operator. More...
 
virtual ~BinArray ()
 Virtual destructor. More...
 
void get_neighbouring_bins_helper (const unsigned &bin_index, const unsigned &radius, Vector< unsigned > &neighbouring_bin_index, const bool &use_old_version=true)
 
void profile_get_neighbouring_bins_helper ()
 
unsigned coords_to_bin_index (const Vector< double > &zeta)
 
void coords_to_vectorial_bin_index (const Vector< double > &zeta, Vector< unsigned > &bin_index)
 Get "coordinates" of bin that contains specified zeta. More...
 
virtual void output_bins (std::ofstream &outfile)=0
 Output bins (boundaries and number of sample points in them) More...
 
virtual void output_bin_vertices (std::ofstream &outfile)=0
 Output bin vertices (allowing display of bin boundaries as zones). More...
 
virtual unsigned nbin () const =0
 
unsigned max_bin_dimension () const
 Max. bin dimension (number of bins in coordinate directions) More...
 
unsigned ndim_zeta () const
 Dimension of the zeta ( = dim of local coordinate of elements) More...
 
unsigned dimension_of_bin_array (const unsigned &i) const
 Number of bins in coordinate direction i. More...
 
Vector< unsigneddimensions_of_bin_array () const
 
unsigned dimensions_of_bin_array (const unsigned &i) const
 Number of bins in specified coordinate direction. More...
 
- Public Member Functions inherited from SamplePointContainer
 SamplePointContainer (Mesh *mesh_pt, const Vector< std::pair< double, double >> &min_and_max_coordinates, const bool &use_eulerian_coordinates_during_setup, const bool &ignore_halo_elements_during_locate_zeta_search, const unsigned &nsample_points_generated_per_element)
 Constructor. More...
 
 SamplePointContainer ()
 
 SamplePointContainer (const SamplePointContainer &data)=delete
 Broken copy constructor. More...
 
void operator= (const SamplePointContainer &)=delete
 Broken assignment operator. More...
 
virtual ~SamplePointContainer ()
 Virtual destructor. More...
 
virtual void locate_zeta (const Vector< double > &zeta, GeomObject *&sub_geom_object_pt, Vector< double > &s)=0
 
virtual unsignedtotal_number_of_sample_points_visited_during_locate_zeta_from_top_level ()
 
virtual unsigned total_number_of_sample_points_computed_recursively () const =0
 
Mesh * mesh_pt () const
 Pointer to mesh from whose FiniteElements sample points are created. More...
 
const std::pair< double, double > & min_and_max_coordinates (const unsigned &i) const
 
const Vector< std::pair< double, double > > & min_and_max_coordinates () const
 
bool use_eulerian_coordinates_during_setup () const
 
unsignednsample_points_generated_per_element ()
 "Measure of" number of sample points generated in each element More...
 
doublemax_search_radius ()
 

Protected Attributes

Vector< unsignedDimensions_of_bin_array
 Number of bins in each coordinate direction. More...
 
- Protected Attributes inherited from SamplePointContainer
Mesh * Mesh_pt
 Pointer to mesh from whose FiniteElements sample points are created. More...
 
Vector< std::pair< double, double > > Min_and_max_coordinates
 
bool Use_eulerian_coordinates_during_setup
 
unsigned Nsample_points_generated_per_element
 "Measure of" number of sample points generated in each element More...
 
unsigned Total_number_of_sample_points_visited_during_locate_zeta_from_top_level
 
double Max_search_radius
 

Additional Inherited Members

- Static Public Attributes inherited from SamplePointContainer
static std::ofstream Visited_sample_points_file
 File to record sequence of visited sample points in. More...
 
static bool Always_fail_elemental_locate_zeta = false
 Boolean flag to make to make locate zeta fail. More...
 
static bool Use_equally_spaced_interior_sample_points = true
 
static bool Enable_timing_of_setup = false
 Time setup? More...
 
static double Percentage_offset = 5.0
 Offset of sample point container boundaries beyond max/min coords. More...
 
- Protected Member Functions inherited from SamplePointContainer
void setup_min_and_max_coordinates ()
 Setup the min and max coordinates for the mesh, in each dimension. More...
 

Detailed Description

Base class for all bin arrays.

///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////

Constructor & Destructor Documentation

◆ BinArray() [1/3]

BinArray::BinArray ( Mesh *  mesh_pt,
const Vector< std::pair< double, double >> &  min_and_max_coordinates,
const Vector< unsigned > &  dimensions_of_bin_array,
const bool use_eulerian_coordinates_during_setup,
const bool ignore_halo_elements_during_locate_zeta_search,
const unsigned nsample_points_generated_per_element 
)
inline

Constructor.

414  ignore_halo_elements_during_locate_zeta_search,
417  {
418  // Note: Resizing of Dimensions_of_bin_array if no sizes are specified
419  // is delayed to derived class since refineable and nonrefineable
420  // bin arrays have different defaults.
421  }
Vector< unsigned > dimensions_of_bin_array() const
Definition: sample_point_container.h:494
Vector< unsigned > Dimensions_of_bin_array
Number of bins in each coordinate direction.
Definition: sample_point_container.h:508
unsigned & nsample_points_generated_per_element()
"Measure of" number of sample points generated in each element
Definition: sample_point_container.h:314
SamplePointContainer()
Definition: sample_point_container.h:233
const Vector< std::pair< double, double > > & min_and_max_coordinates() const
Definition: sample_point_container.h:290
bool use_eulerian_coordinates_during_setup() const
Definition: sample_point_container.h:308
Mesh * mesh_pt() const
Pointer to mesh from whose FiniteElements sample points are created.
Definition: sample_point_container.h:275

◆ BinArray() [2/3]

BinArray::BinArray ( )
inline

Broken default constructor; needed for broken copy constructors. Don't call. It will die.

426  {
427  // Throw the error
428  throw OomphLibError("Broken default constructor. Don't call this!",
431  }
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

◆ BinArray() [3/3]

BinArray::BinArray ( const BinArray data)
delete

Broken copy constructor.

◆ ~BinArray()

virtual BinArray::~BinArray ( )
inlinevirtual

Virtual destructor.

440 {}

Member Function Documentation

◆ coords_to_bin_index()

unsigned BinArray::coords_to_bin_index ( const Vector< double > &  zeta)

Get (linearly enumerated) bin index of bin that contains specified zeta

Update the coef and the bin index

1841  {
1842  unsigned coef = 1;
1843  unsigned n_bin = 0;
1844  const unsigned dim = ndim_zeta();
1845 
1846  // Loop over all the dimensions
1847  for (unsigned u = 0; u < dim; u++)
1848  {
1849  // for each one get the correct bin "coordinate"
1850  unsigned local_bin_number = 0;
1851 
1852  if (zeta[u] < Min_and_max_coordinates[u].first)
1853  {
1854  local_bin_number = 0;
1855  }
1856  else if (zeta[u] > Min_and_max_coordinates[u].second)
1857  {
1858  local_bin_number = dimensions_of_bin_array(u) - 1;
1859  }
1860  else
1861  {
1862  local_bin_number = (int(std::min(
1863  dimensions_of_bin_array(u) - 1,
1864  unsigned(floor(double(zeta[u] - Min_and_max_coordinates[u].first) /
1865  double(Min_and_max_coordinates[u].second -
1866  Min_and_max_coordinates[u].first) *
1867  double(dimensions_of_bin_array(u)))))));
1868  }
1869 
1871  n_bin += local_bin_number * coef;
1872  coef *= dimensions_of_bin_array(u);
1873  }
1874 
1875  // return the correct bin index
1876  return (n_bin);
1877  }
unsigned ndim_zeta() const
Dimension of the zeta ( = dim of local coordinate of elements)
Definition: sample_point_container.h:480
Vector< std::pair< double, double > > Min_and_max_coordinates
Definition: sample_point_container.h:363
#define min(a, b)
Definition: datatypes.h:22
return int(ret)+1
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 floor(const bfloat16 &a)
Definition: BFloat16.h:643
EIGEN_STRONG_INLINE const Eigen::CwiseBinaryOp< Eigen::internal::scalar_zeta_op< typename DerivedX::Scalar >, const DerivedX, const DerivedQ > zeta(const Eigen::ArrayBase< DerivedX > &x, const Eigen::ArrayBase< DerivedQ > &q)
Definition: SpecialFunctionsArrayAPI.h:152

References dimensions_of_bin_array(), Eigen::bfloat16_impl::floor(), int(), min, SamplePointContainer::Min_and_max_coordinates, ndim_zeta(), and Eigen::zeta().

Referenced by RefineableBinArray::add_sample_point(), RefineableBinArray::fill_bin_array(), RefineableBinArray::locate_zeta(), and profile_get_neighbouring_bins_helper().

◆ coords_to_vectorial_bin_index()

void BinArray::coords_to_vectorial_bin_index ( const Vector< double > &  zeta,
Vector< unsigned > &  bin_index 
)

Get "coordinates" of bin that contains specified zeta.

1971  {
1972  unsigned dim = ndim_zeta();
1973  bin_index.resize(dim);
1974  for (unsigned u = 0; u < dim; u++)
1975  {
1976  if (zeta[u] < Min_and_max_coordinates[u].first)
1977  {
1978  bin_index[u] = 0;
1979  }
1980  else if (zeta[u] > Min_and_max_coordinates[u].second)
1981  {
1982  bin_index[u] = dimensions_of_bin_array(u) - 1;
1983  }
1984  else
1985  {
1986  bin_index[u] = (int(
1988  unsigned(floor((zeta[u] - Min_and_max_coordinates[u].first) /
1989  double(Min_and_max_coordinates[u].second -
1990  Min_and_max_coordinates[u].first) *
1991  double(dimensions_of_bin_array(u)))))));
1992  }
1993  }
1994  }

References dimensions_of_bin_array(), Eigen::bfloat16_impl::floor(), int(), min, SamplePointContainer::Min_and_max_coordinates, ndim_zeta(), and Eigen::zeta().

Referenced by RefineableBinArray::locate_zeta(), and profile_get_neighbouring_bins_helper().

◆ dimension_of_bin_array()

unsigned BinArray::dimension_of_bin_array ( const unsigned i) const
inline

Number of bins in coordinate direction i.

487  {
488  return Dimensions_of_bin_array[i];
489  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9

References Dimensions_of_bin_array, and i.

Referenced by RefineableBinArray::get_bin_boundaries().

◆ dimensions_of_bin_array() [1/2]

Vector<unsigned> BinArray::dimensions_of_bin_array ( ) const
inline

Number of bins in coordinate directions. Const vector-based version

495  {
497  }

References Dimensions_of_bin_array.

Referenced by coords_to_bin_index(), and coords_to_vectorial_bin_index().

◆ dimensions_of_bin_array() [2/2]

unsigned BinArray::dimensions_of_bin_array ( const unsigned i) const
inline

Number of bins in specified coordinate direction.

502  {
503  return Dimensions_of_bin_array[i];
504  }

References Dimensions_of_bin_array, and i.

◆ get_neighbouring_bins_helper()

void BinArray::get_neighbouring_bins_helper ( const unsigned bin_index,
const unsigned radius,
Vector< unsigned > &  neighbouring_bin_index,
const bool use_old_version = true 
)

Helper function for computing the bin indices of neighbouring bins at a given "radius" of the specified bin. Final, optional boolean (default: true) chooses to use the old version which appears to be faster than Louis' new one after all (in the few cases where this functionality is still used – not all if we have cgal!)

Helper function for computing the bin indices of neighbouring bins at a given "radius" of the specified bin

1355  {
1356  // OLD VERSION
1357  if (use_old_version)
1358  {
1359  neighbouring_bin_index.clear();
1360 
1361  // Quick return (slightly hacky -- the machinery below adds the
1362  // "home" bin twice...)
1363  if (radius == 0)
1364  {
1365  neighbouring_bin_index.push_back(bin_index);
1366  return;
1367  }
1368 
1369  // translate old code
1370  unsigned level = radius;
1371  unsigned bin = bin_index;
1372 
1373  // Dimension
1374  const unsigned n_lagrangian = this->ndim_zeta();
1375 
1376  // This will be different depending on the number of Lagrangian
1377  // coordinates
1378  if (n_lagrangian == 1)
1379  {
1380  // Reserve memory for the container where we return the indices
1381  // of the neighbouring bins (2 bins max, left and right)
1382  neighbouring_bin_index.reserve(2);
1383 
1384  // Single "loop" in one direction - always a vector of max size 2
1385  unsigned nbr_bin_left = bin - level;
1386  if (nbr_bin_left < Dimensions_of_bin_array[0])
1387  {
1388  unsigned nbr_bin = nbr_bin_left;
1389  neighbouring_bin_index.push_back(nbr_bin);
1390  }
1391  unsigned nbr_bin_right = bin + level;
1392  if ((nbr_bin_right < Dimensions_of_bin_array[0]) &&
1393  (nbr_bin_right != nbr_bin_left))
1394  {
1395  unsigned nbr_bin = nbr_bin_right;
1396  neighbouring_bin_index.push_back(nbr_bin);
1397  }
1398  }
1399  else if (n_lagrangian == 2)
1400  {
1401  // Reserve memory for the container where we return the indices
1402  // of the neighbouring bins
1403  const unsigned n_max_neighbour_bins = 8 * level;
1404  neighbouring_bin_index.reserve(n_max_neighbour_bins);
1405 
1406  const unsigned n_total_bin =
1408 
1409  // Which row of the bin structure is the current bin on?
1410  // This is just given by the integer answer of dividing bin
1411  // by Nbin_x (the number of bins in a single row)
1412  // e.g. in a 6x6 grid, bins 6 through 11 would all have bin_row=1
1413  const unsigned bin_row = bin / Dimensions_of_bin_array[0];
1414 
1415  // The neighbour_bin vector contains all bin numbers at the
1416  // specified "distance" (level) away from the current bin
1417 
1418  // Row/column length
1419  const unsigned n_length = (level * 2) + 1;
1420 
1421  {
1422  // Visit all the bins at the specified distance (level) away
1423  // from the current bin. In order to obtain the same order in
1424  // the visited bins as the previous algorithm we visit all the
1425  // bins at the specified distance (level) as follows:
1426 
1427  // Suppose we want the bins at distance (level=2) of the
1428  // specified bin, then we visit them as indicated below
1429 
1430  // 01 02 03 04 05 // First row
1431  // 06 07
1432  // 08 B 09
1433  // 10 11
1434  // 12 13 14 15 16 // Last row
1435  // ^--------------- First column
1436  // ^-- Last column
1437 
1438  // ----------------------------------------------------------------
1439  // Visit all the bins in the first row at the specified
1440  // distance (level) away from the current bin
1441 
1442  // ------------------ FIRST ROW ------------------------
1443  // Pre-compute the distance in the j-direction
1444  const unsigned j_precomputed = level * Dimensions_of_bin_array[0];
1445  // Pre-compute the row where the bin should lie on
1446  const unsigned j_initial_row = bin_row - level;
1447 
1448  // Loop over the columns (of the first row)
1449  for (unsigned i = 0; i < n_length; i++)
1450  {
1451  // --------- First row ------------------------------------------
1452  const unsigned initial_neighbour_bin =
1453  bin - (level - i) - j_precomputed;
1454  // This number might fall on the wrong row of the bin
1455  // structure; this needs to be tested? Not sure why, but leave
1456  // the test!
1457 
1458  // Which row is this number on? (see above)
1459  const unsigned initial_neighbour_bin_row =
1460  initial_neighbour_bin / Dimensions_of_bin_array[0];
1461  // These numbers for the rows must match; if it is then add
1462  // initial_neighbour_bin to the neighbour scheme (The bin
1463  // number must also be greater than zero and less than the
1464  // total number of bins)
1465  if ((j_initial_row == initial_neighbour_bin_row) &&
1466  (initial_neighbour_bin < n_total_bin))
1467  {
1468  neighbouring_bin_index.push_back(initial_neighbour_bin);
1469  }
1470 
1471  } // for (unsigned i=0;i<n_length;i++)
1472 
1473  // Then visit all the bins in the first and last column at the
1474  // specified distance (level) away from the current bin
1475 
1476  // ------------------ FIRST AND LAST COLUMNS ---------------------
1477  // Loop over the rows (of the first and last column)
1478  for (unsigned j = 1; j < n_length - 1; j++)
1479  {
1480  // --------- First column ---------------------------------------
1481  const unsigned initial_neighbour_bin =
1482  bin - (level) - ((level - j) * Dimensions_of_bin_array[0]);
1483  // This number might fall on the wrong row of the bin
1484  // structure; this needs to be tested? Not sure why, but leave
1485  // the test!
1486 
1487  // Which row is this number on? (see above)
1488  const unsigned initial_neighbour_bin_row =
1489  initial_neighbour_bin / Dimensions_of_bin_array[0];
1490 
1491  // Which row should it be on?
1492  const unsigned initial_row = bin_row - (level - j);
1493 
1494  // These numbers for the rows must match; if it is then add
1495  // initial_neighbour_bin to the neighbour scheme (The bin
1496  // number must also be greater than zero and less than the
1497  // total number of bins)
1498  if ((initial_row == initial_neighbour_bin_row) &&
1499  (initial_neighbour_bin < n_total_bin))
1500  {
1501  neighbouring_bin_index.push_back(initial_neighbour_bin);
1502  }
1503 
1504  // --------- Last column -----------------------------------------
1505  const unsigned final_neighbour_bin =
1506  bin + (level) - ((level - j) * Dimensions_of_bin_array[0]);
1507  // This number might fall on the wrong row of the bin
1508  // structure; this needs to be tested? Not sure why, but leave
1509  // the test!
1510 
1511  // Which row is this number on? (see above)
1512  const unsigned final_neighbour_bin_row =
1513  final_neighbour_bin / Dimensions_of_bin_array[0];
1514 
1515  // Which row should it be on?
1516  const unsigned final_row = bin_row - (level - j);
1517 
1518  // These numbers for the rows must match; if it is then add
1519  // initial_neighbour_bin to the neighbour scheme (The bin
1520  // number must also be greater than zero and less than the
1521  // total number of bins)
1522  if ((final_row == final_neighbour_bin_row) &&
1523  (final_neighbour_bin < n_total_bin))
1524  {
1525  neighbouring_bin_index.push_back(final_neighbour_bin);
1526  }
1527 
1528  } // for (unsigned j=1;j<n_length-1;j++)
1529 
1530  // ------------------ LAST ROW ------------------------
1531  // Pre-compute the row where the bin should lie on
1532  const unsigned j_final_row = bin_row + level;
1533 
1534  // Loop over the columns (of the last row)
1535  for (unsigned i = 0; i < n_length; i++)
1536  {
1537  // --------- Last row ------------------------------------------
1538  const unsigned final_neighbour_bin =
1539  bin - (level - i) + j_precomputed;
1540  // This number might fall on the wrong row of the bin
1541  // structure; this needs to be tested? Not sure why, but leave
1542  // the test!
1543 
1544  // Which row is this number on? (see above)
1545  const unsigned final_neighbour_bin_row =
1546  final_neighbour_bin / Dimensions_of_bin_array[0];
1547  // These numbers for the rows must match; if it is then add
1548  // initial_neighbour_bin to the neighbour scheme (The bin
1549  // number must also be greater than zero and less than the
1550  // total number of bins)
1551  if ((j_final_row == final_neighbour_bin_row) &&
1552  (final_neighbour_bin < n_total_bin))
1553  {
1554  neighbouring_bin_index.push_back(final_neighbour_bin);
1555  }
1556 
1557  } // for (unsigned i=0;i<n_length;i++)
1558  }
1559  }
1560  else if (n_lagrangian == 3)
1561  {
1562  // Reserve memory for the container where we return the indices
1563  // of the neighbouring bins
1564  const unsigned n_max_neighbour_bins =
1565  8 * level * (3 + 2 * (level - 1)) +
1566  2 * (2 * (level - 1) + 1) * (2 * (level - 1) + 1);
1567  neighbouring_bin_index.reserve(n_max_neighbour_bins);
1568 
1569  unsigned n_total_bin = Dimensions_of_bin_array[0] *
1572 
1573  // Which layer of the bin structure is the current bin on?
1574  // This is just given by the integer answer of dividing bin
1575  // by Nbin_x*Nbin_y (the number of bins in a single layer
1576  // e.g. in a 6x6x6 grid, bins 72 through 107 would all have bin_layer=2
1577  unsigned bin_layer =
1579 
1580  // Which row in this layer is the bin number on?
1581  unsigned bin_row = (bin / Dimensions_of_bin_array[0]) -
1582  (bin_layer * Dimensions_of_bin_array[1]);
1583 
1584  // The neighbour_bin vector contains all bin numbers at the
1585  // specified "distance" (level) away from the current bin
1586 
1587  // Row/column/layer length
1588  unsigned n_length = (level * 2) + 1;
1589 
1590  // Loop over the layers
1591  for (unsigned k = 0; k < n_length; k++)
1592  {
1593  // Loop over the rows
1594  for (unsigned j = 0; j < n_length; j++)
1595  {
1596  // Loop over the columns
1597  for (unsigned i = 0; i < n_length; i++)
1598  {
1599  // Only do this for the end points of every row/layer/column
1600  if ((k == 0) || (k == n_length - 1) || (j == 0) ||
1601  (j == n_length - 1) || (i == 0) || (i == n_length - 1))
1602  {
1603  unsigned nbr_bin = bin - level + i -
1604  ((level - j) * Dimensions_of_bin_array[0]) -
1605  ((level - k) * Dimensions_of_bin_array[0] *
1607  // This number might fall on the wrong
1608  // row or layer of the bin structure; this needs to be tested
1609 
1610  // Which layer is this number on?
1611  unsigned nbr_bin_layer = nbr_bin / (Dimensions_of_bin_array[0] *
1613 
1614  // Which row is this number on? (see above)
1615  unsigned nbr_bin_row =
1616  (nbr_bin / Dimensions_of_bin_array[0]) -
1617  (nbr_bin_layer * Dimensions_of_bin_array[1]);
1618 
1619  // Which layer and row should it be on, given level?
1620  unsigned layer = bin_layer - level + k;
1621  unsigned row = bin_row - level + j;
1622 
1623  // These layers and rows must match up:
1624  // if so then add nbr_bin to the neighbour schemes
1625  // (The bin number must also be greater than zero
1626  // and less than the total number of bins)
1627  if ((row == nbr_bin_row) && (layer == nbr_bin_layer) &&
1628  (nbr_bin < n_total_bin))
1629  {
1630  neighbouring_bin_index.push_back(nbr_bin);
1631  }
1632  }
1633  }
1634  }
1635  }
1636  }
1637  }
1638  // LOUIS'S VERSION
1639  else
1640  {
1641  neighbouring_bin_index.clear();
1642 
1643  // Just testing if the radius is equal to 0
1644  if (radius == 0)
1645  {
1646  // in this case we only have to push back the bin
1647  neighbouring_bin_index.push_back(bin_index);
1648  }
1649  // Else, if the radius is different from 0
1650  else
1651  {
1652  unsigned dim = ndim_zeta();
1653 
1654  // The vector which will store the coordinates of the bin in the bin
1655  // arrray
1656  Vector<int> vector_of_positions(3);
1657 
1658  // Will store locally the dimension of the bin array
1659  Vector<int> vector_of_dimensions(3);
1660 
1661  // Will store the radiuses for each dimension
1662  // If it is 0, that means the dimension is not vector_of_active_dim
1663  Vector<int> vector_of_radiuses(3);
1664 
1665  // Stores true if the dimension is "active" or false if the
1666  // dimension is inactive (for example the third dimension is inactive in
1667  // a 2D mesh).
1668  std::vector<bool> vector_of_active_dim(3);
1669 
1670  // Will store the coefficients you have to multiply each bin coordinate
1671  // to have the correct unsigned corresponding to the bin index.
1672  Vector<int> vector_of_coef(3);
1673 
1674 
1675  // First initializing this MyArrays for the active dimensions
1676  unsigned coef = 1;
1677  for (unsigned u = 0; u < dim; u++)
1678  {
1679  vector_of_positions[u] =
1680  (((bin_index / coef) % (Dimensions_of_bin_array[u])));
1681  vector_of_coef[u] = coef;
1682  coef *= Dimensions_of_bin_array[u];
1683  vector_of_dimensions[u] = Dimensions_of_bin_array[u];
1684  vector_of_radiuses[u] = radius;
1685  vector_of_active_dim[u] = true;
1686  }
1687  // Filling the rest with default values
1688  for (unsigned u = dim; u < 3; u++)
1689  {
1690  vector_of_positions[u] = 0;
1691  vector_of_coef[u] = 0;
1692  vector_of_dimensions[u] = 1;
1693  vector_of_radiuses[u] = 0;
1694  vector_of_active_dim[u] = false;
1695  }
1696 
1697  // First we fill the bins which corresponds to x+radius and x-radius in
1698  // the bin array (x being the first coordinate/dimension).
1699  // For j equal to radius or -radius
1700  for (int j = -vector_of_radiuses[0]; j <= vector_of_radiuses[0];
1701  j += 2 * vector_of_radiuses[0]) // j corresponds to x
1702  {
1703  int local_tempj =
1704  vector_of_positions[0] + j; // Corresponding bin index
1705  // if we are in the bin array
1706  if (local_tempj >= 0 && local_tempj < vector_of_dimensions[0])
1707  {
1708  // Loop over all the bins
1709  for (int i = -vector_of_radiuses[1]; i <= vector_of_radiuses[1];
1710  i++)
1711  {
1712  // i corresponds to y (2nd dim)
1713  int local_tempi = vector_of_positions[1] + i;
1714  // if we are still in the bin array
1715  if (local_tempi >= 0 && local_tempi < vector_of_dimensions[1])
1716  {
1717  for (int k = -vector_of_radiuses[2]; k <= vector_of_radiuses[2];
1718  k++)
1719  {
1720  // k corresponds to z (third dimension)
1721  int local_tempk = vector_of_positions[2] + k;
1722  // if we are still in the bin array
1723  if (local_tempk >= 0 && local_tempk < vector_of_dimensions[2])
1724  {
1725  neighbouring_bin_index.push_back(
1726  local_tempj * vector_of_coef[0] +
1727  local_tempi * vector_of_coef[1] +
1728  local_tempk * vector_of_coef[2]);
1729  }
1730  }
1731  }
1732  }
1733  }
1734  }
1735  // Secondly we get the bins corresponding to y+radius and y-radius
1736  // only if the second dimension is active
1737  if (vector_of_active_dim[1])
1738  {
1739  // For i equal to radius or -radius (i corresponds to y)
1740  for (int i = -vector_of_radiuses[1]; i <= vector_of_radiuses[1];
1741  i += 2 * vector_of_radiuses[1])
1742  {
1743  int local_tempi = vector_of_positions[1] + i;
1744  if (local_tempi >= 0 && local_tempi < vector_of_dimensions[1])
1745  {
1746  // We loop over all the surface
1747  for (int j = -vector_of_radiuses[0] + 1;
1748  j <= vector_of_radiuses[0] - 1;
1749  j++)
1750  {
1751  int local_tempj = vector_of_positions[0] + j;
1752  if (local_tempj >= 0 && local_tempj < vector_of_dimensions[0])
1753  {
1754  for (int k = -vector_of_radiuses[2];
1755  k <= vector_of_radiuses[2];
1756  k++)
1757  {
1758  int local_tempk = vector_of_positions[2] + k;
1759  if (local_tempk >= 0 &&
1760  local_tempk < vector_of_dimensions[2])
1761  {
1762  neighbouring_bin_index.push_back(
1763  local_tempj * vector_of_coef[0] +
1764  local_tempi * vector_of_coef[1] +
1765  local_tempk * vector_of_coef[2]);
1766  }
1767  }
1768  }
1769  }
1770  }
1771  }
1772  }
1773  // Thirdly we get the bins corresponding to z+radius and z-radius
1774  // if the third dimension is active.
1775  if (vector_of_active_dim[2])
1776  {
1777  // for k equal to radius or -radius (k corresponds to z)
1778  for (int k = -vector_of_radiuses[2]; k <= vector_of_radiuses[2];
1779  k += 2 * vector_of_radiuses[2])
1780  {
1781  int local_tempk = vector_of_positions[2] + k;
1782  if (local_tempk >= 0 && local_tempk < vector_of_dimensions[2])
1783  {
1784  // We loop over all the surface
1785  for (int j = -vector_of_radiuses[0] + 1;
1786  j <= vector_of_radiuses[0] - 1;
1787  j++)
1788  {
1789  int local_tempj = vector_of_positions[0] + j;
1790  if (local_tempj >= 0 && local_tempj < vector_of_dimensions[0])
1791  {
1792  for (int i = -vector_of_radiuses[1] + 1;
1793  i <= vector_of_radiuses[1] - 1;
1794  i++)
1795  {
1796  int local_tempi = vector_of_positions[1] + i;
1797  if (local_tempi >= 0 &&
1798  local_tempi < vector_of_dimensions[1])
1799  {
1800  neighbouring_bin_index.push_back(
1801  local_tempj * vector_of_coef[0] +
1802  local_tempi * vector_of_coef[1] +
1803  local_tempk * vector_of_coef[2]);
1804  }
1805  }
1806  }
1807  }
1808  }
1809  }
1810  }
1811  }
1812  } // end new version
1813  }
m row(1)
char char char int int * k
Definition: level2_impl.h:374
radius
Definition: UniformPSDSelfTest.py:15
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Dimensions_of_bin_array, i, j, k, ndim_zeta(), UniformPSDSelfTest::radius, and row().

Referenced by NonRefineableBinArray::fill_bin_by_diffusion(), RefineableBinArray::locate_zeta(), NonRefineableBinArray::locate_zeta(), RefineableBinArray::output_neighbouring_bins(), and profile_get_neighbouring_bins_helper().

◆ max_bin_dimension()

unsigned BinArray::max_bin_dimension ( ) const

Max. bin dimension (number of bins in coordinate directions)

660  {
661  unsigned dim = ndim_zeta();
662  unsigned n_max_level = Dimensions_of_bin_array[0];
663  if (dim >= 2)
664  {
665  if (Dimensions_of_bin_array[1] > n_max_level)
666  {
667  n_max_level = Dimensions_of_bin_array[1];
668  }
669  }
670  if (dim == 3)
671  {
672  if (Dimensions_of_bin_array[2] > n_max_level)
673  {
674  n_max_level = Dimensions_of_bin_array[2];
675  }
676  }
677  return n_max_level;
678  }

Referenced by oomph::Multi_domain_functions::aux_setup_multi_domain_interaction(), check_locate_zeta(), and NonRefineableBinArray::NonRefineableBinArray().

◆ nbin()

virtual unsigned BinArray::nbin ( ) const
pure virtual

Number of bins (not taking recursion into account for refineable versions)

Implemented in NonRefineableBinArray, and RefineableBinArray.

◆ ndim_zeta()

◆ operator=()

void BinArray::operator= ( const BinArray )
delete

Broken assignment operator.

◆ output_bin_vertices()

virtual void BinArray::output_bin_vertices ( std::ofstream &  outfile)
pure virtual

Output bin vertices (allowing display of bin boundaries as zones).

Implemented in NonRefineableBinArray, and RefineableBinArray.

◆ output_bins()

virtual void BinArray::output_bins ( std::ofstream &  outfile)
pure virtual

Output bins (boundaries and number of sample points in them)

Implemented in NonRefineableBinArray, and RefineableBinArray.

Referenced by oomph::Multi_domain_functions::aux_setup_multi_domain_interaction().

◆ profile_get_neighbouring_bins_helper()

void BinArray::profile_get_neighbouring_bins_helper ( )

Profiling function to compare performance of two different versions of the get_neighbouring_bins_helper(...) function

1228  {
1229  unsigned old_faster = 0;
1230  unsigned new_faster = 0;
1231  double t_total_new = 0.0;
1232  double t_total_old = 0.0;
1233 
1234  unsigned dim = ndim_zeta();
1235 
1236  // Choose bin in middle of the domain
1237  Vector<double> zeta(dim);
1238  for (unsigned i = 0; i < dim; i++)
1239  {
1240  zeta[i] = 0.5 * (Min_and_max_coordinates[i].first +
1241  Min_and_max_coordinates[i].second);
1242  }
1243 
1244  // Finding the bin in which the point is located
1245  int bin_index = coords_to_bin_index(zeta);
1246 
1247 #ifdef PARANOID
1248  if (bin_index < 0)
1249  {
1250  throw OomphLibError("Negative bin index...",
1253  }
1254 #endif
1255 
1256  // Start at this radius (radius = 0 is the central bin)
1257  unsigned radius = 0;
1258 
1259  // "coordinates" of the bin which is most likely to contain the
1260  // point
1261  Vector<unsigned> bin_index_v(dim);
1262  coords_to_vectorial_bin_index(zeta, bin_index_v);
1263 
1264  // We loop over all the dimensions to find the maximum radius we have to
1265  // do the spiraling if we want to be sure there is no bin left at the end
1266  unsigned max_radius = 0;
1267  for (unsigned k = 0; k < dim; k++)
1268  {
1269  unsigned local =
1270  std::max((bin_index_v[k] + 1),
1271  (Dimensions_of_bin_array[k] - bin_index_v[k] - 1));
1272  if (local > max_radius)
1273  {
1274  max_radius = local;
1275  }
1276  }
1277 
1278  // Vector which will store the indices of the neighbouring bins
1279  // at the current radius
1280  Vector<unsigned> bin_index_at_current_radius_old;
1281  Vector<unsigned> bin_index_at_current_radius_new;
1282  while (radius <= max_radius)
1283  {
1284  // Get the neighbouring bins
1285  bin_index_at_current_radius_old.clear();
1286  double t_start = TimingHelpers::timer();
1288  bin_index, radius, bin_index_at_current_radius_old, true);
1289  unsigned nbin_at_current_radius_old =
1290  bin_index_at_current_radius_old.size();
1291  double t_end = TimingHelpers::timer();
1292  double t_old = t_end - t_start;
1293 
1294  bin_index_at_current_radius_new.clear();
1295  double t_start_new = TimingHelpers::timer();
1297  bin_index, radius, bin_index_at_current_radius_new, false);
1298  unsigned nbin_at_current_radius_new =
1299  bin_index_at_current_radius_new.size();
1300  double t_end_new = TimingHelpers::timer();
1301 
1302  double t_new = t_end_new - t_start_new;
1303 
1304  if (nbin_at_current_radius_new != nbin_at_current_radius_old)
1305  {
1306  oomph_info << "Number of bins don't match: new = "
1307  << nbin_at_current_radius_new
1308  << "old = " << nbin_at_current_radius_old
1309  << " radius = " << radius << std::endl;
1310  oomph_info << "Old: " << std::endl;
1311  for (unsigned i = 0; i < nbin_at_current_radius_old; i++)
1312  {
1313  oomph_info << bin_index_at_current_radius_old[i] << " ";
1314  }
1315  oomph_info << std::endl;
1316  oomph_info << "New: " << std::endl;
1317  for (unsigned i = 0; i < nbin_at_current_radius_new; i++)
1318  {
1319  oomph_info << bin_index_at_current_radius_new[i] << " ";
1320  }
1321  oomph_info << std::endl;
1322  }
1323 
1324  t_total_new += t_new;
1325  t_total_old += t_old;
1326 
1327  if (t_new < t_old)
1328  {
1329  new_faster++;
1330  }
1331  else
1332  {
1333  old_faster++;
1334  }
1335  radius++;
1336  }
1337 
1338 
1339  oomph_info << "Number of times old/new version was faster: " << old_faster
1340  << " " << new_faster << std::endl
1341  << "Total old/new time: " << t_total_old << " " << t_total_new
1342  << " " << std::endl;
1343  }
void get_neighbouring_bins_helper(const unsigned &bin_index, const unsigned &radius, Vector< unsigned > &neighbouring_bin_index, const bool &use_old_version=true)
Definition: sample_point_container.cc:1350
unsigned coords_to_bin_index(const Vector< double > &zeta)
Definition: sample_point_container.cc:1840
void coords_to_vectorial_bin_index(const Vector< double > &zeta, Vector< unsigned > &bin_index)
Get "coordinates" of bin that contains specified zeta.
Definition: sample_point_container.cc:1969
#define max(a, b)
Definition: datatypes.h:23
OomphInfo oomph_info
Definition: oomph_definitions.cc:319
double timer
Definition: oomph_metis_from_parmetis_3.1.1/struct.h:210

References coords_to_bin_index(), coords_to_vectorial_bin_index(), Dimensions_of_bin_array, get_neighbouring_bins_helper(), i, k, max, SamplePointContainer::Min_and_max_coordinates, ndim_zeta(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::oomph_info, UniformPSDSelfTest::radius, and Eigen::zeta().

Member Data Documentation

◆ Dimensions_of_bin_array


The documentation for this class was generated from the following files: