Hdf5ToXdmfConverter.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "Hdf5ToXdmfConverter.hpp"
00037
00038 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00039 Hdf5ToXdmfConverter<ELEMENT_DIM, SPACE_DIM>::Hdf5ToXdmfConverter(const FileFinder& rInputDirectory,
00040 const std::string& rFileBaseName,
00041 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>* pMesh)
00042 : AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>(rInputDirectory, rFileBaseName, pMesh, "xdmf_output", 0u),
00043 XdmfMeshWriter<ELEMENT_DIM,SPACE_DIM>(rInputDirectory.GetRelativePath(FileFinder("", RelativeTo::ChasteTestOutput)) + "/xdmf_output",
00044 rFileBaseName, false )
00045 {
00046
00047 std::vector<double> time_values = this->mpReader->GetUnlimitedDimensionValues();
00048 unsigned num_timesteps = time_values.size();
00049 this->mNumberOfTimePoints = num_timesteps;
00050
00051 if (num_timesteps > 1)
00052 {
00053 this->mTimeStep = time_values[1] - time_values[0];
00054 }
00055
00056 this->WriteFilesUsingMesh(*pMesh);
00057 }
00058
00059 #ifndef _MSC_VER
00060
00061 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00062 void Hdf5ToXdmfConverter<ELEMENT_DIM, SPACE_DIM>::AddDataOnNodes(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* pGridElement,
00063 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDomDocument,
00064 unsigned timeStep)
00065 {
00066
00067 XERCES_CPP_NAMESPACE_USE
00068
00069 unsigned num_timesteps = this->mpReader->GetUnlimitedDimensionValues().size();
00070
00071
00072 for (unsigned var_index=0; var_index<this->mNumVariables; var_index++)
00073 {
00074 std::string variable_name = this->mpReader->GetVariableNames()[var_index];
00075
00076
00077
00078
00079 DOMElement* p_attr_element = pDomDocument->createElement(X("Attribute"));
00080 p_attr_element->setAttribute(X("Name"), X(variable_name));
00081 p_attr_element->setAttribute(X("Center"), X("Node"));
00082 pGridElement->appendChild(p_attr_element);
00083
00084
00085
00086
00087 DOMElement* p_hype_element = pDomDocument->createElement(X("DataItem"));
00088 p_hype_element->setAttribute(X("ItemType"), X("HyperSlab"));
00089 std::stringstream dim_stream;
00090
00091
00093
00094
00095 unsigned num_nodes = AbstractHdf5Converter<ELEMENT_DIM, SPACE_DIM>::mpMesh->GetNumNodes();
00096 dim_stream << "1 " << num_nodes << " 1";
00097 p_hype_element->setAttribute(X("Dimensions"), X(dim_stream.str()));
00098 p_attr_element->appendChild(p_hype_element);
00099
00100
00101
00102
00103 DOMElement* p_xml_element = pDomDocument->createElement(X("DataItem"));
00104 p_xml_element->setAttribute(X("Format"), X("XML"));
00105 p_xml_element->setAttribute(X("Dimensions"), X("3 3"));
00106 p_hype_element->appendChild(p_xml_element);
00107
00108
00109
00110
00111 std::stringstream XMLStream;
00112 XMLStream << timeStep << " 0 " << var_index << " ";
00113 XMLStream << "1 1 1 ";
00114
00115 XMLStream << "1 " << num_nodes << " 1";
00116 DOMText* p_xml_text = pDomDocument->createTextNode(X(XMLStream.str()));
00117 p_xml_element->appendChild(p_xml_text);
00118
00119
00120
00121
00122 DOMElement* p_hdf_element = pDomDocument->createElement(X("DataItem"));
00123 p_hdf_element->setAttribute(X("Format"), X("HDF"));
00124 p_hdf_element->setAttribute(X("NumberType"), X("Float"));
00125 p_hdf_element->setAttribute(X("Precision"), X("8"));
00126 std::stringstream hdf_dims_stream;
00127
00128 hdf_dims_stream << num_timesteps << " " << num_nodes << " " << this->mNumVariables;
00129 p_hdf_element->setAttribute(X("Dimensions"), X(hdf_dims_stream.str()));
00130 p_hype_element->appendChild(p_hdf_element);
00131
00132
00133
00134
00135 std::stringstream HDFStream;
00136 HDFStream << "../" << AbstractHdf5Converter<ELEMENT_DIM, SPACE_DIM>::mFileBaseName << ".h5:/Data";
00137 DOMText* p_hdf_text = pDomDocument->createTextNode(X(HDFStream.str()));
00138 p_hdf_element->appendChild(p_hdf_text);
00139 }
00140 }
00141
00142 #endif
00143
00145
00147
00148 template class Hdf5ToXdmfConverter<1,1>;
00149 template class Hdf5ToXdmfConverter<1,2>;
00150 template class Hdf5ToXdmfConverter<2,2>;
00151 template class Hdf5ToXdmfConverter<1,3>;
00152 template class Hdf5ToXdmfConverter<2,3>;
00153 template class Hdf5ToXdmfConverter<3,3>;