preCICE
Toggle main menu visibility
Loading...
Searching...
No Matches
src
com
config
CommunicationConfiguration.cpp
Go to the documentation of this file.
1
#include "
CommunicationConfiguration.hpp
"
2
#include <memory>
3
#include <ostream>
4
#include "
com/MPIDirectCommunication.hpp
"
5
#include "
com/MPIPortsCommunication.hpp
"
6
#include "
com/SocketCommunication.hpp
"
7
#include "
logging/LogMacros.hpp
"
8
#include "
utils/Helpers.hpp
"
9
#include "
utils/assertion.hpp
"
10
#include "
xml/XMLTag.hpp
"
11
12
namespace
precice::com
{
13
PtrCommunication
CommunicationConfiguration::createCommunication
(
14
const
xml::XMLTag
&tag)
const
15
{
16
com::PtrCommunication
com
;
17
if
(tag.
getName
() ==
"sockets"
) {
18
std::string network = tag.
getStringAttributeValue
(
"network"
);
19
int
port = tag.
getIntAttributeValue
(
"port"
);
20
21
PRECICE_CHECK
(
utils::isValidPort
(port),
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
CommunicationConfiguration.hpp
Helpers.hpp
LogMacros.hpp
PRECICE_ERROR
#define PRECICE_ERROR(...)
Definition
LogMacros.hpp:16
PRECICE_CHECK
#define PRECICE_CHECK(check,...)
Definition
LogMacros.hpp:32
MPIDirectCommunication.hpp
MPIPortsCommunication.hpp
SocketCommunication.hpp
XMLTag.hpp
assertion.hpp
PRECICE_ASSERT
#define PRECICE_ASSERT(...)
Definition
assertion.hpp:85
precice::com::CommunicationConfiguration::createCommunication
PtrCommunication createCommunication(const xml::XMLTag &tag) const
Returns a communication object of given type.
Definition
CommunicationConfiguration.cpp:13
precice::xml::XMLTag
Represents an XML tag to be configured automatically.
Definition
XMLTag.hpp:28
precice::xml::XMLTag::getStringAttributeValue
std::string getStringAttributeValue(const std::string &name, std::optional< std::string > default_value=std::nullopt) const
Definition
XMLTag.cpp:145
precice::xml::XMLTag::getName
const std::string & getName() const
Returns name (without namespace).
Definition
XMLTag.hpp:153
precice::xml::XMLTag::getIntAttributeValue
int getIntAttributeValue(const std::string &name, std::optional< int > default_value=std::nullopt) const
Definition
XMLTag.cpp:131
precice::com
contains the data communication abstraction layer.
Definition
Communication.cpp:12
precice::com::PtrCommunication
std::shared_ptr< Communication > PtrCommunication
Definition
SharedPointer.hpp:11
precice::utils::isValidPort
bool isValidPort(int port)
Returns true if the argument represents a valid port.
Definition
Helpers.hpp:20