LCOV - code coverage report
Current view: top level - coupling/sendrecv - DataExchangeFromAllMacro2MD.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 11.5 % 26 3
Test Date: 2026-08-21 15:14:06 Functions: 0.0 % 6 0

            Line data    Source code
       1              : // Copyright (C) 2015 Technische Universitaet Muenchen
       2              : // This file is part of the Mamico project. For conditions of distribution
       3              : // and use, please see the copyright notice in Mamico's main folder, or at
       4              : // www5.in.tum.de/mamico
       5              : #ifndef _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGEFROMALLMACRO2MD_H_
       6              : #define _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGEFROMALLMACRO2MD_H_
       7              : 
       8              : #include "coupling/CouplingMDDefinitions.h"
       9              : #include "coupling/datastructures/CouplingCell.h"
      10              : #include "coupling/indexing/IndexingService.h"
      11              : #include "coupling/interface/MacroscopicSolverInterface.h"
      12              : #include "coupling/sendrecv/DataExchange.h"
      13              : 
      14              : namespace coupling {
      15              : namespace sendrecv {
      16              : template <unsigned int dim> class DataExchangeFromAllMacro2MD;
      17              : }
      18              : } // namespace coupling
      19              : 
      20              : /** Same as _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGEFROMMACRO2MD_H_ but also sends on inner cells
      21              :  */
      22              : template <unsigned int dim>
      23              : class coupling::sendrecv::DataExchangeFromAllMacro2MD : public coupling::sendrecv::DataExchange<coupling::datastructures::CouplingCell<dim>, dim> {
      24              : 
      25              : public:
      26              :   /** Constructor
      27              :    *    @param interface macroscopic solver interface
      28              :    *    @param tagoffset 0 per default
      29              :    */
      30            4 :   DataExchangeFromAllMacro2MD(coupling::interface::MacroscopicSolverInterface<dim>* interface, unsigned int topologyOffset, unsigned int tagoffset = 0)
      31            4 :       : coupling::sendrecv::DataExchange<coupling::datastructures::CouplingCell<dim>, dim>(TAG_FROM_MACRO2MD + tagoffset), _msi(interface),
      32            4 :         _topologyOffset(topologyOffset) {
      33              : #if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
      34              :     std::cout << "DataExchangeFromAllMacro2MD initialised..." << std::endl;
      35              : #endif
      36              :   }
      37              :   /** Destructor */
      38            0 :   virtual ~DataExchangeFromAllMacro2MD() {}
      39              : 
      40              :   /** returns the ranks to which a particular cell (at index idx)
      41              :    *should be sent.
      42              :    *    @param  idx
      43              :    *    @return the corresponding ranks, if we need
      44              :    *information on MD side, otherwise empty vector
      45              :    */
      46            0 :   std::vector<unsigned int> getTargetRanks(I01 idx) override {
      47              :     // if we need information on MD side, return the respective ranks via
      48            0 :     if (I08::contains(idx)) {
      49            0 :       return IDXS.getRanksForGlobalIndex(idx, _topologyOffset);
      50              :       // otherwise return empty vector
      51              :     }
      52            0 :     return std::vector<unsigned int>();
      53              :   }
      54              : 
      55              :   /** returns all ranks from which a particular cell (at index idx)
      56              :    *is sent.
      57              :    *    @param  idx
      58              :    *    @return the corresponding ranks via MacroscopicSolverInterface, if we
      59              :    *need information on MD side, otherwise empty vector
      60              :    */
      61            0 :   std::vector<unsigned int> getSourceRanks(I01 idx) override {
      62            0 :     if (I08::contains(idx)) {
      63            0 :       return _msi->getSourceRanks(idx);
      64              :     }
      65            0 :     return std::vector<unsigned int>();
      66              :   }
      67              : 
      68              :   /** local rule to read from coupling cell and write data to (e.g. send)
      69              :    * buffer. We only send the macroscopic mass and macroscopic momentum from MD
      70              :    * to the macroscopic solver.
      71              :    *    @param buffer
      72              :    *    @param cell
      73              :    */
      74            0 :   void readFromCell(double* const buffer, const coupling::datastructures::CouplingCell<dim>& cell) override {
      75            0 :     buffer[0] = cell.getMicroscopicMass();
      76            0 :     for (unsigned int d = 0; d < dim; d++) {
      77            0 :       buffer[d + 1] = cell.getMicroscopicMomentum()[d];
      78              :     }
      79            0 :   }
      80              : 
      81              :   /** local rule to read from receive buffer and write data to coupling cell
      82              :    *    @param buffer
      83              :    *    @param cell
      84              :    */
      85            0 :   void writeToCell(const double* const buffer, coupling::datastructures::CouplingCell<dim>& cell) override {
      86            0 :     tarch::la::Vector<dim, double> microscopicMomentum(0.0);
      87            0 :     for (unsigned int d = 0; d < dim; d++) {
      88            0 :       microscopicMomentum[d] = buffer[1 + d];
      89              :     }
      90            0 :     cell.setMicroscopicMomentum(microscopicMomentum);
      91            0 :     cell.setMicroscopicMass(buffer[0]);
      92            0 :   }
      93              : 
      94              :   /** returns the number of doubles that are sent per coupling cell. @return
      95              :    * 1+dim  */
      96            0 :   unsigned int getDoublesPerCell() const override {
      97              :     // 1 double: microscopic mass; dim doubles: microscopic momentum
      98            0 :     return 1 + dim;
      99              :   }
     100              : 
     101              : private:
     102              :   coupling::interface::MacroscopicSolverInterface<dim>* _msi;
     103              :   unsigned int _topologyOffset;
     104              : };
     105              : #endif // _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGEFROMALLMACRO2MD_H_
        

Generated by: LCOV version 2.0-1