Hdf5ToMeshalyzerConverter.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 #include <vector>
00031
00032 #include "Hdf5ToMeshalyzerConverter.hpp"
00033 #include "MeshalyzerMeshWriter.hpp"
00034 #include "UblasCustomFunctions.hpp"
00035 #include "HeartConfig.hpp"
00036 #include "PetscTools.hpp"
00037 #include "Exception.hpp"
00038 #include "ReplicatableVector.hpp"
00039 #include "DistributedVector.hpp"
00040 #include "DistributedVectorFactory.hpp"
00041 #include "Version.hpp"
00042
00043 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00044 void Hdf5ToMeshalyzerConverter<ELEMENT_DIM,SPACE_DIM>::Write(std::string type)
00045 {
00046 assert(type=="V" || type=="Phi_e");
00047
00048 out_stream p_file=out_stream(NULL);
00049 if (PetscTools::AmMaster())
00050 {
00051 p_file = this->mpOutputFileHandler->OpenOutputFile(this->mFileBaseName + "_" + type + ".dat");
00052 }
00053
00054 unsigned num_nodes = this->mpReader->GetNumberOfRows();
00055 unsigned num_timesteps = this->mpReader->GetUnlimitedDimensionValues().size();
00056
00057 DistributedVectorFactory factory(num_nodes);
00058
00059 Vec data = factory.CreateVec();
00060 for (unsigned time_step=0; time_step<num_timesteps; time_step++)
00061 {
00062 this->mpReader->GetVariableOverNodes(data, type, time_step);
00063 ReplicatableVector repl_data(data);
00064
00065 assert(repl_data.GetSize()==num_nodes);
00066
00067 if(PetscTools::AmMaster())
00068 {
00069 for(unsigned i=0; i<num_nodes; i++)
00070 {
00071 *p_file << repl_data[i] << "\n";
00072 }
00073 }
00074 }
00075 VecDestroy(data);
00076 if(PetscTools::AmMaster())
00077 {
00078 std::string comment = "# " + ChasteBuildInfo::GetProvenanceString();
00079 *p_file << comment;
00080 p_file->close();
00081 }
00082 }
00083
00084
00085 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00086 Hdf5ToMeshalyzerConverter<ELEMENT_DIM,SPACE_DIM>::Hdf5ToMeshalyzerConverter(std::string inputDirectory,
00087 std::string fileBaseName,
00088 AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM> *pMesh) :
00089 AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>(inputDirectory, fileBaseName, pMesh, "output")
00090 {
00091
00092 Write("V");
00093 if (this->mNumVariables == 2)
00094 {
00095 Write("Phi_e");
00096 }
00097
00098
00099
00100 std::string output_directory = HeartConfig::Instance()->GetOutputDirectory() + "/output";
00101 MeshalyzerMeshWriter<ELEMENT_DIM,SPACE_DIM> mesh_writer(output_directory, HeartConfig::Instance()->GetOutputFilenamePrefix()+"_mesh", false);
00102 mesh_writer.WriteFilesUsingMesh(*(this->mpMesh));
00103
00104 PetscTools::Barrier("Hdf5ToMeshalyzerConverter");
00105 }
00106
00107
00109
00111
00112 template class Hdf5ToMeshalyzerConverter<1,1>;
00113 template class Hdf5ToMeshalyzerConverter<1,2>;
00114 template class Hdf5ToMeshalyzerConverter<2,2>;
00115 template class Hdf5ToMeshalyzerConverter<1,3>;
00116 template class Hdf5ToMeshalyzerConverter<2,3>;
00117 template class Hdf5ToMeshalyzerConverter<3,3>;