preCICE v3.2.0
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 of the mesh.");
29 tagVector.addAttribute(attrName);
30 tagVector.addAttribute(attrDegree);
31 parent.addSubtag(tagVector);
32}
33
36{
37 return _data;
38}
39
47
49 const xml::ConfigurationContext &context,
50 xml::XMLTag &tag)
51{
52 if (tag.getNamespace() == TAG) {
54
55 Data::typeName typeName;
56 if (tag.getName() == "scalar") {
57 typeName = Data::typeName::SCALAR;
58 } else if (tag.getName() == "vector") {
59 typeName = Data::typeName::VECTOR;
60 } else {
61 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());
62 };
63
64 const int waveformDegree = tag.getIntAttributeValue(ATTR_DEGREE);
66 "You tried to configure the data with name \"{}\" to use the waveform-degree=\"{}\", but the degree must be at least \"{}\".", name, waveformDegree, time::Time::MIN_WAVEFORM_DEGREE);
67 addData(name, typeName, waveformDegree);
68 } else {
69 PRECICE_ASSERT(false, "Received callback from an unknown tag.", tag.getName());
70 }
71}
72
78
80 const std::string &name,
81 const Data::typeName typeName,
82 int waveformDegree)
83{
84 // Check if data with same name has been added already
85 for (auto &elem : _data) {
86 PRECICE_CHECK(elem.name != name,
87 "Data \"{0}\" has already been defined. Please rename or remove one of the data tags with name=\"{0}\".",
88 name);
89 }
90
91 _data.emplace_back(name, typeName, waveformDegree);
92}
93
94} // namespace precice::mesh
#define PRECICE_ERROR(...)
Definition LogMacros.hpp:16
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:32
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
void addData(const std::string &name, const Data::typeName typeName, int waveformDegree=time::Time::DEFAULT_WAVEFORM_DEGREE)
Adds data manually.
void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag) override
Callback at begin of XML tag.
ConfiguredData getRecentlyConfiguredData() const
const std::vector< ConfiguredData > & data() const
std::vector< ConfiguredData > _data
void xmlEndTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag) override
Callback at end of XML tag and at end of subtag.
static const int DEFAULT_WAVEFORM_DEGREE
To be used, when the interpolation degree is not defined.
Definition Time.hpp:8
static const int MIN_WAVEFORM_DEGREE
The minimum required interpolation degree.
Definition Time.hpp:11
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:28
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:145
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:131
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.
contains the XML configuration parser.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:21