Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex project file parameter #2945

Merged
merged 6 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 56 additions & 29 deletions Applications/ApplicationsLib/TestDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

#include <cmath>
#include <cstdlib>
#include <regex>
#include <vector>

#include "BaseLib/ConfigTree.h"
#include "BaseLib/Error.h"
#include "BaseLib/FileTools.h"
#include "filesystem.h"
#ifdef USE_PETSC
#include "MeshLib/IO/VtkIO/VtuInterface.h" // For petsc file name conversion.
#include <petsc.h>
Expand Down Expand Up @@ -163,27 +166,43 @@ TestDefinition::TestDefinition(BaseLib::ConfigTree const& config_tree,
vtkdiff_config.getConfigParameter<std::string>("field");
DBUG("vtkdiff will compare field '{:s}'.", field_name);

std::vector<std::string> filenames;
if (auto const regex_string =
//! \ogs_file_param{prj__test_definition__vtkdiff__regex}
vtkdiff_config.getConfigParameterOptional<std::string>("regex"))
{
// TODO: insert rank into regex for mpi case
DBUG("vtkdiff regex is '{}'.", *regex_string);
auto const regex = std::regex(*regex_string);
for (auto const & p: fs::directory_iterator(fs::path(reference_path)))
{
auto const filename = p.path().filename().string();
if (std::regex_match(filename, regex))
{
DBUG(" -> matched '{}'", filename);
filenames.push_back(filename);
}
}
}
else
{
#ifdef USE_PETSC
int rank;
MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
int mpi_size;
MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size);
std::string const& filename =
MeshLib::IO::getVtuFileNameForPetscOutputWithoutExtension(
//! \ogs_file_param{prj__test_definition__vtkdiff__file}
vtkdiff_config.getConfigParameter<std::string>("file")) +
"_" + std::to_string(rank) + ".vtu";
int rank;
MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
int mpi_size;
MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size);
std::string const& filename =
TomFischer marked this conversation as resolved.
Show resolved Hide resolved
MeshLib::IO::getVtuFileNameForPetscOutputWithoutExtension(
//! \ogs_file_param{prj__test_definition__vtkdiff__file}
vtkdiff_config.getConfigParameter<std::string>("file")) +
"_" + std::to_string(rank) + ".vtu";
#else
std::string const& filename =
//! \ogs_file_param{prj__test_definition__vtkdiff__file}
vtkdiff_config.getConfigParameter<std::string>("file");
std::string const& filename =
//! \ogs_file_param{prj__test_definition__vtkdiff__file}
vtkdiff_config.getConfigParameter<std::string>("file");
#endif // OGS_USE_PETSC
std::string const& output_filename =
BaseLib::joinPaths(output_directory, filename);
_output_files.push_back(output_filename);
// TODO (naumov) expand filename relative to ref path for globbing.
std::string const& reference_filename =
BaseLib::joinPaths(reference_path, filename);
filenames.push_back(filename);
}

auto const absolute_tolerance =
//! \ogs_file_param{prj__test_definition__vtkdiff__absolute_tolerance}
Expand All @@ -199,7 +218,6 @@ TestDefinition::TestDefinition(BaseLib::ConfigTree const& config_tree,
}
std::string const absolute_tolerance_parameter =
"--abs " + absolute_tolerance;

