Hdf5ToTxtConverter.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 "UblasCustomFunctions.hpp"
00037 #include "Hdf5ToTxtConverter.hpp"
00038 #include "PetscTools.hpp"
00039 #include "Exception.hpp"
00040 #include "ReplicatableVector.hpp"
00041 #include "DistributedVector.hpp"
00042 #include "DistributedVectorFactory.hpp"
00043 #include "DistributedTetrahedralMesh.hpp"
00044 #include "Warnings.hpp"
00045
00046 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00047 Hdf5ToTxtConverter<ELEMENT_DIM, SPACE_DIM>::Hdf5ToTxtConverter(const FileFinder& rInputDirectory,
00048 const std::string& rFileBaseName,
00049 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>* pMesh)
00050 : AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>(rInputDirectory, rFileBaseName, pMesh, "txt_output", 0u)
00051 {
00052
00053 assert(this->mpReader->GetNumberOfRows() == pMesh->GetNumNodes());
00054
00055 FileFinder output_directory(this->mRelativeSubdirectory,rInputDirectory);
00056 OutputFileHandler handler(output_directory);
00057
00058 unsigned num_nodes = pMesh->GetNumNodes();
00059 unsigned num_timesteps = this->mpReader->GetUnlimitedDimensionValues().size();
00060
00061 DistributedVectorFactory* p_factory = pMesh->GetDistributedVectorFactory();
00062 Vec data = p_factory->CreateVec();
00063 ReplicatableVector repl_data(num_nodes);
00064
00065
00066 for (unsigned time_step=0; time_step<num_timesteps; time_step++)
00067 {
00068
00069 for (unsigned var_index=0; var_index<this->mNumVariables; var_index++)
00070 {
00071 std::string variable_name = this->mpReader->GetVariableNames()[var_index];
00072
00073
00074 std::stringstream file_name;
00075 file_name << rFileBaseName << "_" << variable_name << "_" << time_step << ".txt";
00076 out_stream p_file = handler.OpenOutputFile(file_name.str());
00077
00078 this->mpReader->GetVariableOverNodes(data, variable_name, time_step);
00079 repl_data.ReplicatePetscVector(data);
00080
00081 assert(repl_data.GetSize() == num_nodes);
00082
00083 if (PetscTools::AmMaster())
00084 {
00085 for (unsigned i=0; i<num_nodes; i++)
00086 {
00087 *p_file << repl_data[i] << "\n";
00088 }
00089 }
00090 p_file->close();
00091 }
00092 }
00093
00094
00095 PetscTools::Destroy(data);
00096 }
00097
00099
00101
00102 template class Hdf5ToTxtConverter<1,1>;
00103 template class Hdf5ToTxtConverter<1,2>;
00104 template class Hdf5ToTxtConverter<2,2>;
00105 template class Hdf5ToTxtConverter<1,3>;
00106 template class Hdf5ToTxtConverter<2,3>;
00107 template class Hdf5ToTxtConverter<3,3>;