38 value = std::stod(s, &pos);
42 OGS_FATAL(
"The given string '{:s}' is not convertible to double.", s);
47 "Only {:d} characters were used for double conversion of string "
52 if (std::isnan(value))
54 OGS_FATAL(
"The given string '{:s}' results in a NaN value.", s);
62 return "\"" + s +
"\"";
70 if (
const char* vtkdiff_exe_environment_variable =
71 std::getenv(
"VTKDIFF_EXE"))
73 std::string
const vtkdiff_exe{vtkdiff_exe_environment_variable};
74 DBUG(
"VTKDIFF_EXE set to {:s}.", vtkdiff_exe);
80 auto const& base_name =
82 if (base_name !=
"vtkdiff")
85 "The VTKDIFF_EXE environment variable does not point to "
86 "'vtkdiff'. VTKDIFF_EXE='{:s}'",
94 "The VTKDIFF_EXE points to a non-existing file. "
103 int const return_value =
111 std::system((vtkdiff_exe +
" --version").c_str());
112 if (return_value == 0)
117 "Calling {:s} from the VTKDIFF_EXE environment variable didn't "
118 "work as expected. Return value was {:d}.",
119 vtkdiff_exe, return_value);
122 std::string
const vtkdiff_exe{
"vtkdiff"};
123 std::vector<std::string>
const paths = {
"",
"bin"};
125 find_if(begin(paths), end(paths),
126 [&vtkdiff_exe](std::string
const& path)
128 int const return_value =
134 return return_value == 0;
136 if (path == end(paths))
148 std::string
const& reference_path,
149 std::string
const& output_directory)
151 if (reference_path.empty())
154 "Reference path containing expected result files can not be "
164 for (
auto const& vtkdiff_config : vtkdiff_configs)
166 std::string
const& field_name =
168 vtkdiff_config.getConfigParameter<std::string>(
"field");
169 DBUG(
"vtkdiff will compare field '{:s}'.", field_name);
171 std::vector<std::string> filenames;
172 if (
auto const regex_string =
174 vtkdiff_config.getConfigParameterOptional<std::string>(
"regex"))
177 DBUG(
"vtkdiff regex is '{}'.", *regex_string);
178 auto const regex = std::regex(*regex_string);
180 fs::directory_iterator(fs::path(reference_path)))
182 auto const filename = p.path().filename().string();
183 if (std::regex_match(filename, regex))
185 DBUG(
" -> matched '{}'", filename);
186 filenames.push_back(filename);
194 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
196 MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size);
197 std::string
const& filename =
200 vtkdiff_config.getConfigParameter<std::string>(
"file")) +
201 "_" + std::to_string(rank) +
".vtu";
203 std::string
const& filename =
205 vtkdiff_config.getConfigParameter<std::string>(
"file");
207 filenames.push_back(filename);
210 if (empty(filenames))
213 "No files from test definitions were added for tests but {} "
215 size(vtkdiff_configs),
216 (size(vtkdiff_configs) == 1 ?
"test was" :
"tests were"));
219 auto const absolute_tolerance =
221 vtkdiff_config.getConfigParameter<std::string>(
"absolute_tolerance",
223 if (!absolute_tolerance.empty() &&
227 "The absolute tolerance value '{:s}' is not convertible to "
231 std::string
const absolute_tolerance_parameter =
232 "--abs " + absolute_tolerance;
233 auto const relative_tolerance =
235 vtkdiff_config.getConfigParameter<std::string>(
"relative_tolerance",
237 if (!relative_tolerance.empty() &&
241 "The relative tolerance value '{:s}' is not convertible to "
245 std::string
const relative_tolerance_parameter =
246 "--rel " + relative_tolerance;
248 for (
auto const& filename : filenames)
250 std::string
const& output_filename =
253 std::string
const& reference_filename =
259 std::string command_line =
260 vtkdiff +
" -a " +
safeString(field_name) +
" -b " +
263 absolute_tolerance_parameter +
" " +
264 relative_tolerance_parameter;
265 INFO(
"Will run '{:s}'", command_line);
273 std::vector<int> return_values;
275 back_inserter(return_values),
276 [](std::string
const& command_line)
278 int const return_value = std::system(command_line.c_str());
279 if (return_value != 0)
281 WARN(
"Return value {:d} was returned by '{:s}'.",
282 return_value, command_line);
286 return !return_values.empty() &&
287 all_of(begin(return_values), end(return_values),
288 [](
int const& return_value) {
return return_value == 0; });
void INFO(char const *fmt, Args const &... args)
void DBUG(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... args)
Implementation of the VtuInterface class.
std::vector< std::string > _output_files
std::vector< std::string > _command_lines
TestDefinition(BaseLib::ConfigTree const &config_tree, std::string const &reference_path, std::string const &output_directory)
std::size_t numberOfTests() const
std::vector< std::string > const & getOutputFiles() const
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
bool IsFileExisting(const std::string &strFilename)
Returns true if given file exists.
std::string extractBaseNameWithoutExtension(std::string const &pathname)
std::string joinPaths(std::string const &pathA, std::string const &pathB)
std::string getVtuFileNameForPetscOutputWithoutExtension(std::string const &file_name)
std::string findVtkdiff()
bool isConvertibleToDouble(std::string const &s)
Test if the given string is convertible to a valid double value, not a NaN.
std::string safeString(std::string const &s)
Wraps a string into double ticks.