LCOV - code coverage report
Current view: top level - coupling/sendrecv - FromMacro2MD.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 50.0 % 2 1
Test Date: 2026-08-21 15:14:06 Functions: 0.0 % 1 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_FROMMACRO2MD_H_
       6              : #define _MOLECULARDYNAMICS_COUPLING_SENDRECV_FROMMACRO2MD_H_
       7              : 
       8              : #include "coupling/sendrecv/DataExchangeFromMacro2MD.h"
       9              : #include "coupling/sendrecv/SendReceiveBuffer.h"
      10              : #include <vector>
      11              : 
      12              : namespace coupling {
      13              : namespace sendrecv {
      14              : template <class Cell_T, unsigned int dim> class FromMacro2MD;
      15              : }
      16              : } // namespace coupling
      17              : 
      18              : /** extends the generic SendReceiveBuffer for transfer of quantities from a
      19              :  *macroscopic solver to the coupling cells of the coupling tool (incl. ghost
      20              :  *cells).
      21              :  *      @brief SendReceiveBuffer for transfer of quantities from a macroscopic
      22              :  *solver to the coupling cells. Derived from the class
      23              :  *coupling::sendrecv::SendReceiveBuffer
      24              :  *      @tparam Cell_T cell type
      25              :  *      @tparam dim Number of dimensions; it can be 1, 2 or 3
      26              :  *  @author Philipp Neumann
      27              :  */
      28              : template <class Cell_T, unsigned int dim> class coupling::sendrecv::FromMacro2MD : public coupling::sendrecv::SendReceiveBuffer<Cell_T, dim> {
      29              : 
      30              : public:
      31              :   /** Constructor, just calling the constructor of the
      32              :    * coupling::sendrecv::SendReceiveBuffer  */
      33            4 :   FromMacro2MD() : coupling::sendrecv::SendReceiveBuffer<Cell_T, dim>() {}
      34              :   /** Destructor */
      35            0 :   virtual ~FromMacro2MD() {}
      36              : 
      37              :   using Local_Container_T = coupling::datastructures::CellContainer<I02, dim>;
      38              : 
      39              :   /** sends information from the local coupling cells of a macroscopic solver
      40              :    * to the coupling cells of MaMico (ghost cells are also allowed). Since
      41              :    * the macroscopic solver can have an arbitrary distribution of cells on the
      42              :    * processes, the buffer for sending the cell data is provided to this
      43              :    * function in terms of an array of coupling cells including the respective
      44              :    * global cell indices. This function calls sendFromMacro2MDNonBlocking(..)
      45              :    * and immediately subsequently wait4SendFromMacro2MD(...). Those two methods
      46              :    * may alternatively be used, e.g., for "non-blocking" communication.
      47              :    *    @param dataExchange
      48              :    *    @param dst
      49              :    *    @param src
      50              :    */
      51              :   template <class Container_T>
      52              :   void sendFromMacro2MD(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Local_Container_T& dst, const Container_T& src);
      53              : 
      54              :   template <class Container_T>
      55              :   void bcastFromMacro2MD(std::vector<coupling::sendrecv::DataExchangeFromMacro2MD<dim>*>& dataExchangeFromCouplingCellServices, const Container_T& src,
      56              :                          std::vector<Local_Container_T> dst);
      57              : 
      58              :   /** sends data from macro to MD. After returning, the data transfer may not be
      59              :    * completely finished, similar to a IRecv/ISend-call by MPI. Please use
      60              :    * wait4SendFromMacro2MD(...) to guarantee that the data transfer has been
      61              :    * finished.
      62              :    *    @param dataExchange
      63              :    *    @param cells
      64              :    */
      65              :   template <class Container_T> void sendFromMacro2MDNonBlocking(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Container_T& cells);
      66              : 
      67              :   /** waits for the data transfer--instantiated by
      68              :    * sendFromMacro2MDNonBlocking(..)--to be finished and fills the information
      69              :    * into the coupling cells from Mamico.
      70              :    *    @param dataExchange
      71              :    *    @param cells
      72              :    */
      73              :   void wait4SendFromMacro2MD(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Local_Container_T& cells);
      74              : 
      75              : private:
      76              :   /** given a coupling cell container (from the macroscopic solver), the data
      77              :    * from these cells are written to the send buffer.
      78              :    *    @param dataExchange
      79              :    *    @param cells
      80              :    *    @param globalCellIndices
      81              :    */
      82              :   template <class Container_T> void writeToSendBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Container_T& cells);
      83              : 
      84              :   template <class Container_T> void writeToSendBufferCollective(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Container_T& cells);
      85              : 
      86              :   /** allocates the receive buffers for the macroscopic solver. Since we want to
      87              :    * obtain data on the side of MaMiCo, we can just loop over all local
      88              :    * coupling cells of the coupling tool and call allocateReceiveBuffers(...)
      89              :    * of the SendReceiveBuffer for each respective cell.
      90              :    *    @param dataExchange
      91              :    */
      92              :   void allocateReceiveBuffers(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange);
      93              : 
      94              :   void allocateReceiveBuffersCollective(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange);
      95              : 
      96              :   /** reads information from the receive buffer and stores the result in the
      97              :    * coupling cells. Since this is a receive for the coupling cells on the
      98              :    * side of the coupling tool, we can consider a Cartesian grid topology for
      99              :    * the coupling cells. For each cell, readFromReceiveBuffer(...) of
     100              :    * SendReceiveBuffer is called.
     101              :    *    @param dataExchange
     102              :    *    @param cells
     103              :    */
     104              :   void readFromReceiveBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Local_Container_T& cells);
     105              : 
     106              :   void readFromCollectiveBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Local_Container_T& cells);
     107              : };
     108              : 
     109              : #include "FromMacro2MD.cpph"
     110              : 
     111              : #endif // _MOLECULARDYNAMICS_COUPLING_SENDRECV_FROMMACRO2MD_H_
        

Generated by: LCOV version 2.0-1