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