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_MD2MACRO_H_ 6 : #define _MOLECULARDYNAMICS_COUPLING_SENDRECV_MD2MACRO_H_ 7 : 8 : #include "coupling/CouplingMDDefinitions.h" 9 : #include "coupling/datastructures/CellContainer.h" 10 : #include "coupling/datastructures/FlexibleCellContainer.h" 11 : #include "coupling/sendrecv/DataExchangeFromMD2Macro.h" 12 : #include "coupling/sendrecv/SendReceiveBuffer.h" 13 : #include <vector> 14 : 15 : namespace coupling { 16 : namespace sendrecv { 17 : template <class Cell_T, unsigned int dim> class FromMD2Macro; 18 : } 19 : } // namespace coupling 20 : 21 : /** extends the generic SendReceiveBuffer for send coupling cell information 22 : *from MaMiCo to the macroscopic solver. 23 : * @brief sends coupling cell information from MaMiCo to the macroscopic 24 : *solver. Derived from the class coupling::sendrecv::SendReceiveBuffer 25 : * @tparam Cell_T cell type 26 : * @tparam dim Number of dimensions; it can be 1, 2 or 3 27 : * @author Philipp Neumann 28 : */ 29 : template <class Cell_T, unsigned int dim> class coupling::sendrecv::FromMD2Macro : public coupling::sendrecv::SendReceiveBuffer<Cell_T, dim> { 30 : 31 : public: 32 : /** Constructor, just calling the constructor of the 33 : * coupling::sendrecv::SendReceiveBuffer */ 34 4 : FromMD2Macro() : coupling::sendrecv::SendReceiveBuffer<Cell_T, dim>() {} 35 : /** Destructor */ 36 0 : virtual ~FromMD2Macro() {} 37 : 38 : using Macro_Container_T = coupling::datastructures::FlexibleCellContainer<dim>; 39 : using Local_Container_T = coupling::datastructures::CellContainer<I02, dim>; 40 : 41 : /** sends information from the local coupling cells of MaMiCo (only inner 42 : * non-ghost cells of this process) to the macroscopic solver. Since the 43 : * macroscopic solver can have an arbitrary distribution of cells on the 44 : * processes, the buffer for receiving the cell data is provided to this 45 : * function in terms of an array of coupling cells including the respective 46 : * global cell indices. This function basically calls for these purposes 47 : * sendFromMD2MacroNonBlocking(...) and wait4SendFromMD2Macro(...) in a row. 48 : * @param dataExchange 49 : * @param src 50 : * @param dst 51 : */ 52 : void sendFromMD2Macro(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Local_Container_T& src, const Macro_Container_T& dst); 53 : 54 : /** reduces information from the local coupling cells of MaMiCo (only inner 55 : * non-ghost cells of this process) and sends it to the macroscopic solver. 56 : * @param dataExchange 57 : * @param src 58 : * @param dst 59 : */ 60 : template <class Container_T1, class Container_T2> 61 : void reduceFromMD2Macro(std::vector<coupling::sendrecv::DataExchangeFromMD2Macro<dim>*>& dataExchange, const Container_T1& src, const Container_T2& dst); 62 : 63 : /** triggers the send/recv operations for data transfer. After returning, 64 : * these data transfers do not necessarily need to be finished, according to 65 : * ISend/IRecv in MPI. 66 : * @param dataExchange 67 : * @param src 68 : * @param dst 69 : */ 70 : void sendFromMD2MacroNonBlocking(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Local_Container_T& src, const Macro_Container_T& dst); 71 : 72 : /** waits for the send operation--instantiated by 73 : * sendFromMD2MacroNonBlocking(...)--to be finished and writes the data to 74 : * couplingCellsFromMacroscopicSolver. 75 : * @param dataExchange 76 : * @param cells 77 : */ 78 : void wait4SendFromMD2Macro(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Macro_Container_T& cells); 79 : 80 : private: 81 : /** loops over the whole local Cartesian grid (only non-ghost cells!) and 82 : * writes respective cells to send buffer. For each cell, 83 : * writeToSendBuffer(...) of SendReceiveBuffer is used. 84 : * @param dataExchange 85 : * @param cells 86 : */ 87 : void writeToSendBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Local_Container_T& cells); 88 : 89 : /** loops over the whole local Cartesian grid (only non-ghost cells!) and 90 : * writes respective cells to reduce buffer. 91 : * @param dataExchange 92 : * @param cells 93 : */ 94 : void writeToReduceBuffer(coupling::sendrecv::DataExchangeFromMD2Macro<dim>& dataExchange, const Local_Container_T& cells); 95 : 96 : /** allocates the receive buffers for the macroscopic solver. Since we do not 97 : * know anything about the macroscopic solver, we only have a list of global 98 : * vector cell indices available for possible cells to be received on this 99 : * rank. For each global cell which is in the list, 100 : * allocateReceiveBuffers(...) of SendReceiveBuffer is called. 101 : * @param dataExchange 102 : * @param cells 103 : */ 104 : void allocateReceiveBuffers(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Macro_Container_T& cells); 105 : 106 : /** allocates the reduce receive buffers for the macroscopic solver. Since we do not 107 : * know anything about the macroscopic solver, we only have a list of global 108 : * vector cell indices available for possible cells to be received on this 109 : * rank. For each global cell which is in the list, 110 : * allocateReduceBufferForReceiving(...) of SendReceiveBuffer is called. 111 : * @param dataExchange 112 : * @param cells 113 : */ 114 : template <class Container_T> void allocateReduceBufferForReceiving(coupling::sendrecv::DataExchangeFromMD2Macro<dim>& dataExchange, const Container_T& cells); 115 : 116 : /** reads information from the receive buffer and stores the result in the 117 : * list of coupling cells. Since this is a receive for the coupling 118 : * cells on the side of the macroscopic solver, we just have a list of global 119 : * cell indices and corresponding coupling cell buffers. For each cell in 120 : * this list, readFromReceiveBuffer(...) of SendReceiveBuffer is called. 121 : * @param dataExchange 122 : * @param cells 123 : */ 124 : void readFromReceiveBuffer(coupling::sendrecv::DataExchange<Cell_T, dim>& dataExchange, const Macro_Container_T& cells); 125 : 126 : /** reads information from the reduce buffer and stores the result in the 127 : * list of coupling cells. Since this is a receive for the coupling 128 : * cells on the side of the macroscopic solver, we just have a list of global 129 : * cell indices and corresponding coupling cell buffers. For each cell in 130 : * this list, readFromReduceBuffer(...) of SendReceiveBuffer is called. 131 : * @param dataExchange 132 : * @param cells 133 : */ 134 : template <class Container_T> void readFromReduceBuffer(coupling::sendrecv::DataExchangeFromMD2Macro<dim>& dataExchange, const Container_T& cells); 135 : }; 136 : 137 : #include "FromMD2Macro.cpph" 138 : 139 : #endif // _MOLECULARDYNAMICS_COUPLING_SENDRECV_MD2MACRO_H_