preCICE
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. Lower and upper bound of the data can be specified to prevent acceleration methods of IQN family violating the physical value range.");
22 tagScalar.addAttribute(attrName);
23 tagScalar.addAttribute(attrDegree);
24 auto attrLowerBound = XMLAttribute<double>(ATTR_LOWER_BOUND)
25 .setDefaultValue(-std::numeric_limits<double>::infinity())
26 .setDocumentation("Lower bound for the scalar data. Example is 0 for temperature in Kelvin.");
27 tagScalar.addAttribute(attrLowerBound);
28
29 auto attrUpperBound = XMLAttribute<double>(ATTR_UPPER_BOUND)
30 .setDefaultValue(std::numeric_limits<double>::infinity())
31 .setDocumentation("Upper bound for the scalar data. Example is 1 for volumetric phase fraction");
32 tagScalar.addAttribute(attrUpperBound);
33 parent.addSubtag(tagScalar);
34
35 XMLTag tagVector(*this, VALUE_VECTOR, XMLTag::OCCUR_ARBITRARY, TAG);
36 tagVector.setDocumentation("Defines a vector data set to be assigned to meshes. The number of "
37 "components of each data entry depends on the spatial dimensions of the mesh."
38 "Lower and upper bound for each component can be specified to prevent acceleration methods of IQN family violating the physical value range.");
39 tagVector.addAttribute(attrName);
40 tagVector.addAttribute(attrDegree);
41 auto attrLowerBoundX = XMLAttribute<double>(ATTR_LOWER_BOUND_X)
42 .setDefaultValue(-std::numeric_limits<double>::infinity())
43 .setDocumentation("Lower bound for the x-component of the vector data.");
44 tagVector.addAttribute(attrLowerBoundX);
45
46 auto attrLowerBoundY = XMLAttribute<double>(ATTR_LOWER_BOUND_Y)
47 .setDefaultValue(-std::numeric_limits<double>::infinity())
48 .setDocumentation("Lower bound for the y-component of the vector data.");
49 tagVector.addAttribute(attrLowerBoundY);
50
51 auto attrLowerBoundZ = XMLAttribute<double>(ATTR_LOWER_BOUND_Z)
52 .setDefaultValue(-std::numeric_limits<double>::infinity())
53 .setDocumentation("Lower bound for the z-component of the vector data.");
54 tagVector.addAttribute(attrLowerBoundZ);
55
56 auto attrUpperBoundX = XMLAttribute<double>(ATTR_UPPER_BOUND_X)
57 .setDefaultValue(std::numeric_limits<double>::infinity())
58 .setDocumentation("Upper bound for the x-component of the vector data.");
59 tagVector.addAttribute(attrUpperBoundX);
60
61 auto attrUpperBoundY = XMLAttribute<double>(ATTR_UPPER_BOUND_Y)
62 .setDefaultValue(std::numeric_limits<double>::infinity())
63 .setDocumentation("Upper bound for the y-component of the vector data.");
64 tagVector.addAttribute(attrUpperBoundY);
65
66 auto attrUpperBoundZ = XMLAttribute<double>(ATTR_UPPER_BOUND_Z)
67 .setDefaultValue(std::numeric_limits<double>::infinity())
68 .setDocumentation("Upper bound for the z-component of the vector data.");
69 tagVector.addAttribute(attrUpperBoundZ);
70 parent.addSubtag(tagVector);
71}
72
73const std::vector<DataConfiguration::ConfiguredData> &
75{
76 return _data;
77}
78
86
88 const xml::ConfigurationContext &context,
89 xml::XMLTag &tag)
90{
91 if (tag.getNamespace() == TAG) {
92 const std::string &name = tag.getStringAttributeValue(ATTR_NAME);
93
94 Data::typeName typeName;
95 if (tag.getName() == "scalar") {
96 typeName = Data::typeName::SCALAR;
97 } else if (tag.getName() == "vector") {
98 typeName = Data::typeName::VECTOR;
99 } else {
100 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());
101 };
102
103 const int waveformDegree = tag.getIntAttributeValue(ATTR_DEGREE);
105 "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);
106 if (tag.getName() == "scalar") {
107 const double lowerBound = tag.getDoubleAttributeValue(ATTR_LOWER_BOUND);
108 const double upperBound = tag.getDoubleAttributeValue(ATTR_UPPER_BOUND);
109
110 std::vector<std::optional<double>> lowerBoundVec(1);
111 std::vector<std::optional<double>> upperBoundVec(1);
112
113 std::isfinite(lowerBound) ? lowerBoundVec[0] = lowerBound : lowerBoundVec[0] = std::nullopt;
114 std::isfinite(upperBound) ? upperBoundVec[0] = upperBound : upperBoundVec[0] = std::nullopt;
115
116 PRECICE_CHECK(lowerBound <= upperBound,
117 "You tried to configure the data with name \"{}\" to have a lower-bound=\"{}\" that is larger than the upper-bound=\"{}\".",
118 name, lowerBound, upperBound);
119 addData(name, typeName, waveformDegree, lowerBoundVec, upperBoundVec);
120 } else if (tag.getName() == "vector") {
121 const double lowerBoundX = tag.getDoubleAttributeValue(ATTR_LOWER_BOUND_X);
122 const double lowerBoundY = tag.getDoubleAttributeValue(ATTR_LOWER_BOUND_Y);
123 const double lowerBoundZ = tag.getDoubleAttributeValue(ATTR_LOWER_BOUND_Z);
124 const double upperBoundX = tag.getDoubleAttributeValue(ATTR_UPPER_BOUND_X);
125 const double upperBoundY = tag.getDoubleAttributeValue(ATTR_UPPER_BOUND_Y);
126 const double upperBoundZ = tag.getDoubleAttributeValue(ATTR_UPPER_BOUND_Z);
127
128 std::vector<std::optional<double>> lowerBoundVec(3);
129 std::vector<std::optional<double>> upperBoundVec(3);
130
131 std::isfinite(lowerBoundX) ? lowerBoundVec[0] = lowerBoundX : lowerBoundVec[0] = std::nullopt;
132 std::isfinite(lowerBoundY) ? lowerBoundVec[1] = lowerBoundY : lowerBoundVec[1] = std::nullopt;
133 std::isfinite(lowerBoundZ) ? lowerBoundVec[2] = lowerBoundZ : lowerBoundVec[2] = std::nullopt;
134 std::isfinite(upperBoundX) ? upperBoundVec[0] = upperBoundX : upperBoundVec[0] = std::nullopt;
135 std::isfinite(upperBoundY) ? upperBoundVec[1] = upperBoundY : upperBoundVec[1] = std::nullopt;
136 std::isfinite(upperBoundZ) ? upperBoundVec[2] = upperBoundZ : upperBoundVec[2] = std::nullopt;
137
138 if (lowerBoundVec[0].has_value() && upperBoundVec[0].has_value()) {
139 PRECICE_CHECK(lowerBoundVec[0].value() <= upperBoundVec[0].value(),
140 "You tried to configure the data with name \"{}\" to have a lower-bound-x=\"{}\" that is larger than the upper-bound-x=\"{}\".",
141 name, lowerBoundVec[0].value(), upperBoundVec[0].value());
142 }
143 if (lowerBoundVec[1].has_value() && upperBoundVec[1].has_value()) {
144 PRECICE_CHECK(lowerBoundVec[1].value() <= upperBoundVec[1].value(),
145 "You tried to configure the data with name \"{}\" to have a lower-bound-y=\"{}\" that is larger than the upper-bound-y=\"{}\".",
146 name, lowerBoundVec[1].value(), upperBoundVec[1].value());
147 }
148 if (lowerBoundVec[2].has_value() && upperBoundVec[2].has_value()) {
149 PRECICE_CHECK(lowerBoundVec[2].value() <= upperBoundVec[2].value(),
150 "You tried to configure the data with name \"{}\" to have a lower-bound-z=\"{}\" that is larger than the upper-bound-z=\"{}\".",
151 name, lowerBoundVec[2].value(), upperBoundVec[2].value());
152 }
153
154 addData(name, typeName, waveformDegree, lowerBoundVec, upperBoundVec);
155 }
156 } else {
157 PRECICE_ASSERT(false, "Received callback from an unknown tag.", tag.getName());
158 }
159}
160
166
168 const std::string &name,
169 const Data::typeName typeName,
170 int waveformDegree,
171 std::vector<std::optional<double>> lowerBound,
172 std::vector<std::optional<double>> upperBound)
173{
174 // Check if data with same name has been added already
175 for (auto &elem : _data) {
176 PRECICE_CHECK(elem.name != name,
177 "Data \"{0}\" has already been defined. Please rename or remove one of the data tags with name=\"{0}\".",
178 name);
179 }
180 _data.emplace_back(name, typeName, waveformDegree, lowerBound, upperBound);
181}
182
183} // 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 xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag) override
Callback at begin of XML tag.
void addData(const std::string &name, const Data::typeName typeName, int waveformDegree=time::Time::DEFAULT_WAVEFORM_DEGREE, std::vector< std::optional< double > > lowerBound=std::vector< std::optional< double > >(3), std::vector< std::optional< double > > upperBound=std::vector< std::optional< double > >(3))
Adds data manually.
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
double getDoubleAttributeValue(const std::string &name, std::optional< double > default_value=std::nullopt) const
Definition XMLTag.cpp:117
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