MaMiCo 1.2
Loading...
Searching...
No Matches
DataExchangeFromMD2Macro.h
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_DATAEXCHANGEFROMMD2MACRO_H_
6#define _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGEFROMMD2MACRO_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
14namespace coupling {
15namespace sendrecv {
16template <unsigned int dim> class DataExchangeFromMD2Macro;
17}
18} // namespace coupling
19
35template <unsigned int dim>
36class coupling::sendrecv::DataExchangeFromMD2Macro : public coupling::sendrecv::DataExchange<coupling::datastructures::CouplingCell<dim>, dim> {
37
38public:
43 DataExchangeFromMD2Macro(coupling::interface::MacroscopicSolverInterface<dim>* interface, unsigned int topologyOffset, unsigned int tagoffset = 0)
44 : coupling::sendrecv::DataExchange<coupling::datastructures::CouplingCell<dim>, dim>(TAG_FROM_MD2MACRO + tagoffset), _msi(interface),
45 _topologyOffset(topologyOffset) {
46#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
47 std::cout << "DataExchangeFromMD2Macro initialised..." << std::endl;
48#endif
49 }
50
52
59 std::vector<unsigned int> getTargetRanks(I01 idx) override {
60 // if we need information on macroscopic solver side, return the respective
61 // ranks via interface
62 if (I12::contains(idx)) {
63 return _msi->getTargetRanks(idx);
64 // otherwise return empty vector
65 } else {
66 return std::vector<unsigned int>();
67 }
68 }
69
76 std::vector<unsigned int> getSourceRanks(I01 idx) override {
77 std::vector<unsigned int> sourceRanks;
78 if (I12::contains(idx)) {
79 sourceRanks.push_back(IDXS.getUniqueRankForCouplingCell(idx, _topologyOffset));
80 }
81 return sourceRanks;
82 }
83
90 void readFromCell(double* const buffer, const coupling::datastructures::CouplingCell<dim>& cell) override {
91 buffer[0] = cell.getMacroscopicMass();
92 for (unsigned int d = 0; d < dim; d++) {
93 buffer[d + 1] = cell.getMacroscopicMomentum()[d];
94 }
95 }
96
101 void writeToCell(const double* const buffer, coupling::datastructures::CouplingCell<dim>& cell) override {
102 tarch::la::Vector<dim, double> macroscopicMomentum(0.0);
103 for (unsigned int d = 0; d < dim; d++) {
104 macroscopicMomentum[d] = buffer[1 + d];
105 }
106 cell.setMacroscopicMomentum(macroscopicMomentum);
107 cell.setMacroscopicMass(buffer[0]);
108 }
109
112 unsigned int getDoublesPerCell() const override {
113 // 1 double: macroscopic mass; dim doubles: macroscopic momentum
114 return 1 + dim;
115 }
116
117private:
119 unsigned int _topologyOffset;
120};
121#endif // _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGEFROMMD2MACRO_H_
defines the cell type with cell-averaged quantities only (no linked cells).
Definition CouplingCell.h:29
const tarch::la::Vector< dim, double > & getMacroscopicMomentum() const
Definition CouplingCell.h:64
void setMacroscopicMomentum(const tarch::la::Vector< dim, double > &momentum)
Definition CouplingCell.h:61
const double & getMacroscopicMass() const
Definition CouplingCell.h:58
void setMacroscopicMass(const double &mass)
Definition CouplingCell.h:55
static bool contains(const coupling::indexing::BaseIndex< dim > &index)
Definition CellIndex.h:227
interface for the macroscopic, i.e. continuum solver
Definition MacroscopicSolverInterface.h:23
data exchange from the MD solver to the macroscopic solver. Derived from the class coupling::sendrecv...
Definition DataExchangeFromMD2Macro.h:36
virtual ~DataExchangeFromMD2Macro()
Definition DataExchangeFromMD2Macro.h:51
void writeToCell(const double *const buffer, coupling::datastructures::CouplingCell< dim > &cell) override
Definition DataExchangeFromMD2Macro.h:101
DataExchangeFromMD2Macro(coupling::interface::MacroscopicSolverInterface< dim > *interface, unsigned int topologyOffset, unsigned int tagoffset=0)
Definition DataExchangeFromMD2Macro.h:43
std::vector< unsigned int > getSourceRanks(I01 idx) override
Definition DataExchangeFromMD2Macro.h:76
void readFromCell(double *const buffer, const coupling::datastructures::CouplingCell< dim > &cell) override
Definition DataExchangeFromMD2Macro.h:90
unsigned int getDoublesPerCell() const override
Definition DataExchangeFromMD2Macro.h:112
std::vector< unsigned int > getTargetRanks(I01 idx) override
Definition DataExchangeFromMD2Macro.h:59
generic class for the the data exchange purposes.
Definition DataExchange.h:27
Definition Vector.h:24
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15