preCICE v3.1.1
Loading...
Searching...
No Matches
DataConfiguration.cpp
Go to the documentation of this file.
2#include <ostream>
4#include "utils/assertion.hpp"
7
8namespace precice::mesh {
9
11{
12 using namespace xml;
13
14 auto attrName = XMLAttribute<std::string>(ATTR_NAME)
15 .setDocumentation("Unique name for the data set.");
16
17 auto attrDegree = makeXMLAttribute(ATTR_DEGREE, time::Time::DEFAULT_WAVEFORM_DEGREE);
18 attrDegree.setDocumentation("Polynomial degree of waveform that is used for time interpolation.");
19
20 XMLTag tagScalar(*this, VALUE_SCALAR, XMLTag::OCCUR_ARBITRARY, TAG);
21 tagScalar.setDocumentation("Defines a scalar data set to be assigned to meshes.");
22 tagScalar.addAttribute(attrName);
23 tagScalar.addAttribute(attrDegree);
24 parent.addSubtag(tagScalar);
25
26 XMLTag tagVector(*this, VALUE_VECTOR, XMLTag::OCCUR_ARBITRARY, TAG);
27 tagVector.setDocumentation("Defines a vector data set to be assigned to meshes. The number of "
28 "components of each data entry depends on the spatial dimensions set "
29 "in tag <precice-configuration>.");
30 tagVector.addAttribute(attrName);
31 tagVector.addAttribute(attrDegree);
32 parent.addSubtag(tagVector);
33}
34
37{
38 return _data;
39}
40
48
50 const xml::ConfigurationContext &context,
51 xml::XMLTag & tag)
52{
53 if (tag.getNamespace() == TAG) {
55
56 Data::typeName typeName;
57 if (tag.getName() == "scalar") {
58 typeName = Data::typeName::SCALAR;
59 } else if (tag.getName() == "vector") {
60 typeName = Data::typeName::VECTOR;
61 } else {
62 PRECICE_ERROR("You configured data with name=\"{}\" to be of type \"{}\", but this type is unknown. Known types are \"scalar\" and \"vector\".", name, tag.getName());
63 };
64
65 const int waveformDegree = tag.getIntAttributeValue(ATTR_DEGREE);
66 PRECICE_CHECK(!(waveformDegree < time::Time::MIN_WAVEFORM_DEGREE || waveformDegree > time::Time::MAX_WAVEFORM_DEGREE),
67 "You tried to configure the data with name \"{}\" to use the waveform-degree=\"{}\", but the degree must be between \"{}\" and \"{}\". Please use a degree in the allowed range.", name, waveformDegree, time::Time::MIN_WAVEFORM_DEGREE, time::Time::MAX_WAVEFORM_DEGREE);
68 addData(name, typeName, waveformDegree);
69 } else {
70 PRECICE_ASSERT(false, "Received callback from an unknown tag.", tag.getName());
71 }
72}
73
79
81 const std::string & name,
82 const Data::typeName typeName,
83 int waveformDegree)
84{
85 // Check if data with same name has been added already
86 for (auto &elem : _data) {
87 PRECICE_CHECK(elem.name != name,
88 "Data \"{0}\" has already been defined. Please rename or remove one of the data tags with name=\"{0}\".",
89 name);
90 }
91
92 _data.emplace_back(name, typeName, waveformDegree);
93}
94
95} // namespace precice::mesh
#define PRECICE_ERROR(...)
Definition LogMacros.hpp:15
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:35
std::string name
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
void addData(const std::string &name, const Data::typeName typeName, int waveformDegree=time::Time::DEFAULT_WAVEFORM_DEGREE)
Adds data manually.
ConfiguredData getRecentlyConfiguredData() const
virtual void xmlEndTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag)
Callback at end of XML tag and at end of subtag.
const std::vector< ConfiguredData > & data() const
std::vector< ConfiguredData > _data
virtual void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag)
Callback at begin of XML tag.
static const int DEFAULT_WAVEFORM_DEGREE
To be used, when the interpolation degree is not defined.
Definition Time.hpp:9
static const int MAX_WAVEFORM_DEGREE
The maximum allowed interpolation degree.
Definition Time.hpp:15
static const int MIN_WAVEFORM_DEGREE
The minimum required interpolation degree.
Definition Time.hpp:12
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
const std::string & getNamespace() const
Returns xml namespace.
Definition XMLTag.hpp:159
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
XMLTag & addSubtag(const XMLTag &tag)
Adds an XML tag as subtag by making a copy of the given tag.
Definition XMLTag.cpp:41
provides Mesh, Data and primitives.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:24