MaMiCo 1.2
Loading...
Searching...
No Matches
DataExchangeFromMacro2MD.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_DATAEXCHANGEFROMMACRO2MD_H_
6#define _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGEFROMMACRO2MD_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 DataExchangeFromMacro2MD;
17}
18} // namespace coupling
19
35template <unsigned int dim>
36class coupling::sendrecv::DataExchangeFromMacro2MD : public coupling::sendrecv::DataExchange<coupling::datastructures::CouplingCell<dim>, dim> {
37
38public:
43 DataExchangeFromMacro2MD(coupling::interface::MacroscopicSolverInterface<dim>* interface, unsigned int topologyOffset, unsigned int tagoffset = 0)
44 : coupling::sendrecv::DataExchange<coupling::datastructures::CouplingCell<dim>, dim>(TAG_FROM_MACRO2MD + tagoffset), _msi(interface),
45 _topologyOffset(topologyOffset) {
46#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
47 std::cout << "DataExchangeFromMacro2MD initialised..." << std::endl;
48#endif
49 }
50
52
59 std::vector<unsigned int> getTargetRanks(I01 idx) override {
60 // if we need information on MD side, return the respective ranks via
61 if (I08::contains(idx) && !I12::contains(idx)) {
62 return IDXS.getRanksForGlobalIndex(idx, _topologyOffset);
63 // otherwise return empty vector
64 }
65 return std::vector<unsigned int>();
66 }
67
74 std::vector<unsigned int> getSourceRanks(I01 idx) override {
75 if (I08::contains(idx) && !I12::contains(idx)) { // Global, no ghost, no MD2Macro
76 return _msi->getSourceRanks(idx);
77 }
78 return std::vector<unsigned int>();
79 }
80
87 void readFromCell(double* const buffer, const coupling::datastructures::CouplingCell<dim>& cell) override {
88 buffer[0] = cell.getMicroscopicMass();
89 for (unsigned int d = 0; d < dim; d++) {
90 buffer[d + 1] = cell.getMicroscopicMomentum()[d];
91 }
92 }
93
98 void writeToCell(const double* const buffer, coupling::datastructures::CouplingCell<dim>& cell) override {
99 tarch::la::Vector<dim, double> microscopicMomentum(0.0);
100 for (unsigned int d = 0; d < dim; d++) {
101 microscopicMomentum[d] = buffer[1 + d];
102 }
103 cell.setMicroscopicMomentum(microscopicMomentum);
104 cell.setMicroscopicMass(buffer[0]);
105 }
106
109 unsigned int getDoublesPerCell() const override {
110 // 1 double: microscopic mass; dim doubles: microscopic momentum
111 return 1 + dim;
112 }
113
114private:
116 unsigned int _topologyOffset;
117};
118#endif // _MOLECULARDYNAMICS_COUPLING_SENDRECV_DATAEXCHANGEFROMMACRO2MD_H_
defines the cell type with cell-averaged quantities only (no linked cells).
Definition CouplingCell.h:29
const tarch::la::Vector< dim, double > & getMicroscopicMomentum() const
Definition CouplingCell.h:51
void setMicroscopicMass(const double &mass)
Definition CouplingCell.h:42
const double & getMicroscopicMass() const
Definition CouplingCell.h:45
void setMicroscopicMomentum(const tarch::la::Vector< dim, double > &momentum)
Definition CouplingCell.h:48
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 macroscopic solver to the MD solver. Derived from the class coupling::sendrecv...
Definition DataExchangeFromMacro2MD.h:36
std::vector< unsigned int > getSourceRanks(I01 idx) override
Definition DataExchangeFromMacro2MD.h:74
void readFromCell(double *const buffer, const coupling::datastructures::CouplingCell< dim > &cell) override
Definition DataExchangeFromMacro2MD.h:87
unsigned int getDoublesPerCell() const override
Definition DataExchangeFromMacro2MD.h:109
DataExchangeFromMacro2MD(coupling::interface::MacroscopicSolverInterface< dim > *interface, unsigned int topologyOffset, unsigned int tagoffset=0)
Definition DataExchangeFromMacro2MD.h:43
void writeToCell(const double *const buffer, coupling::datastructures::CouplingCell< dim > &cell) override
Definition DataExchangeFromMacro2MD.h:98
std::vector< unsigned int > getTargetRanks(I01 idx) override
Definition DataExchangeFromMacro2MD.h:59
virtual ~DataExchangeFromMacro2MD()
Definition DataExchangeFromMacro2MD.h:51
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