preCICE v3.1.2
Loading...
Searching...
No Matches
BiCouplingScheme.cpp
Go to the documentation of this file.
1#include <algorithm>
2#include <map>
3#include <memory>
4#include <ostream>
5#include <type_traits>
6#include <utility>
7
12#include "logging/LogMacros.hpp"
13#include "m2n/M2N.hpp"
14#include "m2n/SharedPointer.hpp"
15#include "mesh/Data.hpp"
17#include "utils/Helpers.hpp"
18
19namespace precice::cplscheme {
20
22 double maxTime,
23 int maxTimeWindows,
24 double timeWindowSize,
25 std::string firstParticipant,
26 std::string secondParticipant,
27 const std::string & localParticipant,
28 m2n::PtrM2N m2n,
29 int minIterations,
30 int maxIterations,
31 CouplingMode cplMode,
33 : BaseCouplingScheme(maxTime, maxTimeWindows, timeWindowSize, localParticipant, minIterations, maxIterations, cplMode, dtMethod),
34 _m2n(std::move(m2n)),
35 _firstParticipant(std::move(firstParticipant)),
36 _secondParticipant(std::move(secondParticipant))
37{
39 "First participant and second participant must have different names.");
41 setDoesFirstStep(true);
43 setDoesFirstStep(false);
44 } else {
45 PRECICE_ERROR("Name of local participant \"{}\" does not match any participant specified for the coupling scheme.",
47 }
48}
49
51 const mesh::PtrData &data,
52 mesh::PtrMesh mesh,
53 bool requiresInitialization,
54 bool exchangeSubsteps)
55{
57 PtrCouplingData ptrCplData = addCouplingData(data, std::move(mesh), requiresInitialization, exchangeSubsteps, CouplingData::Direction::Send);
58
59 if (!utils::contained(data->getID(), _sendData)) {
60 PRECICE_ASSERT(_sendData.count(data->getID()) == 0, "Key already exists!");
61 _sendData.emplace(data->getID(), ptrCplData);
62 } else {
63 PRECICE_ERROR("Data \"{0}\" cannot be added twice for sending. Please remove any duplicate <exchange data=\"{0}\" .../> tags", data->getName());
64 }
65}
66
68 const mesh::PtrData &data,
69 mesh::PtrMesh mesh,
70 bool requiresInitialization,
71 bool exchangeSubsteps)
72{
74 PtrCouplingData ptrCplData = addCouplingData(data, std::move(mesh), requiresInitialization, exchangeSubsteps, CouplingData::Direction::Receive);
75
76 if (!utils::contained(data->getID(), _receiveData)) {
77 PRECICE_ASSERT(_receiveData.count(data->getID()) == 0, "Key already exists!");
78 _receiveData.emplace(data->getID(), ptrCplData);
79 } else {
80 PRECICE_ERROR("Data \"{0}\" cannot be added twice for receiving. Please remove any duplicate <exchange data=\"{0}\" ... /> tags", data->getName());
81 }
82}
83
89
91{
92 std::vector<std::string> partnerNames;
93 // Add non-local participant
94 if (doesFirstStep()) {
95 partnerNames.push_back(_secondParticipant);
96 } else {
97 partnerNames.push_back(_firstParticipant);
98 }
99 return partnerNames;
100}
101
106
111
113{
114 return _receiveData;
115}
116
118 DataID dataID)
119{
120 PRECICE_TRACE(dataID);
121 DataMap::iterator iter = _sendData.find(dataID);
122 if (iter != _sendData.end()) {
123 return &(*(iter->second));
124 }
125 return nullptr;
126}
127
129 DataID dataID)
130{
131 PRECICE_TRACE(dataID);
132 DataMap::iterator iter = _receiveData.find(dataID);
133 if (iter != _receiveData.end()) {
134 return &(*(iter->second));
135 }
136 return nullptr;
137}
138
140{
142 return _m2n;
143}
144
146{
147 // @todo check receiveData. Should only contain zero data!
149}
150
152{
153 return not getSendData().empty();
154}
155
157{
158 return getSendData(dataID) != nullptr;
159}
160
161} // namespace precice::cplscheme
#define PRECICE_ERROR(...)
Definition LogMacros.hpp:15
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:95
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
Abstract base class for standard coupling schemes.
void initializeWithZeroInitialData(const DataMap &receiveData)
Initializes storage in receiveData as zero.
void determineInitialReceive(DataMap &receiveData)
Sets _receivesInitializedData, if receiveData requires initialization.
void determineInitialSend(DataMap &sendData)
Sets _sendsInitializedData, if sendData requires initialization.
PtrCouplingData addCouplingData(const mesh::PtrData &data, mesh::PtrMesh mesh, bool requiresInitialization, bool exchangeSubsteps, CouplingData::Direction direction)
Adds CouplingData with given properties to this BaseCouplingScheme and returns a pointer to the Coupl...
std::string localParticipant() const override final
Returns the name of the local participant.
void setDoesFirstStep(bool doesFirstStep)
Setter for _doesFirstStep.
bool doesFirstStep() const
Getter for _doesFirstStep.
std::vector< std::string > getCouplingPartners() const override final
returns list of all coupling partners
std::string _secondParticipant
Second participant name.
DataMap & getSendData()
Returns all data to be sent.
DataMap _sendData
All send data as a map "data ID -> data".
std::string _firstParticipant
First participant name.
DataMap _receiveData
All receive data as a map "data ID -> data".
void initializeReceiveDataStorage() override final
Functions needed for initialize()
m2n::PtrM2N _m2n
Communication to the other coupling participant.
void addDataToReceive(const mesh::PtrData &data, mesh::PtrMesh mesh, bool requiresInitialization, bool exchangeSubsteps)
Adds data to be received on data exchange.
DataMap & getReceiveData()
Returns all data to be received.
BiCouplingScheme(double maxTime, int maxTimeWindows, double timeWindowSize, std::string firstParticipant, std::string secondParticipant, const std::string &localParticipant, m2n::PtrM2N m2n, int minIterations, int maxIterations, CouplingMode cplMode, constants::TimesteppingMethod dtMethod)
void addDataToSend(const mesh::PtrData &data, mesh::PtrMesh mesh, bool requiresInitialization, bool exchangeSubsteps)
Adds data to be sent on data exchange and possibly be modified during coupling iterations.
void determineInitialDataExchange() override
Determines which data is initialized and therefore has to be exchanged during initialize.
T count(T... args)
T emplace(T... args)
T empty(T... args)
T end(T... args)
T find(T... args)
contains implementations of coupling schemes for coupled simulations.
bool contained(const ELEMENT_T &element, const std::vector< ELEMENT_T > &vec)
Returns true, if given element is in vector, otherwise false.
Definition Helpers.hpp:39
int DataID
Definition Types.hpp:25
STL namespace.
T push_back(T... args)