36 #include "CompareHdf5ResultsFiles.hpp" 41 #include "Hdf5DataReader.hpp" 42 #include "DistributedVectorFactory.hpp" 44 bool CompareFilesViaHdf5DataReader(std::string pathname1, std::string filename1,
bool makeAbsolute1,
45 std::string pathname2, std::string filename2,
bool makeAbsolute2,
46 double tol, std::string datasetName)
48 Hdf5DataReader reader1(pathname1, filename1, makeAbsolute1, datasetName);
49 Hdf5DataReader reader2(pathname2, filename2, makeAbsolute2, datasetName);
51 unsigned number_nodes1 = reader1.GetNumberOfRows();
52 unsigned number_nodes2 = reader2.GetNumberOfRows();
53 if (number_nodes1 != number_nodes2)
55 std::cout <<
"Number of nodes " << number_nodes1 <<
" and " << number_nodes2 <<
" don't match\n";
60 std::vector<std::string> variable_names1 = reader1.GetVariableNames();
61 std::vector<std::string> variable_names2 = reader2.GetVariableNames();
62 std::string unlimited_variable1 = reader1.GetUnlimitedDimensionName();
63 std::string unlimited_variable2 = reader2.GetUnlimitedDimensionName();
64 std::string unlimited_variable_unit1 = reader1.GetUnlimitedDimensionUnit();
65 std::string unlimited_variable_unit2 = reader2.GetUnlimitedDimensionUnit();
67 unsigned num_vars = variable_names1.size();
68 if (num_vars != variable_names2.size())
70 std::cout <<
"Number of variables " << variable_names1.size()
71 <<
" and " << variable_names2.size() <<
" don't match\n";
74 if (unlimited_variable1 != unlimited_variable2)
76 std::cout <<
"Unlimited variable names " << unlimited_variable1 <<
" and " 77 << unlimited_variable2 <<
" don't match\n";
80 if (unlimited_variable_unit1 != unlimited_variable_unit2)
82 std::cout <<
"Unlimited variable units " << unlimited_variable_unit1 <<
" and " 83 << unlimited_variable_unit2 <<
" don't match\n";
86 for (
unsigned var=0; var<num_vars; var++)
88 std::string var_name = variable_names1[var];
89 if (var_name != variable_names2[var])
91 std::cout <<
"Variable names " << var_name <<
" and " 92 << variable_names2[var] <<
" don't match\n";
95 if (reader1.GetUnit(var_name) != reader2.GetUnit(var_name))
97 std::cout <<
"Units names " << reader1.GetUnit(var_name)
98 <<
" and " << reader2.GetUnit(var_name) <<
" don't match\n";
104 std::vector<double> times1 = reader1.GetUnlimitedDimensionValues();
105 std::vector<double> times2 = reader2.GetUnlimitedDimensionValues();
107 if (times1.size() != times2.size())
109 std::cout <<
"Number of time steps " << times1.size()
110 <<
" and " << times2.size() <<
" don't match\n";
114 for (
unsigned timestep=0; timestep<times1.size(); timestep++)
117 if (fabs(times1[timestep]-times2[timestep]) > 1e-8)
119 std::cout <<
"Time steps " << times1[timestep]
120 <<
" and " << times2[timestep] <<
" don't match\n";
125 bool is_complete1 = reader1.IsDataComplete();
126 bool is_complete2 = reader2.IsDataComplete();
128 if (is_complete1 != is_complete2)
130 std::cout<<
"One of the readers has incomplete data and the other doesn't\n";
138 Vec data1 = factory.CreateVec();
139 Vec data2 = factory.CreateVec();
141 for (
unsigned timestep=0; timestep<times1.size(); timestep++)
143 for (
unsigned var=0; var<num_vars; var++)
145 reader1.GetVariableOverNodes(data1, variable_names1[var], timestep);
146 reader2.GetVariableOverNodes(data2, variable_names2[var], timestep);
148 #if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) //PETSc 2.2 149 double minus_one = -1.0;
150 VecAXPY(&minus_one, data2, data1);
153 VecAXPY(data1, -1.0, data2);
156 PetscReal difference_norm;
157 VecNorm(data1, NORM_2, &difference_norm);
159 if (difference_norm > tol)
161 std::cout <<
"Time " << times1[timestep] <<
": vectors differ in NORM_2 by " << difference_norm << std::endl;
174 std::vector<unsigned> indices1 = reader1.GetIncompleteNodeMap();
175 std::vector<unsigned> indices2 = reader2.GetIncompleteNodeMap();
177 if (indices1.size() != indices2.size())
179 std::cout <<
"Index map sizes " << indices1.size() <<
" and " << indices2.size() <<
" don't match\n";
183 for (
unsigned index=0; index<indices1.size(); index++)
185 if (indices1[index]!=indices2[index])
187 std::cout <<
"Time steps " << indices1[index] <<
" and " << indices2[index] <<
" don't match\n";
193 for (
unsigned index=0; index<indices1.size(); index++)
195 unsigned node_index = indices1[index];
196 for (
unsigned var=0; var<num_vars; var++)
198 std::vector<double> var_over_time1 = reader1.GetVariableOverTime(variable_names1[var], node_index);
199 std::vector<double> var_over_time2 = reader2.GetVariableOverTime(variable_names1[var], node_index);
200 for (
unsigned time_step=0;time_step< var_over_time1.size(); time_step++)
202 if (fabs(var_over_time1[time_step] - var_over_time2[time_step]) > tol)
204 std::cout<<
"Node "<<node_index<<
" at time step "<<time_step<<
" variable "<<variable_names1[var]<<
205 " differs ("<<var_over_time1[time_step]<<
" != "<<var_over_time2[time_step]<<
")\n";
215 bool CompareFilesViaHdf5DataReaderGlobalNorm(std::string pathname1, std::string filename1,
bool makeAbsolute1,
216 std::string pathname2, std::string filename2,
bool makeAbsolute2,
217 double tol, std::string datasetName)
219 Hdf5DataReader reader1(pathname1, filename1, makeAbsolute1, datasetName);
220 Hdf5DataReader reader2(pathname2, filename2, makeAbsolute2, datasetName);
222 unsigned number_nodes1 = reader1.GetNumberOfRows();
223 bool is_the_same =
true;
224 std::vector<std::string> variable_names1 = reader1.GetVariableNames();
225 std::vector<std::string> variable_names2 = reader2.GetVariableNames();
226 std::vector<double> times1 = reader1.GetUnlimitedDimensionValues();
227 unsigned num_vars = variable_names1.size();
230 Vec data1 = factory.CreateVec();
231 Vec data2 = factory.CreateVec();
233 for (
unsigned timestep=0; timestep<times1.size(); timestep++)
235 for (
unsigned var=0; var<num_vars; var++)
237 reader1.GetVariableOverNodes(data1, variable_names1[var], timestep);
238 reader2.GetVariableOverNodes(data2, variable_names2[var], timestep);
240 PetscReal data1_norm;
241 PetscReal data2_norm;
242 VecNorm(data1, NORM_2, &data1_norm);
243 VecNorm(data2, NORM_2, &data2_norm);
244 PetscReal norm = fabs(data1_norm-data2_norm);
248 std::cout <<
"Vectors differ in global NORM_2 by " << norm << std::endl;