auto const relative_tolerance =
//! \ogs_file_param{prj__test_definition__vtkdiff__relative_tolerance}
vtkdiff_config.getConfigParameter<std::string>("relative_tolerance",
Expand All @@ -215,16 +233,25 @@ TestDefinition::TestDefinition(BaseLib::ConfigTree const& config_tree,
std::string const relative_tolerance_parameter =
"--rel " + relative_tolerance;

//
// Construct command line.
//
std::string command_line =
vtkdiff + " -a " + safeString(field_name) + " -b " +
safeString(field_name) + " " + safeString(reference_filename) +
" " + safeString(output_filename) + " " +
absolute_tolerance_parameter + " " + relative_tolerance_parameter;
INFO("Will run '{:s}'", command_line);
_command_lines.emplace_back(std::move(command_line));
for (auto const &filename : filenames)
{
std::string const& output_filename =
BaseLib::joinPaths(output_directory, filename);
_output_files.push_back(output_filename);
std::string const& reference_filename =
BaseLib::joinPaths(reference_path, filename);

//
// Construct command line.
//
std::string command_line =
vtkdiff + " -a " + safeString(field_name) + " -b " +
safeString(field_name) + " " + safeString(reference_filename) +
" " + safeString(output_filename) + " " +
absolute_tolerance_parameter + " " + relative_tolerance_parameter;
INFO("Will run '{:s}'", command_line);
_command_lines.emplace_back(std::move(command_line));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Regular expression which should match the full names of the output files. For parallel
simulations specify the same name as for the serial case; conversion of the file
names according to the number of ranks happens automatically.

Regex search is used instead of the `file`-parameter when the `regex`-parameter
is given.
20 changes: 4 additions & 16 deletions ProcessLib/HydroMechanics/Tests.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# HydroMechanics; Small deformations, linear poroelastic (HML)

### With monolithic scheme
AddTest(
NAME HydroMechanics_HML_square_1e2_quad8_confined_compression
PATH HydroMechanics/Linear/Confined_Compression
EXECUTABLE ogs
EXECUTABLE_ARGS square_1e2.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT OGS_USE_MPI
DIFF_DATA
GLOB square_1e2_pcs_0_ts_*.vtu displacement displacement 1e-15 1e-15
GLOB square_1e2_pcs_0_ts_*.vtu pressure pressure 1e-15 1e-15
GLOB square_1e2_pcs_0_ts_*.vtu pressure_interpolated pressure_interpolated 1e-15 1e-15
GLOB square_1e2_pcs_0_ts_*.vtu velocity velocity 1e-15 1e-15
GLOB square_1e2_pcs_0_ts_*.vtu HydraulicFlow HydraulicFlow 1e-15 1e-15
GLOB square_1e2_pcs_0_ts_*.vtu NodalForces NodalForces 1e-15 1e-15
)
if (NOT OGS_USE_MPI)
OgsTest(PROJECTFILE HydroMechanics/Linear/Confined_Compression/square_1e2.prj)
endif()

AddTest(
NAME HydroMechanics_HML_square_1e2_quad9_confined_compression
PATH HydroMechanics/Linear/Confined_Compression
Expand Down
30 changes: 4 additions & 26 deletions ProcessLib/LIE/HydroMechanics/Tests.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# LIE; HydroMechanics
if (NOT (OGS_USE_LIS OR OGS_USE_MPI))
OgsTest(PROJECTFILE LIE/HydroMechanics/single_fracture_constK.prj)
endif()

AddTest(
NAME LIE_HM_single_fracture
PATH LIE/HydroMechanics
Expand Down Expand Up @@ -54,32 +58,6 @@ AddTest(
expected_single_fracture_3D_pcs_0_ts_10_t_100.000000.vtu single_fracture_3D_pcs_0_ts_10_t_100.000000.vtu velocity velocity 1e-12 1e-12
)

AddTest(
NAME LIE_HM_single_fracture_constK
PATH LIE/HydroMechanics
EXECUTABLE ogs
EXECUTABLE_ARGS single_fracture_constK.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT (OGS_USE_LIS OR OGS_USE_MPI)
DIFF_DATA
GLOB single_fracture_constK_pcs_0_ts_*.vtu pressure pressure 5e-6 1e-16
GLOB single_fracture_constK_pcs_0_ts_*.vtu pressure_interpolated pressure_interpolated 5e-6 1e-16
GLOB single_fracture_constK_pcs_0_ts_*.vtu displacement displacement 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu displacement_jump1 displacement_jump1 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu nodal_w nodal_w 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu nodal_aperture nodal_aperture 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu strain_xx strain_xx 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu strain_yy strain_yy 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu strain_xy strain_xy 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu strain_zz strain_zz 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu stress_xx stress_xx 5e-6 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu stress_yy stress_yy 5e-6 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu stress_xy stress_xy 5e-6 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu stress_zz stress_zz 1e-16 0
GLOB single_fracture_constK_pcs_0_ts_*.vtu velocity velocity 1e-13 0
)

AddTest(
NAME LARGE_LIE_HM_TaskB
PATH LIE/HydroMechanics
Expand Down
45 changes: 5 additions & 40 deletions ProcessLib/RichardsComponentTransport/Tests.cmake
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
AddTest(
NAME RichardsComponentTransport_1D_Padilla_NaCl1
PATH Parabolic/RichardsComponentTransport/Padilla/Padilla_NaCl1
EXECUTABLE ogs
EXECUTABLE_ARGS Padilla_NaCl1.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT OGS_USE_MPI
DIFF_DATA
GLOB Padilla_NaCl1_pcs_0_ts_*.vtu concentration concentration 1e-12 0
GLOB Padilla_NaCl1_pcs_0_ts_*.vtu pressure pressure 1e-10 0
)

AddTest(
NAME RichardsComponentTransport_1D_Padilla_NaCl1_quadratic
PATH Parabolic/RichardsComponentTransport/Padilla/Padilla_NaCl1
EXECUTABLE ogs
EXECUTABLE_ARGS Padilla_NaCl1_quadratic.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT OGS_USE_MPI
DIFF_DATA
GLOB Padilla_NaCl1_quadratic_pcs_0_ts_*.vtu concentration concentration 5e-8 0
GLOB Padilla_NaCl1_quadratic_pcs_0_ts_*.vtu pressure pressure 5e-7 0
)

AddTest(
NAME RichardsComponentTransport_1D_Padilla_NaCl6
PATH Parabolic/RichardsComponentTransport/Padilla/Padilla_NaCl6
EXECUTABLE ogs
EXECUTABLE_ARGS Padilla_NaCl6.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT OGS_USE_MPI
RUNTIME 13
DIFF_DATA
GLOB Padilla_NaCl6_pcs_0_ts_*.vtu concentration concentration 1e-13 0
GLOB Padilla_NaCl6_pcs_0_ts_*.vtu pressure pressure 1e-10 0
)

if (NOT OGS_USE_MPI)
OgsTest(PROJECTFILE Parabolic/RichardsComponentTransport/Padilla/Padilla_NaCl1/Padilla_NaCl1.prj)
OgsTest(PROJECTFILE Parabolic/RichardsComponentTransport/Padilla/Padilla_NaCl1/Padilla_NaCl1_quadratic.prj)
OgsTest(PROJECTFILE Parabolic/RichardsComponentTransport/Padilla/Padilla_NaCl6/Padilla_NaCl6.prj RUNTIME 13)
endif()
32 changes: 6 additions & 26 deletions ProcessLib/RichardsFlow/Tests.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
if (NOT OGS_USE_MPI)
# Comparison test for richards mechanics w/o deformations.
OgsTest(PROJECTFILE RichardsMechanics/RichardsFlow_2d_richardsflow.prj)
OgsTest(PROJECTFILE Parabolic/Richards/flow_fully_saturated.prj)
endif()

AddTest(
NAME 2D_RichardsFlow_h_us_quad_ogs5
PATH Parabolic/Richards
Expand Down Expand Up @@ -63,32 +69,6 @@ AddTest(
# no longer be ambiguous.
)

# Comparison test for richards mechanics w/o deformations.
AddTest(
NAME RichardsMechanics_RichardsFlow_2d_richardsflow
PATH RichardsMechanics
EXECUTABLE ogs
EXECUTABLE_ARGS RichardsFlow_2d_richardsflow.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT OGS_USE_MPI
DIFF_DATA
GLOB RichardsFlow_2d_richardsflow_pcs_0_ts_*.vtu pressure pressure 5e-11 1e-15
GLOB RichardsFlow_2d_richardsflow_pcs_0_ts_*.vtu saturation saturation 1e-14 1e-15
)

AddTest(
NAME RichardsFlow_square_1e2_flow_fully_saturated
PATH Parabolic/Richards
EXECUTABLE ogs
EXECUTABLE_ARGS flow_fully_saturated.prj
WRAPPER time
TESTER vtkdiff
REQUIREMENTS NOT OGS_USE_MPI
DIFF_DATA
GLOB flow_fully_saturated_pcs_0_ts_*.vtu pressure pressure 1e-9 0
GLOB flow_fully_saturated_pcs_0_ts_*.vtu darcy_velocity darcy_velocity 1e-11 1e-15
)
#PETSc/MPI
#AddTest(
# NAME 2D_RichardsFlow_h_us_quad_small_PID_adaptive_dt
Expand Down
Loading