21 #ifndef __XML_MESH_VALUE_COLLECTION_H 22 #define __XML_MESH_VALUE_COLLECTION_H 25 #include <dolfin/mesh/MeshValueCollection.h> 26 #include "pugixml.hpp" 42 const std::string type,
43 const pugi::xml_node xml_node);
48 const std::string type,
49 pugi::xml_node xml_node);
57 const std::string type,
58 const pugi::xml_node xml_node)
61 const pugi::xml_node mvc_node
62 = xmlutils::get_node(xml_node,
"mesh_value_collection");
63 dolfin_assert(mvc_node);
66 const std::string name = mvc_node.attribute(
"name").value();
67 const std::string type_file = mvc_node.attribute(
"type").value();
68 const std::size_t dim = mvc_node.attribute(
"dim").as_uint();
71 mesh_value_collection.
rename(name,
"a mesh value collection");
74 mesh_value_collection.
init(dim);
77 if (type != type_file)
80 "read mesh value collection from XML file",
81 "Type mismatch, found \"%s\" but expecting \"%s\"",
82 type_file.c_str(), type.c_str());
86 mesh_value_collection.
clear();
91 pugi::xml_node_iterator it;
92 for (it = mvc_node.begin(); it != mvc_node.end(); ++it)
94 const std::size_t cell_index = it->attribute(
"cell_index").as_uint();
95 const std::size_t local_entity
96 = it->attribute(
"local_entity").as_uint();
97 const std::size_t value = it->attribute(
"value").as_uint();
98 mesh_value_collection.
set_value(cell_index, local_entity, value);
101 else if (type ==
"int")
103 pugi::xml_node_iterator it;
104 for (it = mvc_node.begin(); it != mvc_node.end(); ++it)
106 const std::size_t cell_index = it->attribute(
"cell_index").as_uint();
107 const std::size_t local_entity
108 = it->attribute(
"local_entity").as_uint();
109 const int value = it->attribute(
"value").as_int();
110 mesh_value_collection.
set_value(cell_index, local_entity, value);
113 else if (type ==
"double")
115 pugi::xml_node_iterator it;
116 for (it = mvc_node.begin(); it != mvc_node.end(); ++it)
118 const std::size_t cell_index = it->attribute(
"cell_index").as_uint();
119 const std::size_t local_entity
120 = it->attribute(
"local_entity").as_uint();
121 const double value = it->attribute(
"value").as_double();
122 mesh_value_collection.
set_value(cell_index, local_entity, value);
125 else if (type ==
"bool")
127 pugi::xml_node_iterator it;
128 for (it = mvc_node.begin(); it != mvc_node.end(); ++it)
130 const std::size_t cell_index = it->attribute(
"cell_index").as_uint();
131 const std::size_t local_entity
132 = it->attribute(
"local_entity").as_uint();
133 const bool value = it->attribute(
"value").as_bool();
134 mesh_value_collection.
set_value(cell_index, local_entity, value);
140 "read mesh value collection from XML file",
141 "Unhandled value type \"%s\"", type.c_str());
147 mesh_value_collection,
148 const std::string type,
149 pugi::xml_node xml_node)
154 pugi::xml_node mf_node = xml_node.append_child(
"mesh_value_collection");
155 mf_node.append_attribute(
"name") = mesh_value_collection.
name().c_str();
156 mf_node.append_attribute(
"type") = type.c_str();
157 mf_node.append_attribute(
"dim")
158 = (
unsigned int)mesh_value_collection.
dim();
159 mf_node.append_attribute(
"size")
160 = (
unsigned int) mesh_value_collection.
size();
163 const std::map<std::pair<std::size_t, std::size_t>, T>&
164 values = mesh_value_collection.
values();
165 typename std::map<std::pair<std::size_t,
166 std::size_t>, T>::const_iterator it;
167 for (it = values.begin(); it != values.end(); ++it)
169 pugi::xml_node entity_node = mf_node.append_child(
"value");
170 entity_node.append_attribute(
"cell_index")
171 = (
unsigned int) it->first.first;
172 entity_node.append_attribute(
"local_entity")
173 = (
unsigned int) it->first.second;
174 entity_node.append_attribute(
"value")
175 = std::to_string(it->second).c_str();
I/O of XML representation of a MeshValueCollection.
Definition: XMLMeshValueCollection.h:35
std::map< std::pair< std::size_t, std::size_t >, T > & values()
Definition: MeshValueCollection.h:521
static void write(const MeshValueCollection< T > &mesh_value_collection, const std::string type, pugi::xml_node xml_node)
Write mesh value collection to XML file.
Definition: XMLMeshValueCollection.h:146
std::string name() const
Return name.
Definition: Variable.cpp:71
void clear()
Clear all values.
Definition: MeshValueCollection.h:534
void rename(const std::string name, const std::string label)
Rename variable.
Definition: Variable.cpp:65
std::size_t size() const
Definition: MeshValueCollection.h:402
bool set_value(std::size_t cell_index, std::size_t local_entity, const T &value)
Definition: MeshValueCollection.h:415
std::size_t dim() const
Definition: MeshValueCollection.h:389
void init(std::shared_ptr< const Mesh > mesh, std::size_t dim)
Definition: MeshValueCollection.h:371
static void read(MeshValueCollection< T > &mesh_value_collection, const std::string type, const pugi::xml_node xml_node)
Read mesh value collection from XML file.
Definition: XMLMeshValueCollection.h:56
Definition: GenericFile.h:38
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
void not_working_in_parallel(std::string what)
Definition: log.cpp:205