diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c81a057131..6a8241e46c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -791,12 +791,13 @@ endif() # Tests ####################################################################### # +if(BUILD_TESTING) + enable_testing() -#if(BUILD_TESTING) -# enable_testing() -# -# add_test(...) -#endif() + if(WarpX_APP) + add_subdirectory(Examples) + endif() +endif() # Status Summary for Build Options ############################################ diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt new file mode 100644 index 00000000000..3d49bb052a5 --- /dev/null +++ b/Examples/CMakeLists.txt @@ -0,0 +1,175 @@ +# Configuration ############################################################### +# +if(WarpX_MPI) + # OpenMPI root guard: https://github.com/open-mpi/ompi/issues/4451 + if("$ENV{USER}" STREQUAL "root") + # calling even --help as root will abort and warn on stderr + execute_process( + COMMAND ${MPIEXEC_EXECUTABLE} --help + ERROR_VARIABLE MPIEXEC_HELP_TEXT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(${MPIEXEC_HELP_TEXT} MATCHES "^.*allow-run-as-root.*$") + set(MPI_ALLOW_ROOT --allow-run-as-root) + endif() + endif() + set(MPI_TEST_EXE + ${MPIEXEC_EXECUTABLE} + ${MPI_ALLOW_ROOT} + ${MPIEXEC_NUMPROC_FLAG} 2 + ${MPIEXEC_POSTFLAGS} + ${MPIEXEC_PREFLAGS} + ) +endif() + +# Add a WarpX test set (with sub-tests) +# +function(add_warpx_test + name + mpi + dims + inputs_base + inputs_test + analysis + output +) + # cannot run MPI tests w/o MPI support + if(mpi AND NOT WarpX_MPI) + return() + endif() + + # make a unique run directory + file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name}) + set(THIS_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${name}) + + set(THIS_MPI_TEST_EXE) + if(mpi) + set(THIS_MPI_TEST_EXE ${MPI_TEST_EXE}) + endif() + + # test run + add_test( + NAME ${name}.run + COMMAND + ${THIS_MPI_TEST_EXE} + $ + ${WarpX_SOURCE_DIR}/${inputs_base} + amrex.abort_on_unused_inputs = 1 + amrex.fpe_trap_invalid = 1 + amrex.fpe_trap_overflow = 1 + amrex.fpe_trap_zero = 1 + amrex.throw_exception = 1 + warpx.always_warn_immediately = 1 + warpx.abort_on_warning_threshold = low + warpx.do_dynamic_scheduling = 0 + warpx.serialize_initial_conditions = 1 + # FILE parameter must be at the end, + # to possibly overwrite previous inputs + FILE = ${WarpX_SOURCE_DIR}/${inputs_test} + WORKING_DIRECTORY ${THIS_WORKING_DIR} + ) + + if(mpi) + set_property(TEST ${name}.run APPEND PROPERTY ENVIRONMENT "OMP_NUM_THREADS=1") + endif() + + # test analysis + if(analysis) + add_test( + NAME ${name}.analysis + COMMAND + ${WarpX_SOURCE_DIR}/${analysis} + ${output} + WORKING_DIRECTORY ${THIS_WORKING_DIR} + ) + set_property(TEST ${name}.analysis APPEND PROPERTY DEPENDS "${name}.run") + endif() + +endfunction() + +# Add tests (alphabetical order) ############################################## +# + +# Langmuir_multi_2d_MR ######################################################## +# +if(2 IN_LIST WarpX_DIMS) + add_warpx_test( + Langmuir_multi_2d_MR + ON + 2 + Examples/Tests/langmuir/inputs_2d_base + Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR + Examples/Tests/langmuir/analysis_2d.py + diags/diag1000080 + ) +endif() + +# Langmuir_multi_2d_MR_anisotropic ############################################ +# +if(2 IN_LIST WarpX_DIMS) + add_warpx_test( + Langmuir_multi_2d_MR_anisotropic + ON + 2 + Examples/Tests/langmuir/inputs_2d_base + Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR_anisotropic + Examples/Tests/langmuir/analysis_2d.py + diags/diag1000080 + ) +endif() + +# Langmuir_multi_2d_MR_momentum_conserving #################################### +# +if(2 IN_LIST WarpX_DIMS) + add_warpx_test( + Langmuir_multi_2d_MR_momentum_conserving + ON + 2 + Examples/Tests/langmuir/inputs_2d_base + Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR_momentum_conserving + Examples/Tests/langmuir/analysis_2d.py + diags/diag1000080 + ) +endif() + +# Langmuir_multi_2d_MR_psatd ################################################## +# +if(2 IN_LIST WarpX_DIMS AND WarpX_FFT) + add_warpx_test( + Langmuir_multi_2d_MR_psatd + ON + 2 + Examples/Tests/langmuir/inputs_2d_base + Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR_psatd + Examples/Tests/langmuir/analysis_2d.py + diags/diag1000080 + ) +endif() + +# Langmuir_multi_2d_nodal ##################################################### +# +if(2 IN_LIST WarpX_DIMS) + add_warpx_test( + Langmuir_multi_2d_nodal + ON + 2 + Examples/Tests/langmuir/inputs_2d_base + Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_nodal + Examples/Tests/langmuir/analysis_2d.py + diags/diag1000080 + ) +endif() + +# Langmuir_multi_2d_psatd ##################################################### +# +if(2 IN_LIST WarpX_DIMS AND WarpX_FFT) + add_warpx_test( + Langmuir_multi_2d_psatd + ON + 2 + Examples/Tests/langmuir/inputs_2d_base + Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_psatd + Examples/Tests/langmuir/analysis_2d.py + diags/diag1000080 + ) +endif() diff --git a/Examples/Tests/langmuir/inputs_2d b/Examples/Tests/langmuir/inputs_2d_base similarity index 100% rename from Examples/Tests/langmuir/inputs_2d rename to Examples/Tests/langmuir/inputs_2d_base diff --git a/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR b/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR new file mode 100644 index 00000000000..586624654c1 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR @@ -0,0 +1,9 @@ +# additional runtime parameters +algo.maxwell_solver = ckc +amr.max_level = 1 +amr.ref_ratio = 4 +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.fine_tag_hi = 10.e-6 10.e-6 +warpx.fine_tag_lo = -10.e-6 -10.e-6 +warpx.use_filter = 1 diff --git a/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR_anisotropic b/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR_anisotropic new file mode 100644 index 00000000000..91c2d1c80d3 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_MR_anisotropic @@ -0,0 +1,9 @@ +# additional runtime parameters +algo.maxwell_solver = ckc +amr.max_level = 1 +amr.ref_ratio_vect = 4 2 +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.fine_tag_hi = 10.e-6 10.e-6 +warpx.fine_tag_lo = -10.e-6 -10.e-6 +warpx.use_filter = 1 diff --git a/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_nodal b/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_nodal new file mode 100644 index 00000000000..a5c132eef91 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_nodal @@ -0,0 +1,5 @@ +# additional runtime parameters +algo.current_deposition = direct +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +warpx.grid_type = collocated diff --git a/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_psatd b/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_psatd new file mode 100644 index 00000000000..343cc0cede1 --- /dev/null +++ b/Examples/Tests/langmuir/inputs_2d_test_Langmuir_multi_2d_psatd @@ -0,0 +1,8 @@ +# additional runtime parameters +algo.maxwell_solver = psatd +diag1.electrons.variables = x z w ux uy uz +diag1.positrons.variables = x z w ux uy uz +diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell +psatd.current_correction = 0 +warpx.abort_on_warning_threshold = medium +warpx.cfl = 0.7071067811865475 diff --git a/Regression/WarpX-tests.ini b/Regression/WarpX-tests.ini index 17ecfd64f29..2ea8018fd8c 100644 --- a/Regression/WarpX-tests.ini +++ b/Regression/WarpX-tests.ini @@ -1011,7 +1011,7 @@ analysisOutputImage = langmuir_multi_1d_analysis.png [Langmuir_multi_2d_MR] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver = ckc warpx.use_filter = 1 amr.max_level = 1 amr.ref_ratio = 4 warpx.fine_tag_lo = -10.e-6 -10.e-6 warpx.fine_tag_hi = 10.e-6 10.e-6 diag1.electrons.variables = x z w ux uy uz diag1.positrons.variables = x z w ux uy uz dim = 2 addToCompileString = @@ -1026,7 +1026,7 @@ analysisOutputImage = Langmuir_multi_2d_MR.png [Langmuir_multi_2d_MR_anisotropic] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver = ckc warpx.use_filter = 1 amr.max_level = 1 amr.ref_ratio_vect = 4 2 warpx.fine_tag_lo = -10.e-6 -10.e-6 warpx.fine_tag_hi = 10.e-6 10.e-6 diag1.electrons.variables = x z w ux uy uz diag1.positrons.variables = x z w ux uy uz dim = 2 addToCompileString = @@ -1041,7 +1041,7 @@ analysisOutputImage = Langmuir_multi_2d_MR.png [Langmuir_multi_2d_MR_momentum_conserving] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=ckc warpx.use_filter=1 amr.max_level=1 amr.ref_ratio=4 warpx.fine_tag_lo=-10.e-6 -10.e-6 warpx.fine_tag_hi=10.e-6 10.e-6 algo.field_gathering=momentum-conserving diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz dim = 2 addToCompileString = @@ -1056,7 +1056,7 @@ analysisOutputImage = Langmuir_multi_2d_MR_momentum_conserving.png [Langmuir_multi_2d_MR_psatd] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver = psatd warpx.use_filter = 1 amr.max_level = 1 amr.ref_ratio = 4 warpx.fine_tag_lo = -10.e-6 -10.e-6 warpx.fine_tag_hi = 10.e-6 10.e-6 diag1.electrons.variables = x z w ux uy uz diag1.positrons.variables = x z w ux uy uz psatd.current_correction=0 warpx.abort_on_warning_threshold=medium dim = 2 addToCompileString = USE_FFT=TRUE @@ -1071,7 +1071,7 @@ analysisOutputImage = Langmuir_multi_2d_MR_psatd.png [Langmuir_multi_2d_nodal] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = warpx.grid_type=collocated algo.current_deposition=direct diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz dim = 2 addToCompileString = @@ -1086,7 +1086,7 @@ analysisOutputImage = langmuir_multi_2d_analysis.png [Langmuir_multi_2d_psatd] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot=Ex Ey Ez jx jy jz part_per_cell warpx.cfl = 0.7071067811865475 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium dim = 2 addToCompileString = USE_FFT=TRUE @@ -1101,7 +1101,7 @@ analysisOutputImage = langmuir_multi_2d_analysis.png [Langmuir_multi_2d_psatd_current_correction] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 algo.current_deposition=esirkepov psatd.periodic_single_box_fft=1 psatd.current_correction=1 diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot =Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 dim = 2 addToCompileString = USE_FFT=TRUE @@ -1116,7 +1116,7 @@ analysisOutputImage = langmuir_multi_2d_analysis.png [Langmuir_multi_2d_psatd_current_correction_nodal] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 algo.current_deposition=direct psatd.periodic_single_box_fft=1 psatd.current_correction=1 warpx.grid_type=collocated diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot =Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 dim = 2 addToCompileString = USE_FFT=TRUE @@ -1131,7 +1131,7 @@ analysisOutputImage = langmuir_multi_2d_analysis.png [Langmuir_multi_2d_psatd_momentum_conserving] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd algo.field_gathering=momentum-conserving diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot=Ex Ey Ez jx jy jz part_per_cell warpx.cfl = 0.7071067811865475 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium dim = 2 addToCompileString = USE_FFT=TRUE @@ -1146,7 +1146,7 @@ analysisOutputImage = langmuir_multi_2d_analysis.png [Langmuir_multi_2d_psatd_multiJ] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd warpx.cfl=0.7071067811865475 psatd.update_with_rho=1 warpx.do_multi_J=1 warpx.do_multi_J_n_depositions=2 psatd.solution_type=first-order psatd.J_in_time=linear warpx.abort_on_warning_threshold=medium dim = 2 addToCompileString = USE_FFT=TRUE @@ -1161,7 +1161,7 @@ analysisOutputImage = Langmuir_multi_2d_psatd_multiJ.png [Langmuir_multi_2d_psatd_multiJ_nodal] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd warpx.cfl=0.7071067811865475 psatd.update_with_rho=1 warpx.do_multi_J=1 warpx.do_multi_J_n_depositions=2 psatd.solution_type=first-order psatd.J_in_time=linear warpx.abort_on_warning_threshold=medium warpx.grid_type=collocated dim = 2 addToCompileString = USE_FFT=TRUE @@ -1176,7 +1176,7 @@ analysisOutputImage = Langmuir_multi_2d_psatd_multiJ_nodal.png [Langmuir_multi_2d_psatd_nodal] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd warpx.grid_type=collocated algo.current_deposition=direct diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot=Ex Ey Ez jx jy jz part_per_cell warpx.cfl = 0.7071067811865475 psatd.current_correction=0 warpx.abort_on_warning_threshold=medium dim = 2 addToCompileString = USE_FFT=TRUE @@ -1191,7 +1191,7 @@ analysisOutputImage = langmuir_multi_2d_analysis.png [Langmuir_multi_2d_psatd_Vay_deposition] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 algo.current_deposition=vay diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 dim = 2 addToCompileString = USE_FFT=TRUE @@ -1206,7 +1206,7 @@ analysisOutputImage = langmuir_multi_2d_analysis.png [Langmuir_multi_2d_psatd_Vay_deposition_particle_shape_4] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 algo.current_deposition=vay diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 algo.particle_shape=4 dim = 2 addToCompileString = USE_FFT=TRUE @@ -1221,7 +1221,7 @@ analysisOutputImage = langmuir_multi_2d_analysis.png [Langmuir_multi_2d_psatd_Vay_deposition_nodal] buildDir = . -inputFile = Examples/Tests/langmuir/inputs_2d +inputFile = Examples/Tests/langmuir/inputs_2d_base runtime_params = algo.maxwell_solver=psatd amr.max_grid_size=128 warpx.grid_type=collocated algo.current_deposition=vay diag1.electrons.variables=x z w ux uy uz diag1.positrons.variables=x z w ux uy uz diag1.fields_to_plot = Ex Ey Ez jx jy jz part_per_cell rho divE warpx.cfl = 0.7071067811865475 dim = 2 addToCompileString = USE_FFT=TRUE