55 bool keepOriginalElementIndexing)
58 EXCEPTION(
"XDMF is not supported under Windows at present.");
60 assert(keepOriginalElementIndexing);
68 unsigned num_chunks = 1;
69 if (mesh_is_distributed)
73 WriteXdmfMasterFile(num_chunks);
83 std::stringstream local_geometry_file_name;
85 out_stream geometry_file = this->mpOutputFileHandler->OpenOutputFile(local_geometry_file_name.str());
86 std::string geom_type =
"XYZ";
91 (*geometry_file) <<
"<Geometry GeometryType=\""<< geom_type <<
"\">\n";
93 if (this->mpDistributedMesh)
95 num_nodes = this->mpDistributedMesh->GetNumLocalNodes() + this->mpDistributedMesh->GetNumHaloNodes();
98 (*geometry_file) <<
"\t<DataItem Format=\"XML\" Dimensions=\""<< num_nodes <<
" "<< SPACE_DIM <<
"\" DataType=\"Float\">";
101 std::map<unsigned, unsigned> global_to_node_index_map;
111 global_to_node_index_map[iter->GetIndex()] = index;
113 (*geometry_file) <<
"\n\t\t";
114 c_vector<double, SPACE_DIM> current_item = (iter)->rGetLocation();
115 for (
unsigned j=0; j<SPACE_DIM; j++)
117 (*geometry_file) << current_item[j] <<
"\t";
122 if (this->mpDistributedMesh)
125 halo_iter != this->mpDistributedMesh->GetHaloNodeIteratorEnd();
128 global_to_node_index_map[(*halo_iter)->GetIndex()] = index;
130 (*geometry_file) <<
"\n\t\t";
131 c_vector<double, SPACE_DIM> current_item = (*halo_iter)->rGetLocation();
132 for (
unsigned j=0; j<SPACE_DIM; j++)
134 (*geometry_file) << current_item[j] <<
"\t";
138 (*geometry_file) <<
"\n";
140 (*geometry_file) <<
"\t</DataItem>\n";
141 (*geometry_file) <<
"</Geometry>\n";
143 geometry_file->close();
146 std::stringstream local_topology_file_name;
148 out_stream topology_file = this->mpOutputFileHandler->OpenOutputFile(local_topology_file_name.str());
149 std::string top_type =
"Tetrahedron";
152 top_type =
"Triangle";
155 if (this->mpDistributedMesh)
157 num_elems = this->mpDistributedMesh->GetNumLocalElements();
159 (*topology_file) <<
"<Topology TopologyType=\""<< top_type <<
"\" NumberOfElements=\""<< num_elems <<
"\">\n";
160 (*topology_file) <<
"\t<DataItem Format=\"XML\" Dimensions=\""<< num_elems <<
" "<< ELEMENT_DIM+1 <<
"\">";
165 (*topology_file) <<
"\n\t\t";
166 for (
unsigned j=0; j<ELEMENT_DIM+1; j++)
168 unsigned local_index = global_to_node_index_map[ elem_iter->GetNodeGlobalIndex(j) ];
169 (*topology_file) << local_index <<
"\t";
172 (*topology_file) <<
"\n";
174 (*topology_file) <<
"\t</DataItem>\n";
175 (*topology_file) <<
"</Topology>\n";
177 topology_file->close();
252 XERCES_CPP_NAMESPACE_USE
255 XMLPlatformUtils::Initialize();
257 DOMImplementation* p_DOM_implementation = DOMImplementationRegistry::getDOMImplementation(X(
"core"));
259 DOMDocumentType* p_DOM_document_type = p_DOM_implementation->createDocumentType(X(
"Xdmf"),
nullptr,X(
"Xdmf.dtd"));
260 DOMDocument* p_DOM_document = p_DOM_implementation->createDocument(
nullptr, X(
"Xdmf"), p_DOM_document_type);
261 DOMElement* p_root_element = p_DOM_document->getDocumentElement();
262 p_root_element->setAttribute(X(
"Version"), X(
"2.0"));
263 p_root_element->setAttribute(X(
"xmlns:xi"), X(
"http://www.w3.org/2001/XInclude"));
265 DOMElement* p_domain_element = p_DOM_document->createElement(X(
"Domain"));
266 p_root_element->appendChild(p_domain_element);
269 DOMElement* p_grid_temp_collection_element = p_DOM_document->createElement(X(
"Grid"));
270 p_grid_temp_collection_element->setAttribute(X(
"CollectionType"), X(
"Temporal"));
271 p_grid_temp_collection_element->setAttribute(X(
"GridType"), X(
"Collection"));
272 p_domain_element->appendChild(p_grid_temp_collection_element);
275 DOMElement* p_time_element = p_DOM_document->createElement(X(
"Time"));
276 p_time_element->setAttribute(X(
"TimeType"), X(
"HyperSlab"));
277 p_grid_temp_collection_element->appendChild(p_time_element);
279 DOMElement* p_time_dataitem_element = p_DOM_document->createElement(X(
"DataItem"));
280 p_time_dataitem_element->setAttribute(X(
"Format"),X(
"XML"));
281 p_time_dataitem_element->setAttribute(X(
"NumberType"),X(
"Float"));
282 p_time_dataitem_element->setAttribute(X(
"Dimensions"),X(
"3"));
283 p_time_element->appendChild(p_time_dataitem_element);
285 std::stringstream time_stream;
286 time_stream <<
"0.0 " << mTimeStep <<
" " << mNumberOfTimePoints;
287 DOMText* p_time_text = p_DOM_document->createTextNode(X(time_stream.str()));
288 p_time_dataitem_element->appendChild(p_time_text);
290 for (
unsigned t=0; t<mNumberOfTimePoints; ++t)
292 DOMElement* p_grid_collection_element = p_DOM_document->createElement(X(
"Grid"));
293 p_grid_collection_element->setAttribute(X(
"CollectionType"), X(
"Spatial"));
294 p_grid_collection_element->setAttribute(X(
"GridType"), X(
"Collection"));
296 p_grid_temp_collection_element->appendChild(p_grid_collection_element);
300 for (
unsigned chunk=0; chunk<numberOfChunks; chunk++)
302 std::stringstream chunk_stream;
303 chunk_stream << chunk;
305 DOMElement* p_grid_element = p_DOM_document->createElement(X(
"Grid"));
306 p_grid_element->setAttribute(X(
"GridType"), X(
"Uniform"));
307 p_grid_element->setAttribute(X(
"Name"), X(
"Chunk_" + chunk_stream.str()));
308 p_grid_collection_element->appendChild(p_grid_element);
312 DOMElement* p_geom_element = p_DOM_document->createElement(X(
"xi:include"));
313 p_geom_element->setAttribute(X(
"href"), X(this->mBaseName+
"_geometry_"+chunk_stream.str()+
".xml"));
314 p_grid_element->appendChild(p_geom_element);
317 DOMElement* p_topo_element = p_DOM_document->createElement(X(
"xi:include"));
318 p_topo_element->setAttribute(X(
"href"), X(this->mBaseName+
"_topology_"+chunk_stream.str()+
".xml"));
319 p_grid_element->appendChild(p_topo_element);
325 AddDataOnNodes(p_grid_element, p_DOM_document, t);
330 for (
unsigned chunk=0; chunk<numberOfChunks; chunk++)
332 std::stringstream chunk_stream;
333 chunk_stream << chunk;
335 DOMElement* p_grid_element = p_DOM_document->createElement(X(
"Grid"));
336 p_grid_element->setAttribute(X(
"GridType"), X(
"Subset"));
337 p_grid_element->setAttribute(X(
"Section"), X(
"All"));
338 p_grid_collection_element->appendChild(p_grid_element);
344 AddDataOnNodes(p_grid_element, p_DOM_document, t);
345 DOMElement* p_grid_ref_element = p_DOM_document->createElement(X(
"Grid"));
346 p_grid_ref_element->setAttribute(X(
"GridType"), X(
"Uniform"));
347 p_grid_ref_element->setAttribute(X(
"Reference"), X(
"XML"));
350 DOMText* p_ref_text = p_DOM_document->createTextNode(X(
"/Xdmf/Domain/Grid/Grid/Grid[@Name=\"Chunk_"+chunk_stream.str()+
"\"]"));
351 p_grid_ref_element->appendChild(p_ref_text);
352 p_grid_element->appendChild(p_grid_ref_element);
358 p_DOM_document->appendChild(p_provenance_comment);
360 XMLFormatTarget* p_target =
new LocalFileFormatTarget(X(this->mpOutputFileHandler->GetOutputDirectoryFullPath() + this->mBaseName+
".xdmf"));
362#if _XERCES_VERSION >= 30000
363 DOMLSSerializer* p_serializer = ((DOMImplementationLS*)p_DOM_implementation)->createLSSerializer();
364 p_serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
365 DOMLSOutput* p_output = ((DOMImplementationLS*)p_DOM_implementation)->createLSOutput();
366 p_output->setByteStream(p_target);
367 p_serializer->write(p_DOM_document, p_output);
369 DOMWriter* p_serializer = ((DOMImplementationLS*)p_DOM_implementation)->createDOMWriter();
370 p_serializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
371 p_serializer->writeNode(p_target, *p_DOM_document);
375 p_serializer->release();
376 p_DOM_document->release();
377#if _XERCES_VERSION >= 30000
381 XMLPlatformUtils::Terminate();