Hdf5ToVtkConverter.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 "UblasCustomFunctions.hpp"
00033 #include "HeartConfig.hpp"
00034 #include "Hdf5ToVtkConverter.hpp"
00035 #include "PetscTools.hpp"
00036 #include "Exception.hpp"
00037 #include "ReplicatableVector.hpp"
00038 #include "DistributedVector.hpp"
00039 #include "DistributedVectorFactory.hpp"
00040 #include "VtkWriter.hpp"
00041
00042 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00043 Hdf5ToVtkConverter<ELEMENT_DIM, SPACE_DIM>::Hdf5ToVtkConverter(std::string inputDirectory,
00044 std::string fileBaseName,
00045 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> *pMesh) :
00046 AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>(inputDirectory, fileBaseName, pMesh, "vtk_output")
00047 {
00048 #ifdef CHASTE_VTK
00049
00050
00051 VtkWriter<ELEMENT_DIM,SPACE_DIM> vtk_writer(HeartConfig::Instance()->GetOutputDirectory() + "/vtk_output", fileBaseName, false);
00052
00053 unsigned num_nodes = this->mpReader->GetNumberOfRows();
00054 DistributedVectorFactory factory(num_nodes);
00056 Vec data = factory.CreateVec();
00057
00058 unsigned num_timesteps = this->mpReader->GetUnlimitedDimensionValues().size();
00059
00060
00061 for (unsigned time_step=0; time_step<num_timesteps; time_step++)
00062 {
00063 this->mpReader->GetVariableOverNodes(data, "V", time_step);
00064 ReplicatableVector repl_data(data);
00065 std::vector<double> v_for_vtk;
00066 v_for_vtk.resize(num_nodes);
00067 for (unsigned index=0; index<num_nodes; index++)
00068 {
00069 v_for_vtk[index] = repl_data[index];
00070 }
00071
00072 std::ostringstream V_point_data_name;
00073 V_point_data_name << "V_" << std::setw(6) << std::setfill('0') << time_step;
00074
00075 if (PetscTools::AmMaster())
00076 {
00077
00078 vtk_writer.AddPointData(V_point_data_name.str(), v_for_vtk);
00079 }
00080 if(this->mNumVariables==2)
00081 {
00082 this->mpReader->GetVariableOverNodes(data, "Phi_e", time_step);
00083 ReplicatableVector repl_phi(data);
00084 std::vector<double> phi_for_vtk;
00085 phi_for_vtk.resize(num_nodes);
00086 for (unsigned index=0; index<num_nodes; index++)
00087 {
00088 phi_for_vtk[index] = repl_phi[index];
00089 }
00090
00091 std::ostringstream Phi_point_data_name;
00092 Phi_point_data_name << "Phi_e_" << std::setw(6) << std::setfill('0') << time_step;
00093
00094 if (PetscTools::AmMaster())
00095 {
00096
00097 vtk_writer.AddPointData(Phi_point_data_name.str(), phi_for_vtk);
00098 }
00099 }
00100 }
00101 VecDestroy(data);
00102 vtk_writer.WriteFilesUsingMesh( *(this->mpMesh) );
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>;