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 "HeartConfig.hpp"
00031 #include "Hdf5ToVtkConverter.hpp"
00032 #include "PetscTools.hpp"
00033 #include "Exception.hpp"
00034 #include "ReplicatableVector.hpp"
00035 #include "DistributedVector.hpp"
00036 #include "DistributedVectorFactory.hpp"
00037 #include "VtkMeshWriter.hpp"
00038 #include "GenericMeshReader.hpp"
00039
00040
00041 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00042 Hdf5ToVtkConverter<ELEMENT_DIM, SPACE_DIM>::Hdf5ToVtkConverter(std::string inputDirectory,
00043 std::string fileBaseName,
00044 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> *pMesh) :
00045 AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>(inputDirectory, fileBaseName, pMesh, "vtk_output")
00046 {
00047 #ifdef CHASTE_VTK
00048
00049
00050 VtkMeshWriter<ELEMENT_DIM,SPACE_DIM> vtk_writer(HeartConfig::Instance()->GetOutputDirectory() + "/vtk_output", fileBaseName, false);
00051
00052 unsigned num_nodes = this->mpReader->GetNumberOfRows();
00053 DistributedVectorFactory factory(num_nodes);
00055 Vec data = factory.CreateVec();
00056
00057 unsigned num_timesteps = this->mpReader->GetUnlimitedDimensionValues().size();
00058
00059
00060 for (unsigned time_step=0; time_step<num_timesteps; time_step++)
00061 {
00062
00063 for( unsigned variable = 0; variable < this->mNumVariables; variable++ )
00064 {
00065 std::string variable_name = this->mpReader->GetVariableNames()[variable];
00066
00067 this->mpReader->GetVariableOverNodes(data, variable_name, time_step);
00068 ReplicatableVector repl_data(data);
00069 std::vector<double> data_for_vtk;
00070 data_for_vtk.resize(num_nodes);
00071 for (unsigned index=0; index<num_nodes; index++)
00072 {
00073 data_for_vtk[index] = repl_data[index];
00074 }
00075
00076 std::ostringstream variable_point_data_name;
00077 variable_point_data_name << variable_name << "_" << std::setw(6) << std::setfill('0') << time_step;
00078
00079 if (PetscTools::AmMaster())
00080 {
00081
00082 vtk_writer.AddPointData(variable_point_data_name.str(), data_for_vtk);
00083 }
00084 }
00085 }
00086 VecDestroy(data);
00087
00088
00089 if (HeartConfig::Instance()->GetOutputUsingOriginalNodeOrdering() == false)
00090 {
00091 vtk_writer.WriteFilesUsingMesh( *(this->mpMesh) );
00092 }
00093 else
00094 {
00095
00097
00098 std::string original_file=this->mpMesh->GetMeshFileBaseName();
00099 GenericMeshReader<ELEMENT_DIM, SPACE_DIM> original_mesh_reader(original_file);
00100 vtk_writer.WriteFilesUsingMeshReader(original_mesh_reader);
00101 }
00102
00103 #endif //CHASTE_VTK
00104
00105 }
00106
00107
00109
00111
00112 template class Hdf5ToVtkConverter<1,1>;
00113 template class Hdf5ToVtkConverter<1,2>;
00114 template class Hdf5ToVtkConverter<2,2>;
00115 template class Hdf5ToVtkConverter<1,3>;
00116 template class Hdf5ToVtkConverter<2,3>;
00117 template class Hdf5ToVtkConverter<3,3>;