29 #include <boost/format.hpp> 30 #include "dolfin/common/Array.h" 31 #include "dolfin/log/log.h" 32 #include "pugixml.hpp" 54 static void read(std::vector<T>& x,
const pugi::xml_node xml_dolfin);
58 static void write(
const std::vector<T>& x,
const std::string type,
59 pugi::xml_node xml_node);
65 void XMLArray::read(std::vector<T>& x,
const pugi::xml_node xml_node)
68 const pugi::xml_node array = xml_node.child(
"array");
72 "read array from XML file",
73 "Unable to find <array> tag in XML file");
77 const std::size_t size = array.attribute(
"size").as_uint();
78 const std::string type = array.attribute(
"type").value();
82 "read array from XML file",
83 "XML I/O of Array objects only supported when the value type is 'double'");
89 for (pugi::xml_node_iterator it = array.begin(); it != array.end(); ++it)
91 const std::size_t index = it->attribute(
"index").as_uint();
92 const double value = it->attribute(
"value").as_double();
93 dolfin_assert(index < size);
94 indices[index] = index;
100 void XMLArray::write(
const std::vector<T>& x,
const std::string type,
101 pugi::xml_node xml_node)
104 pugi::xml_node array_node = xml_node.append_child(
"array");
107 const std::size_t size = x.
size();
108 array_node.append_attribute(
"type") = type.c_str();
109 array_node.append_attribute(
"size") = (
unsigned int) size;
112 for (std::size_t i = 0; i < size; ++i)
114 pugi::xml_node element_node = array_node.append_child(
"element");
115 element_node.append_attribute(
"index") = (
unsigned int) i;
118 element_node.append_attribute(
"value")
119 = boost::str(boost::format(
"%.15e") % x[i]).c_str();
std::size_t size() const
Return size of array.
Definition: Array.h:81
I/O of array data in XML format.
Definition: XMLArray.h:48
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129