preCICE
Loading...
Searching...
No Matches
CouplingSchemeConfiguration.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <string>
5#include <tuple>
6#include <vector>
7
14#include "logging/Logger.hpp"
20#include "xml/XMLTag.hpp"
21
22namespace precice::cplscheme {
25} // namespace precice::cplscheme
26
27// Forward declaration to friend the boost test struct
28namespace CplSchemeTests {
29namespace ParallelImplicitCouplingSchemeTests {
30struct testParseConfigurationWithRelaxation;
31}
32namespace SerialImplicitCouplingSchemeTests {
33struct testParseConfigurationWithRelaxation;
34}
35} // namespace CplSchemeTests
36
37// ----------------------------------------------------------- CLASS DEFINITION
38
39namespace precice::cplscheme {
41
44public:
54 xml::XMLTag &parent,
57 config::PtrParticipantConfiguration participantConfig);
58
59 void setRemeshing(bool allowed);
60
62 ~CouplingSchemeConfiguration() override = default;
63
65 bool hasCouplingScheme(const std::string &participantName) const;
66
68 const PtrCouplingScheme &getCouplingScheme(const std::string &participantName) const;
69
71 const std::string &getDataToExchange(int index) const;
72
74 void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag) override;
75
77 void xmlEndTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag) override;
78
80 void addCouplingScheme(const PtrCouplingScheme &cplScheme, const std::string &participantName);
81
82private:
83 bool _allowRemeshing = false;
84 mutable logging::Logger _log{"cplscheme::CouplingSchemeConfiguration"};
85
86 const std::string TAG;
87 const std::string TAG_PARTICIPANTS;
88 const std::string TAG_PARTICIPANT;
89 const std::string TAG_EXCHANGE;
90 const std::string TAG_MAX_TIME;
91 const std::string TAG_MAX_TIME_WINDOWS;
92 const std::string TAG_TIME_WINDOW_SIZE;
93 const std::string TAG_ABS_CONV_MEASURE;
94 const std::string TAG_ABS_OR_REL_CONV_MEASURE;
95 const std::string TAG_REL_CONV_MEASURE;
96 const std::string TAG_RES_REL_CONV_MEASURE;
97 const std::string TAG_MIN_ITERATIONS;
98 const std::string TAG_MAX_ITERATIONS;
99
100 const std::string ATTR_DATA;
101 const std::string ATTR_MESH;
102 const std::string ATTR_PARTICIPANT;
103 const std::string ATTR_INITIALIZE;
104 const std::string ATTR_EXCHANGE_SUBSTEPS;
105 const std::string ATTR_TYPE;
106 const std::string ATTR_FIRST;
107 const std::string ATTR_SECOND;
108 const std::string ATTR_VALUE;
109 const std::string ATTR_METHOD;
110 const std::string ATTR_LIMIT;
111 const std::string ATTR_ABS_LIMIT;
112 const std::string ATTR_REL_LIMIT;
113 const std::string ATTR_NAME;
114 const std::string ATTR_FROM;
115 const std::string ATTR_TO;
116 const std::string ATTR_SUFFICES;
117 const std::string ATTR_STRICT;
118 const std::string ATTR_CONTROL;
119
120 const std::string VALUE_SERIAL_EXPLICIT;
121 const std::string VALUE_PARALLEL_EXPLICIT;
122 const std::string VALUE_SERIAL_IMPLICIT;
123 const std::string VALUE_PARALLEL_IMPLICIT;
124 const std::string VALUE_MULTI;
125 const std::string VALUE_FIXED;
126 const std::string VALUE_FIRST_PARTICIPANT;
127
128 static const int DEFAULT_MIN_ITERATIONS;
129 static const int DEFAULT_MAX_ITERATIONS;
130
138
139 struct Config {
140 std::string type;
141 std::string name;
142 std::vector<std::string> participants;
143 std::string controller;
144 bool setController = false;
149
158 std::vector<Exchange> exchanges;
159 std::vector<ConvergenceMeasureDefintion> convergenceMeasureDefinitions;
162
163 bool hasExchange(const Exchange &totest) const
164 {
165 return std::any_of(exchanges.begin(), exchanges.end(), [&totest](const auto &ex) {
166 return ex.from == totest.from && ex.to == totest.to && ex.data->getName() == totest.data->getName() && ex.mesh->getName() == totest.mesh->getName();
167 });
168 }
170
172
174
176
178
180 std::map<std::string, PtrCouplingScheme> _couplingSchemes;
181
183 std::map<std::string, CompositionalCouplingScheme *> _couplingSchemeCompositions;
184
185 void addTypespecifcSubtags(const std::string &type, xml::XMLTag &tag);
186
187 void addTransientLimitTags(const std::string &type, xml::XMLTag &tag);
188
190
192
193 void addTagExchange(xml::XMLTag &tag, bool substepsDefault);
194
196
198
200
202
204
206
208
210
212 const std::string &dataName,
213 const std::string &meshName,
214 double limit,
215 bool suffices,
216 bool strict);
217
219 const std::string &dataName,
220 const std::string &meshName,
221 double absLimit,
222 double relLimit,
223 bool suffices,
224 bool strict);
225
227 const std::string &dataName,
228 const std::string &meshName,
229 double limit,
230 bool suffices,
231 bool strict);
232
234 const std::string &dataName,
235 const std::string &meshName,
236 double limit,
237 bool suffices,
238 bool strict);
239
241 const std::string &dataName,
242 const std::string &meshName) const;
243
245 int ID) const;
246
248 const std::string &accessor) const;
249
251 const std::string &accessor) const;
252
254 const std::string &accessor) const;
255
257 const std::string &accessor) const;
258
260 const std::string &accessor) const;
261
263 const std::string &method) const;
264
267 BiCouplingScheme &scheme,
268 const std::string &accessor) const;
269
275 MultiCouplingScheme &scheme,
276 const std::string &accessor) const;
277
279 DataID dataID, std::string_view participant) const;
280
282 DataID dataID, const std::string &first, const std::string &second) const;
283
285 BaseCouplingScheme *scheme,
286 const std::string &participant,
287 const std::vector<ConvergenceMeasureDefintion> &convergenceMeasureDefinitions) const;
288
290 BaseCouplingScheme *scheme,
291 const std::string &first,
292 const std::string &second) const;
293
295 BaseCouplingScheme *scheme,
296 const std::string &participant) const;
297
298 friend struct CplSchemeTests::ParallelImplicitCouplingSchemeTests::testParseConfigurationWithRelaxation; // For whitebox tests
299 friend struct CplSchemeTests::SerialImplicitCouplingSchemeTests::testParseConfigurationWithRelaxation; // For whitebox tests
300
312 void checkSubstepExchangeWaveformDegree(const Config::Exchange &exchange) const;
313
316
320 void checkIterationLimits() const;
321};
322} // namespace precice::cplscheme
Abstract base class for standard coupling schemes.
Abstract base class for coupling schemes with two participants.
Acts as one coupling scheme, but consists of several composed ones.
PtrCouplingScheme createSerialExplicitCouplingScheme(const std::string &accessor) const
void checkIterationLimits() const
Helper function to check iteration limits in conjunction with convergence measures.
const PtrCouplingScheme & getCouplingScheme(const std::string &participantName) const
Returns the configured coupling scheme.
precice::config::PtrParticipantConfiguration _participantConfig
void addMultiDataToBeExchanged(MultiCouplingScheme &scheme, const std::string &accessor) const
Adds configured exchange data to be sent or received to scheme. Only used specifically for MultiCoupl...
PtrCouplingScheme createSerialImplicitCouplingScheme(const std::string &accessor) const
~CouplingSchemeConfiguration() override=default
Destructor, empty.
void xmlEndTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag) override
Callback method required when using xml::XMLTag.
void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag) override
Callback method required when using xml::XMLTag.
void setSerialAcceleration(BaseCouplingScheme *scheme, const std::string &first, const std::string &second) const
void addResidualRelativeConvergenceMeasure(const std::string &dataName, const std::string &meshName, double limit, bool suffices, bool strict)
void addAbsoluteConvergenceMeasure(const std::string &dataName, const std::string &meshName, double limit, bool suffices, bool strict)
void addDataToBeExchanged(BiCouplingScheme &scheme, const std::string &accessor) const
Adds configured exchange data to be sent or received to scheme.
struct precice::cplscheme::CouplingSchemeConfiguration::Config _config
void checkSubstepExchangeWaveformDegree(const Config::Exchange &exchange) const
Helper function to check that waveform-degree and substep exchange are compatible.
constants::TimesteppingMethod getTimesteppingMethod(const std::string &method) const
void checkSerialImplicitAccelerationData(DataID dataID, const std::string &first, const std::string &second) const
acceleration::PtrAccelerationConfiguration _accelerationConfig
std::map< std::string, PtrCouplingScheme > _couplingSchemes
Map from participant name to coupling scheme (composition).
void checkIfDataIsExchanged(DataID dataID, std::string_view participant) const
CouplingSchemeConfiguration(xml::XMLTag &parent, mesh::PtrMeshConfiguration meshConfig, m2n::M2NConfiguration::SharedPointer m2nConfig, config::PtrParticipantConfiguration participantConfig)
Constructor.
void addTagExchange(xml::XMLTag &tag, bool substepsDefault)
void addTypespecifcSubtags(const std::string &type, xml::XMLTag &tag)
PtrCouplingScheme createMultiCouplingScheme(const std::string &accessor) const
void addCouplingScheme(const PtrCouplingScheme &cplScheme, const std::string &participantName)
Adds a manually configured coupling scheme for a participant.
bool hasCouplingScheme(const std::string &participantName) const
Check, if a coupling scheme is configured for a participant.
void updateConfigForImplicitCoupling()
Helper to update some configs which may have a different meaning in implicit coupling.
void addAbsoluteOrRelativeConvergenceMeasure(const std::string &dataName, const std::string &meshName, double absLimit, double relLimit, bool suffices, bool strict)
PtrCouplingScheme createParallelImplicitCouplingScheme(const std::string &accessor) const
PtrCouplingScheme createParallelExplicitCouplingScheme(const std::string &accessor) const
void addTransientLimitTags(const std::string &type, xml::XMLTag &tag)
const std::string & getDataToExchange(int index) const
Returns the name of one dataset exchanged in the coupling scheme.
void addRelativeConvergenceMeasure(const std::string &dataName, const std::string &meshName, double limit, bool suffices, bool strict)
std::map< std::string, CompositionalCouplingScheme * > _couplingSchemeCompositions
If a participant has more than one coupling scheme, a composition is created.
void addConvergenceMeasures(BaseCouplingScheme *scheme, const std::string &participant, const std::vector< ConvergenceMeasureDefintion > &convergenceMeasureDefinitions) const
void setParallelAcceleration(BaseCouplingScheme *scheme, const std::string &participant) const
static const double UNDEFINED_MAX_TIME
Does not define a time limit for the coupled simulation.
static const double UNDEFINED_TIME_WINDOW_SIZE
To be used, when the time window size is determined dynamically during the coupling.
static const int UNDEFINED_TIME_WINDOWS
Does not define limit on time windows for the coupled simulation.
A coupling scheme with multiple participants.
This class provides a lightweight logger.
Definition Logger.hpp:17
std::shared_ptr< M2NConfiguration > SharedPointer
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:28
vector< double > getData()
Definition mainA.cpp:19
std::shared_ptr< AccelerationConfiguration > PtrAccelerationConfiguration
std::shared_ptr< ParticipantConfiguration > PtrParticipantConfiguration
std::shared_ptr< ConvergenceMeasure > PtrConvergenceMeasure
contains implementations of coupling schemes for coupled simulations.
std::shared_ptr< CouplingScheme > PtrCouplingScheme
std::shared_ptr< Data > PtrData
std::shared_ptr< Mesh > PtrMesh
std::shared_ptr< MeshConfiguration > PtrMeshConfiguration
int DataID
Definition Types.hpp:25
std::vector< ConvergenceMeasureDefintion > convergenceMeasureDefinitions
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:21
Callback interface for configuration classes using XMLTag.
Definition XMLTag.hpp:46