preCICE
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"
22#include "utils/assertion.hpp"
23#include "xml/ConfigParser.hpp"
24#include "xml/XMLAttribute.hpp"
25
26namespace precice::config {
27
29 : _tag(*this, "precice-configuration", xml::XMLTag::OCCUR_ONCE),
30 _logConfig(_tag), // This must be the first configuration to be constructed
32{
33 _tag.setDocumentation("Main tag containing preCICE configuration.");
34 _tag.addNamespace("data");
35 _tag.addNamespace("communication");
36 _tag.addNamespace("mapping");
37 _tag.addNamespace("export");
38 _tag.addNamespace("action");
39 _tag.addNamespace("coupling-scheme");
40 _tag.addNamespace("acceleration");
41
42 auto attrExperimental = xml::makeXMLAttribute("experimental", false)
43 .setDocumentation("Enable experimental features.");
44 _tag.addAttribute(attrExperimental);
45
46 auto attrRemeshing = xml::makeXMLAttribute("allow-remeshing", false)
47 .setDocumentation("Enable experimental remeshing feature, requires experimental to be true.");
48 _tag.addAttribute(attrRemeshing);
49
50 auto attrWaitInFinalize = xml::makeXMLAttribute("wait-in-finalize", false)
51 .setDocumentation("Connected participants wait for each other in finalize, which can be helpful in SLURM sessions.");
52 _tag.addAttribute(attrWaitInFinalize);
53 _dataConfiguration = std::make_shared<mesh::DataConfiguration>(
54 _tag);
55 _meshConfiguration = std::make_shared<mesh::MeshConfiguration>(
57 _m2nConfiguration = std::make_shared<m2n::M2NConfiguration>(
58 _tag);
59 _participantConfiguration = std::make_shared<ParticipantConfiguration>(
61 _couplingSchemeConfiguration = std::make_shared<cplscheme::CouplingSchemeConfiguration>(
63}
64
69
71{
73 if (tag.getName() == "precice-configuration") {
74 _experimental = tag.getBooleanAttributeValue("experimental");
75 _remeshing = tag.getBooleanAttributeValue("allow-remeshing");
76
77 PRECICE_CHECK(!_remeshing || _experimental, "Remeshing is considered an experimental feature. Please enable <precice-configuration experimental=\"1\" >.");
81 _waitInFinalize = tag.getBooleanAttributeValue("wait-in-finalize");
82 } else {
83 PRECICE_UNREACHABLE("Received callback from unknown tag '{}'.", tag.getName());
84 }
85}
86
88 const xml::ConfigurationContext &context,
89 xml::XMLTag &tag)
90{
92 PRECICE_ASSERT(tag.getName() == "precice-configuration");
93
94 // test if both participants do have the exchange meshes
95 typedef std::map<std::string, std::vector<std::string>>::value_type neededMeshPair;
96 for (const neededMeshPair &neededMeshes : _meshConfiguration->getNeededMeshes()) {
97 bool participantFound = false;
98 for (const impl::PtrParticipant &participant : _participantConfiguration->getParticipants()) {
99 if (participant->getName() == neededMeshes.first) {
100 for (const std::string &neededMesh : neededMeshes.second) {
101 PRECICE_CHECK(participant->isMeshUsed(neededMesh),
102 "Participant \"{}\" needs to use the mesh \"{}\" to be able to use it in the coupling scheme. "
103 "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.",
104 neededMeshes.first, neededMesh);
105 }
106 participantFound = true;
107 break;
108 }
109 }
110 PRECICE_ASSERT(participantFound);
111 }
112
113 // test if all M2Ns use participants that exist
114 for (const auto &m2n : _m2nConfiguration->m2ns()) {
115 PRECICE_CHECK(_participantConfiguration->hasParticipant(m2n.acceptor),
116 "The acceptor in <m2n:... acceptor=\"{}\" connector=\"{}\" /> is an unknown. {}",
117 m2n.acceptor, m2n.connector, _participantConfiguration->hintFor(m2n.acceptor));
118
119 PRECICE_CHECK(_participantConfiguration->hasParticipant(m2n.connector),
120 "The connector in <m2n:... acceptor=\"{}\" connector=\"{}\" /> is an unknown. {}",
121 m2n.acceptor, m2n.connector, _participantConfiguration->hintFor(m2n.connector));
122 }
123}
124
130
131std::map<std::string, m2n::BoundM2N> Configuration::getBoundM2NsFor(std::string_view participantName) const
132{
133 std::map<std::string, m2n::BoundM2N> result;
134
135 for (const auto &m2nConf : _m2nConfiguration->m2ns()) {
136 if (m2nConf.acceptor != participantName && m2nConf.connector != participantName) {
137 continue;
138 }
139
140 std::string comPartner("");
141 bool isRequesting;
142 if (m2nConf.acceptor == participantName) {
143 comPartner = m2nConf.connector;
144 isRequesting = true;
145 } else {
146 comPartner = m2nConf.acceptor;
147 isRequesting = false;
148 }
149
150 PRECICE_ASSERT(!comPartner.empty());
151 for (const impl::PtrParticipant &participant : _participantConfiguration->getParticipants()) {
152 if (participant->getName() == comPartner) {
153 PRECICE_ASSERT(not utils::contained(comPartner, result), comPartner);
154 PRECICE_ASSERT(m2nConf.m2n);
155
156 result[comPartner] = [&] {
157 m2n::BoundM2N bound;
158 bound.m2n = m2nConf.m2n;
159 bound.localName = participantName;
160 bound.remoteName = comPartner;
161 bound.isRequesting = isRequesting;
162 return bound;
163 }();
164 }
165 }
166 }
167 return result;
168}
169
170void Configuration::configurePartitionsFor(std::string_view participantName)
171{
173 PRECICE_ASSERT(_participantConfiguration->hasParticipant(participantName));
174
175 auto participant = _participantConfiguration->getParticipant(participantName);
176
177 // Iterate over provided mesh contexts
178 for (auto &context : participant->providedMeshContexts()) {
179 // Accessor provides mesh
180 context.partition = std::make_shared<partition::ProvidedPartition>(context.mesh);
181
182 for (auto &receiver : _participantConfiguration->getParticipants()) {
183 for (auto &receivedMeshContext : receiver->receivedMeshContexts()) {
184 if (receivedMeshContext.receiveMeshFrom == participantName && receivedMeshContext.mesh->getName() == context.mesh->getName()) {
185 // meshRequirement has to be copied from "from" to provide", since
186 // mapping are only defined at "provide"
187 if (receivedMeshContext.meshRequirement > context.meshRequirement) {
188 context.meshRequirement = receivedMeshContext.meshRequirement;
189 }
190
191 m2n::PtrM2N m2n = _m2nConfiguration->getM2N(receiver->getName(), std::string(participantName));
192 m2n->createDistributedCommunication(context.mesh);
193 context.partition->addM2N(m2n);
194 }
195 }
196 }
197 }
198
199 // Iterate over received mesh contexts
200 for (auto &receivedContext : participant->receivedMeshContexts()) {
201 // Accessor receives mesh
202 std::string receiver(participantName);
203 std::string provider(receivedContext.receiveMeshFrom);
204
205 PRECICE_DEBUG("Receiving mesh from {}", provider);
206
207 receivedContext.partition = std::make_shared<partition::ReceivedPartition>(receivedContext.mesh, receivedContext.geoFilter, receivedContext.safetyFactor, receivedContext.allowDirectAccess);
208
209 m2n::PtrM2N m2n = _m2nConfiguration->getM2N(receiver, provider);
210 m2n->createDistributedCommunication(receivedContext.mesh);
211 receivedContext.partition->addM2N(m2n);
212 for (const precice::impl::MappingContext &mappingContext : receivedContext.fromMappingContexts) {
213 receivedContext.partition->addFromMapping(mappingContext.mapping);
214 }
215 for (const precice::impl::MappingContext &mappingContext : receivedContext.toMappingContexts) {
216 receivedContext.partition->addToMapping(mappingContext.mapping);
217 }
218 }
219}
220
221} // namespace precice::config
#define PRECICE_DEBUG(...)
Definition LogMacros.hpp:61
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:92
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:32
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
#define PRECICE_UNREACHABLE(...)
Definition assertion.hpp:93
const PtrParticipantConfiguration & getParticipantConfiguration() const
void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &tag) override
Callback function required for use of automatic configuration.
mesh::PtrMeshConfiguration _meshConfiguration
logging::LogConfiguration _logConfig
bool _remeshing
Allow the use of experimental remeshing features.
std::map< std::string, m2n::BoundM2N > getBoundM2NsFor(std::string_view participant) const
precice::profiling::ProfilingConfiguration _profilingConfig
void configurePartitionsFor(std::string_view participantName)
bool _experimental
Allow the use of experimental features.
m2n::M2NConfiguration::SharedPointer _m2nConfiguration
PtrParticipantConfiguration _participantConfiguration
void xmlEndTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &tag) override
Callback function required for use of automatic configuration.
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
An M2N between participants with a configured direction.
Definition BoundM2N.hpp:12
std::string remoteName
Definition BoundM2N.hpp:31
std::string localName
Definition BoundM2N.hpp:30
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:28
bool getBooleanAttributeValue(const std::string &name, std::optional< bool > default_value=std::nullopt) const
Definition XMLTag.cpp:159
const std::string & getName() const
Returns name (without namespace).
Definition XMLTag.hpp:153
std::shared_ptr< ParticipantConfiguration > PtrParticipantConfiguration
std::shared_ptr< ParticipantState > PtrParticipant
contains the logic of the parallel communication between participants.
Definition BoundM2N.cpp:12
std::shared_ptr< M2N > PtrM2N
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:38
contains the XML configuration parser.
XMLAttribute< std::string > makeXMLAttribute(std::string name, const char *defaultValue)
Holds a data mapping and related information.
mapping::PtrMapping mapping
Data mapping.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:21