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