LCOV - code coverage report
Current view: top level - coupling/datastructures - CouplingCellWithLinkedCells.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 54.8 % 31 17
Test Date: 2026-08-21 15:14:06 Functions: 12.5 % 16 2

            Line data    Source code
       1              : #ifndef _MOLECULARDYNAMICS_COUPLING_DATASTRUCTURES_COUPLINGCELLWITHLINKEDCELLS_H_
       2              : #define _MOLECULARDYNAMICS_COUPLING_DATASTRUCTURES_COUPLINGCELLWITHLINKEDCELLS_H_
       3              : 
       4              : #include "CouplingCell.h"
       5              : 
       6              : namespace coupling {
       7              : namespace datastructures {
       8              : template <class LinkedCell, unsigned int dim> class CouplingCellWithLinkedCells;
       9              : } // namespace datastructures
      10              : } // namespace coupling
      11              : 
      12              : /** describes a quadratic/ cubic coupling cell filled with fluid. It is built
      13              :  *up by a certain number of linked cells (from the MD algorithm). The linked
      14              :  *  cells need to exactly fill this cell; no overlap/ non-fitting boundaries
      15              :  *  shall be allowed.
      16              :  *  We can use the CouplingCell-structure to evaluate macroscopic quantities
      17              :  *  over a certain MD volume and then map macroscopic conserved quantities
      18              :  *  between macro- and microscopic simulations.
      19              :  *      @brief defines the cell type with cell-averaged quantities. Derived from
      20              :  *the class coupling::datastructures::CouplingCell
      21              :  *      @tparam LinkedCell linked cells that build up the
      22              :  *CouplingCellWithLinkedCells
      23              :  *      @tparam dim Number of dimensions; it can be 1, 2 or 3
      24              :  *  @author Philipp Neumann
      25              :  */
      26              : template <class LinkedCell, unsigned int dim> class coupling::datastructures::CouplingCellWithLinkedCells : public coupling::datastructures::CouplingCell<dim> {
      27              : public:
      28              :   /** Constructor: initialises the coupling cell based on the assumption of
      29              :    * having blockSize linked cells;
      30              :    *  @param blockSize represents the number of linked cells in all spatial
      31              :    * directions.
      32              :    */
      33        19708 :   CouplingCellWithLinkedCells(tarch::la::Vector<dim, unsigned int> blockSize)
      34        19708 :       : coupling::datastructures::CouplingCell<dim>(), _numberCells(getNumberCells(blockSize)), _linkedCells(NULL) {
      35              : 
      36        19708 :     _linkedCells = new LinkedCell*[_numberCells];
      37        19708 :     if (_linkedCells == NULL) {
      38            0 :       std::cout << "ERROR coupling::datastructures::CouplingCellWithLinkedCells: "
      39              :                    "_linkedCells == NULL"
      40            0 :                 << std::endl;
      41            0 :       exit(EXIT_FAILURE);
      42              :     }
      43              :     // set each pointer to a NULL pointer
      44       176616 :     for (unsigned int i = 0; i < _numberCells; i++) {
      45       156908 :       _linkedCells[i] = NULL;
      46              :     }
      47        19708 :   }
      48              :   /** Destructor */
      49        19600 :   virtual ~CouplingCellWithLinkedCells() {
      50        19600 :     if (_linkedCells != NULL) {
      51       176400 :       for (unsigned int i = 0; i < _numberCells; i++) {
      52       156800 :         _linkedCells[i] = NULL;
      53              :       }
      54        19600 :       delete[] _linkedCells;
      55        19600 :       _linkedCells = NULL;
      56              :     }
      57        19600 :   }
      58              : 
      59              :   /** adds a linked cell to the coupling cell and puts it at position index.
      60              :    * We refer to the lexicographic ordering of the linked cells here.
      61              :    * @param cell the linked cell that should be inserted into the coupling
      62              :    * cell
      63              :    * @param index specifies the position, at which cell should be inserted
      64              :    */
      65        69124 :   void addLinkedCell(LinkedCell& cell, const size_t index) { _linkedCells[index] = &cell; }
      66              : 
      67              :   /** This template fuction applies class A to all linked cells of this
      68              :    *coupling cell. The syntax is exactly the same as for regular cell
      69              :    *mappings so that a general cell mapping can also be directly applied to
      70              :    *single coupling cells only.
      71              :    *    @tparam A
      72              :    *    @param a
      73              :    */
      74            0 :   template <class A> void iterateCells(A& a) {
      75            0 :     a.beginCellIteration();
      76            0 :     for (unsigned int i = 0; i < _numberCells; i++) {
      77            0 :       a.handleCell(*(_linkedCells[i]));
      78              :     }
      79              :     a.endCellIteration();
      80            0 :   }
      81              : 
      82              :   /** This template function applies class A to all linked cells of this
      83              :    *coupling cell. The syntax is exactly the same as for regular cell
      84              :    *mappings so that a general cell mapping can also be directly applied to
      85              :    *single coupling cells only. This method is const, i.e. id does not modify
      86              :    *anything except for the object a. This allows for further optimisations.
      87              :    *    @tparam A
      88              :    *    @param a
      89              :    */
      90            0 :   template <class A> void iterateConstCells(A& a) const {
      91            0 :     a.beginCellIteration();
      92            0 :     for (unsigned int i = 0; i < _numberCells; i++) {
      93            0 :       a.handleCell(*(_linkedCells[i]));
      94              :     }
      95            0 :     a.endCellIteration();
      96            0 :   }
      97              : 
      98              : private:
      99              :   /** computes and returns the number of cells specified by the product of the
     100              :    * entries of blockSize in all dimensions
     101              :    *  @param blockSize represents the number of linked cells in all spatial
     102              :    * directions.
     103              :    */
     104              :   unsigned int getNumberCells(tarch::la::Vector<dim, unsigned int> blockSize) const {
     105              :     unsigned int num = 1;
     106        78832 :     for (unsigned int d = 0; d < dim; d++) {
     107        59124 :       num = num * blockSize[d];
     108              :     }
     109              :     return num;
     110              :   }
     111              : 
     112              :   /** total number of linked cells contained in this coupling cell */
     113              :   const size_t _numberCells;
     114              : 
     115              :   /** holds pointers to all linked cells that describe the microscopic dynamics
     116              :    * within the coupling cell */
     117              :   LinkedCell** _linkedCells;
     118              : };
     119              : 
     120              : #endif // _MOLECULARDYNAMICS_COUPLING_DATASTRUCTURES_COUPLINGCELLWITHLINKEDCELLS_H_
        

Generated by: LCOV version 2.0-1