-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
DataConfiguration.cpp
101 lines (87 loc) · 3.01 KB
/
DataConfiguration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "DataConfiguration.hpp"
#include <ostream>
#include "logging/LogMacros.hpp"
#include "utils/assertion.hpp"
#include "xml/ConfigParser.hpp"
#include "xml/XMLAttribute.hpp"
namespace precice {
namespace mesh {
DataConfiguration::DataConfiguration(xml::XMLTag &parent)
{
using namespace xml;
auto attrName = XMLAttribute<std::string>(ATTR_NAME)
.setDocumentation("Unique name for the data set.");
XMLTag tagScalar(*this, VALUE_SCALAR, XMLTag::OCCUR_ARBITRARY, TAG);
tagScalar.setDocumentation("Defines a scalar data set to be assigned to meshes.");
tagScalar.addAttribute(attrName);
parent.addSubtag(tagScalar);
XMLTag tagVector(*this, VALUE_VECTOR, XMLTag::OCCUR_ARBITRARY, TAG);
tagVector.setDocumentation("Defines a vector data set to be assigned to meshes. The number of "
"components of each data entry depends on the spatial dimensions set "
"in tag <solver-interface>.");
tagVector.addAttribute(attrName);
parent.addSubtag(tagVector);
}
void DataConfiguration::setDimensions(
int dimensions)
{
PRECICE_TRACE(dimensions);
PRECICE_ASSERT((dimensions == 2) || (dimensions == 3), dimensions);
_dimensions = dimensions;
}
const std::vector<DataConfiguration::ConfiguredData> &
DataConfiguration::data() const
{
return _data;
}
DataConfiguration::ConfiguredData DataConfiguration::getRecentlyConfiguredData() const
{
PRECICE_ASSERT(_data.size() > 0);
PRECICE_ASSERT(_indexLastConfigured >= 0);
PRECICE_ASSERT(_indexLastConfigured < (int) _data.size());
return _data[_indexLastConfigured];
}
void DataConfiguration::xmlTagCallback(
const xml::ConfigurationContext &context,
xml::XMLTag & tag)
{
if (tag.getNamespace() == TAG) {
PRECICE_ASSERT(_dimensions != 0);
const std::string &name = tag.getStringAttributeValue(ATTR_NAME);
const std::string &typeName = tag.getName();
int dataDimensions = getDataDimensions(typeName);
addData(name, dataDimensions);
} else {
PRECICE_ASSERT(false, "Received callback from an unknown tag.", tag.getName());
}
}
void DataConfiguration::xmlEndTagCallback(
const xml::ConfigurationContext &context,
xml::XMLTag & tag)
{
}
void DataConfiguration::addData(
const std::string &name,
int dataDimensions)
{
// Check if data with same name has been added already
for (auto &elem : _data) {
PRECICE_CHECK(elem.name != name,
"Data \"{0}\" has already been defined. Please rename or remove one of the data tags with name=\"{0}\".",
name);
}
_data.push_back({name, dataDimensions});
}
int DataConfiguration::getDataDimensions(
const std::string &typeName) const
{
if (typeName == VALUE_VECTOR) {
return _dimensions;
} else if (typeName == VALUE_SCALAR) {
return 1;
}
// We should never reach this point
PRECICE_UNREACHABLE("Unknown data type \"{}\".", typeName);
}
} // namespace mesh
} // namespace precice