preCICE v3.1.1
Loading...
Searching...
No Matches
Configuration.cpp
Go to the documentation of this file.
1#include "Configuration.hpp"
2#include <map>
3#include <memory>
4#include <ostream>
5#include <vector>
10#include "math/differences.hpp"
11#include "mesh/Mesh.hpp"
18#include "utils/assertion.hpp"
19#include "xml/ConfigParser.hpp"
20#include "xml/XMLAttribute.hpp"
21
22namespace precice::config {
23
25 : _tag(*this, "precice-configuration", xml::XMLTag::OCCUR_ONCE),
26 _logConfig(_tag), // This must be the first configuration to be constructed
27 _profilingConfig(_tag)
28{
29 _tag.setDocumentation("Main tag containing preCICE configuration.");
30 _tag.addNamespace("data");
31 _tag.addNamespace("communication");
32 _tag.addNamespace("mapping");
33 _tag.addNamespace("export");
34 _tag.addNamespace("action");
35 _tag.addNamespace("coupling-scheme");
36 _tag.addNamespace("acceleration");
37
38 auto attrExperimental = xml::makeXMLAttribute("experimental", false)
39 .setDocumentation("Enable experimental features.");
40 _tag.addAttribute(attrExperimental);
41
42 auto attrWaitInFinalize = xml::makeXMLAttribute("wait-in-finalize", false)
43 .setDocumentation("Connected participants wait for each other in finalize, which can be helpful in SLURM sessions.");
44 _tag.addAttribute(attrWaitInFinalize);
45 _dataConfiguration = std::make_shared<mesh::DataConfiguration>(
46 _tag);
47 _meshConfiguration = std::make_shared<mesh::MeshConfiguration>(
49 _m2nConfiguration = std::make_shared<m2n::M2NConfiguration>(
50 _tag);
51 _participantConfiguration = std::make_shared<ParticipantConfiguration>(
53 _couplingSchemeConfiguration = std::make_shared<cplscheme::CouplingSchemeConfiguration>(
55}
56
61
63{
65 if (tag.getName() == "precice-configuration") {
66 _experimental = tag.getBooleanAttributeValue("experimental");
68 _waitInFinalize = tag.getBooleanAttributeValue("wait-in-finalize");
69 } else {
70 PRECICE_UNREACHABLE("Received callback from unknown tag '{}'.", tag.getName());
71 }
72}
73
75 const xml::ConfigurationContext &context,
76 xml::XMLTag & tag)
77{
79 PRECICE_ASSERT(tag.getName() == "precice-configuration");
80
81 //test if both participants do have the exchange meshes
82 typedef std::map<std::string, std::vector<std::string>>::value_type neededMeshPair;
83 for (const neededMeshPair &neededMeshes : _meshConfiguration->getNeededMeshes()) {
84 bool participantFound = false;
85 for (const impl::PtrParticipant &participant : _participantConfiguration->getParticipants()) {
86 if (participant->getName() == neededMeshes.first) {
87 for (const std::string &neededMesh : neededMeshes.second) {
88 PRECICE_CHECK(participant->isMeshUsed(neededMesh),
89 "Participant \"{}\" needs to use the mesh \"{}\" to be able to use it in the coupling scheme. "
90 "Please either add a provide-mesh or a receive-mesh tag in this participant's configuration, or use a different mesh in the coupling scheme.",
91 neededMeshes.first, neededMesh);
92 }
93 participantFound = true;
94 break;
95 }
96 }
97 PRECICE_ASSERT(participantFound);
98 }
99
100 // test if all M2Ns use participants that exist
101 for (const auto &m2n : _m2nConfiguration->m2ns()) {
102 PRECICE_CHECK(_participantConfiguration->hasParticipant(m2n.acceptor),
103 "The acceptor in <m2n:... acceptor=\"{}\" connector=\"{}\" /> is an unknown. {}",
104 m2n.acceptor, m2n.connector, _participantConfiguration->hintFor(m2n.acceptor));
105
106 PRECICE_CHECK(_participantConfiguration->hasParticipant(m2n.connector),
107 "The connector in <m2n:... acceptor=\"{}\" connector=\"{}\" /> is an unknown. {}",
108 m2n.acceptor, m2n.connector, _participantConfiguration->hintFor(m2n.connector));
109 }
110}
111
117
118} // namespace precice::config
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:95
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:35
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
#define PRECICE_UNREACHABLE(...)
Definition assertion.hpp:95
const PtrParticipantConfiguration & getParticipantConfiguration() const
virtual void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &tag)
Callback function required for use of automatic configuration.
mesh::PtrMeshConfiguration _meshConfiguration
virtual void xmlEndTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &tag)
Callback function required for use of automatic configuration.
bool _experimental
Allow the use of experimental features.
m2n::M2NConfiguration::SharedPointer _m2nConfiguration
PtrParticipantConfiguration _participantConfiguration
xml::XMLTag & getXMLTag()
Returns root xml tag to start the automatic configuration process.
bool _waitInFinalize
Synchronize participants in finalize.
cplscheme::PtrCouplingSchemeConfiguration _couplingSchemeConfiguration
mesh::PtrDataConfiguration _dataConfiguration
XMLAttribute & setDocumentation(std::string documentation)
Sets a documentation string for the attribute.
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
bool getBooleanAttributeValue(const std::string &name, std::optional< bool > default_value=std::nullopt) const
Definition XMLTag.cpp:155
XMLTag & setDocumentation(const std::string &documentation)
Adds a description of the purpose of this XML tag.
Definition XMLTag.cpp:29
const std::string & getName() const
Returns name (without namespace).
Definition XMLTag.hpp:153
XMLTag & addNamespace(const std::string &namespaceName)
Adds a namespace to the tag.
Definition XMLTag.cpp:35
XMLTag & addAttribute(const XMLAttribute< double > &attribute)
Removes the XML subtag with given name.
Definition XMLTag.cpp:53
XMLAttribute< std::string > makeXMLAttribute(std::string name, const char *defaultValue)
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:24