preCICE v3.1.2
Loading...
Searching...
No Matches
CommunicationConfiguration.cpp
Go to the documentation of this file.
2#include <memory>
3#include <ostream>
8#include "utils/Helpers.hpp"
9#include "utils/assertion.hpp"
10#include "xml/XMLTag.hpp"
11
12namespace precice::com {
14 const xml::XMLTag &tag) const
15{
17 if (tag.getName() == "sockets") {
18 std::string network = tag.getStringAttributeValue("network");
19 int port = tag.getIntAttributeValue("port");
20
22 "A sockets communication was configured with an invalid port \"{}\". "
23 "Please check the \"ports=\" attributes of your socket connections.",
24 port);
25
26 std::string dir = tag.getStringAttributeValue("exchange-directory");
27 com = std::make_shared<com::SocketCommunication>(port, false, network, dir);
28 } else if (tag.getName() == "mpi") {
29 std::string dir = tag.getStringAttributeValue("exchange-directory");
30#ifdef PRECICE_NO_MPI
31 PRECICE_ERROR("Communication type \"mpi\" can only be used if preCICE was compiled with MPI support enabled. "
32 "Either switch to a \"sockets\" communication or recompile preCICE with \"PRECICE_MPICommunication=ON\".");
33#else
34 com = std::make_shared<com::MPIPortsCommunication>(dir);
35#endif
36 }
37 PRECICE_ASSERT(com != nullptr);
38 return com;
39}
40
41} // namespace precice::com
#define PRECICE_ERROR(...)
Definition LogMacros.hpp:15
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:35
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
PtrCommunication createCommunication(const xml::XMLTag &tag) const
Returns a communication object of given type.
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
std::string getStringAttributeValue(const std::string &name, std::optional< std::string > default_value=std::nullopt) const
Definition XMLTag.cpp:142
const std::string & getName() const
Returns name (without namespace).
Definition XMLTag.hpp:153
int getIntAttributeValue(const std::string &name, std::optional< int > default_value=std::nullopt) const
Definition XMLTag.cpp:129
contains the data communication abstraction layer.
bool isValidPort(int port)
Returns true if the argument represents a valid port.
Definition Helpers.hpp:21