55 bool keepOriginalElementIndexing)
57 assert(keepOriginalElementIndexing);
65 unsigned num_chunks = 1;
66 if (mesh_is_distributed)
70 WriteXdmfMasterFile(num_chunks);
80 std::stringstream local_geometry_file_name;
82 out_stream geometry_file = this->mpOutputFileHandler->OpenOutputFile(local_geometry_file_name.str());
83 std::string geom_type =
"XYZ";
88 (*geometry_file) <<
"<Geometry GeometryType=\""<< geom_type <<
"\">\n";
90 if (this->mpDistributedMesh)
92 num_nodes = this->mpDistributedMesh->GetNumLocalNodes() + this->mpDistributedMesh->GetNumHaloNodes();
95 (*geometry_file) <<
"\t<DataItem Format=\"XML\" Dimensions=\""<< num_nodes <<
" "<< SPACE_DIM <<
"\" DataType=\"Float\">";
98 std::map<unsigned, unsigned> global_to_node_index_map;
108 global_to_node_index_map[iter->GetIndex()] = index;
110 (*geometry_file) <<
"\n\t\t";
111 c_vector<double, SPACE_DIM> current_item = (iter)->rGetLocation();
112 for (
unsigned j=0; j<SPACE_DIM; j++)
114 (*geometry_file) << current_item[j] <<
"\t";
119 if (this->mpDistributedMesh)
122 halo_iter != this->mpDistributedMesh->GetHaloNodeIteratorEnd();
125 global_to_node_index_map[(*halo_iter)->GetIndex()] = index;
127 (*geometry_file) <<
"\n\t\t";
128 c_vector<double, SPACE_DIM> current_item = (*halo_iter)->rGetLocation();
129 for (
unsigned j=0; j<SPACE_DIM; j++)
131 (*geometry_file) << current_item[j] <<
"\t";
135 (*geometry_file) <<
"\n";
137 (*geometry_file) <<
"\t</DataItem>\n";
138 (*geometry_file) <<
"</Geometry>\n";
140 geometry_file->close();
143 std::stringstream local_topology_file_name;
145 out_stream topology_file = this->mpOutputFileHandler->OpenOutputFile(local_topology_file_name.str());
146 std::string top_type =
"Tetrahedron";
149 top_type =
"Triangle";
152 if (this->mpDistributedMesh)
154 num_elems = this->mpDistributedMesh->GetNumLocalElements();
156 (*topology_file) <<
"<Topology TopologyType=\""<< top_type <<
"\" NumberOfElements=\""<< num_elems <<
"\">\n";
157 (*topology_file) <<
"\t<DataItem Format=\"XML\" Dimensions=\""<< num_elems <<
" "<< ELEMENT_DIM+1 <<
"\">";
162 (*topology_file) <<
"\n\t\t";
163 for (
unsigned j=0; j<ELEMENT_DIM+1; j++)
165 unsigned local_index = global_to_node_index_map[ elem_iter->GetNodeGlobalIndex(j) ];
166 (*topology_file) << local_index <<
"\t";
169 (*topology_file) <<
"\n";
171 (*topology_file) <<
"\t</DataItem>\n";
172 (*topology_file) <<
"</Topology>\n";
174 topology_file->close();
243 XERCES_CPP_NAMESPACE_USE
246 XMLPlatformUtils::Initialize();
248 DOMImplementation* p_DOM_implementation = DOMImplementationRegistry::getDOMImplementation(X(
"core"));
250 DOMDocumentType* p_DOM_document_type = p_DOM_implementation->createDocumentType(X(
"Xdmf"),
nullptr,X(
"Xdmf.dtd"));
251 DOMDocument* p_DOM_document = p_DOM_implementation->createDocument(
nullptr, X(
"Xdmf"), p_DOM_document_type);
252 DOMElement* p_root_element = p_DOM_document->getDocumentElement();
253 p_root_element->setAttribute(X(
"Version"), X(
"2.0"));
254 p_root_element->setAttribute(X(
"xmlns:xi"), X(
"http://www.w3.org/2001/XInclude"));
256 DOMElement* p_domain_element = p_DOM_document->createElement(X(
"Domain"));
257 p_root_element->appendChild(p_domain_element);
260 DOMElement* p_grid_temp_collection_element = p_DOM_document->createElement(X(
"Grid"));
261 p_grid_temp_collection_element->setAttribute(X(
"CollectionType"), X(
"Temporal"));
262 p_grid_temp_collection_element->setAttribute(X(
"GridType"), X(
"Collection"));
263 p_domain_element->appendChild(p_grid_temp_collection_element);
266 DOMElement* p_time_element = p_DOM_document->createElement(X(
"Time"));
267 p_time_element->setAttribute(X(
"TimeType"), X(
"HyperSlab"));
268 p_grid_temp_collection_element->appendChild(p_time_element);
270 DOMElement* p_time_dataitem_element = p_DOM_document->createElement(X(
"DataItem"));
271 p_time_dataitem_element->setAttribute(X(
"Format"),X(
"XML"));
272 p_time_dataitem_element->setAttribute(X(
"NumberType"),X(
"Float"));
273 p_time_dataitem_element->setAttribute(X(
"Dimensions"),X(
"3"));
274 p_time_element->appendChild(p_time_dataitem_element);
276 std::stringstream time_stream;
277 time_stream <<
"0.0 " << mTimeStep <<
" " << mNumberOfTimePoints;
278 DOMText* p_time_text = p_DOM_document->createTextNode(X(time_stream.str()));
279 p_time_dataitem_element->appendChild(p_time_text);
281 for (
unsigned t=0; t<mNumberOfTimePoints; ++t)
283 DOMElement* p_grid_collection_element = p_DOM_document->createElement(X(
"Grid"));
284 p_grid_collection_element->setAttribute(X(
"CollectionType"), X(
"Spatial"));
285 p_grid_collection_element->setAttribute(X(
"GridType"), X(
"Collection"));
287 p_grid_temp_collection_element->appendChild(p_grid_collection_element);
291 for (
unsigned chunk=0; chunk<numberOfChunks; chunk++)
293 std::stringstream chunk_stream;
294 chunk_stream << chunk;
296 DOMElement* p_grid_element = p_DOM_document->createElement(X(
"Grid"));
297 p_grid_element->setAttribute(X(
"GridType"), X(
"Uniform"));
298 p_grid_element->setAttribute(X(
"Name"), X(
"Chunk_" + chunk_stream.str()));
299 p_grid_collection_element->appendChild(p_grid_element);
303 DOMElement* p_geom_element = p_DOM_document->createElement(X(
"xi:include"));
304 p_geom_element->setAttribute(X(
"href"), X(this->mBaseName+
"_geometry_"+chunk_stream.str()+
".xml"));
305 p_grid_element->appendChild(p_geom_element);
308 DOMElement* p_topo_element = p_DOM_document->createElement(X(
"xi:include"));
309 p_topo_element->setAttribute(X(
"href"), X(this->mBaseName+
"_topology_"+chunk_stream.str()+
".xml"));
310 p_grid_element->appendChild(p_topo_element);
316 AddDataOnNodes(p_grid_element, p_DOM_document, t);
321 for (
unsigned chunk=0; chunk<numberOfChunks; chunk++)
323 std::stringstream chunk_stream;
324 chunk_stream << chunk;
326 DOMElement* p_grid_element = p_DOM_document->createElement(X(
"Grid"));
327 p_grid_element->setAttribute(X(
"GridType"), X(
"Subset"));
328 p_grid_element->setAttribute(X(
"Section"), X(
"All"));
329 p_grid_collection_element->appendChild(p_grid_element);
335 AddDataOnNodes(p_grid_element, p_DOM_document, t);
336 DOMElement* p_grid_ref_element = p_DOM_document->createElement(X(
"Grid"));
337 p_grid_ref_element->setAttribute(X(
"GridType"), X(
"Uniform"));
338 p_grid_ref_element->setAttribute(X(
"Reference"), X(
"XML"));
341 DOMText* p_ref_text = p_DOM_document->createTextNode(X(
"/Xdmf/Domain/Grid/Grid/Grid[@Name=\"Chunk_"+chunk_stream.str()+
"\"]"));
342 p_grid_ref_element->appendChild(p_ref_text);
343 p_grid_element->appendChild(p_grid_ref_element);
349 p_DOM_document->appendChild(p_provenance_comment);
351 XMLFormatTarget* p_target =
new LocalFileFormatTarget(X(this->mpOutputFileHandler->GetOutputDirectoryFullPath() + this->mBaseName+
".xdmf"));
353#if _XERCES_VERSION >= 30000
354 DOMLSSerializer* p_serializer = ((DOMImplementationLS*)p_DOM_implementation)->createLSSerializer();
355 p_serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
356 DOMLSOutput* p_output = ((DOMImplementationLS*)p_DOM_implementation)->createLSOutput();
357 p_output->setByteStream(p_target);
358 p_serializer->write(p_DOM_document, p_output);
360 DOMWriter* p_serializer = ((DOMImplementationLS*)p_DOM_implementation)->createDOMWriter();
361 p_serializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
362 p_serializer->writeNode(p_target, *p_DOM_document);
366 p_serializer->release();
367 p_DOM_document->release();
368#if _XERCES_VERSION >= 30000
372 XMLPlatformUtils::Terminate();