Skip to content
Open
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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ if(OPENTRIM_BUILD_GUI)
find_package(QtDataBrowser REQUIRED)
endif () ## BUILD GUI

include(CTest)

add_subdirectory(source)

if (OPENTRIM_BUILD_TESTS)
add_subdirectory(test/scattering_calc)
endif () ## Tests

add_subdirectory(test/post-build)

include(CMakeSummary)


Expand Down
5 changes: 4 additions & 1 deletion dist/OBS/opentrim.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
%global debug_package %{nil}
%global __strip /bin/true

Name: opentrim
Version: 0
Expand Down Expand Up @@ -43,6 +42,7 @@ BuildRequires: libqwt-qt5-dev
BuildRequires: libqt5svg5-dev
BuildRequires: libeigen3-dev >= 3.4
BuildRequires: libhdf5-dev
BuildRequires: hdf5-tools

%else

Expand Down Expand Up @@ -135,6 +135,9 @@ install -d %{buildroot}/%{_datadir}/%{name}/tests

cp -r test/%{name}/* %{buildroot}/%{_datadir}/%{name}/tests/

%check
%ctest "-V" "-j1"

%post libs -p /sbin/ldconfig

%postun libs -p /sbin/ldconfig
Expand Down
41 changes: 41 additions & 0 deletions test/post-build/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
find_program(H5DIFF_EXECUTABLE h5diff REQUIRED)

# loop over the test cases
foreach(N IN ITEMS 1 2 3)

# Do it with 1 or 2 threads
foreach(J IN ITEMS 1 2)

# Test 1 (fixture setup): run opentrim with J threads, produce out${N}j${J}.h5
add_test(NAME PostBuild_RunSim_${N}_${J}
COMMAND "$<TARGET_FILE:opentrim_exe>"
-f "${CMAKE_CURRENT_SOURCE_DIR}/in${N}.json"
-j ${J} -o out${N}j${J}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set_tests_properties(PostBuild_RunSim_${N}_${J} PROPERTIES
FIXTURES_SETUP PostBuildFixture_${N}_${J}
)

# Test 2: compare produced out${N}j${J}.h5 against template using h5diff
add_test(NAME PostBuild_Compare_${N}_${J}
COMMAND "${CMAKE_COMMAND}"
"-DH5DIFF=${H5DIFF_EXECUTABLE}"
"-DPRODUCED=${CMAKE_CURRENT_BINARY_DIR}/out${N}j${J}.h5"
"-DTEMPLATE=${CMAKE_CURRENT_SOURCE_DIR}/out${N}j${J}.h5"
-P "${CMAKE_CURRENT_SOURCE_DIR}/compare.cmake"
)
set_tests_properties(PostBuild_Compare_${N}_${J} PROPERTIES
FIXTURES_REQUIRED PostBuildFixture_${N}_${J}
)

# Fixture cleanup
add_test(NAME PostBuild_Cleanup_${N}_${J}
COMMAND "${CMAKE_COMMAND}" -E rm -f "${CMAKE_CURRENT_BINARY_DIR}/out${N}j${J}.h5"
)
set_tests_properties(PostBuild_Cleanup_${N}_${J} PROPERTIES
FIXTURES_CLEANUP PostBuildFixture_${N}_${J}
)

endforeach()
endforeach()
64 changes: 64 additions & 0 deletions test/post-build/compare.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
set(physics_datasets
/tally/damage_events/Implantations
/tally/damage_events/Recombinations
/tally/damage_events/Replacements
/tally/damage_events/Vacancies
/tally/energy_deposition/Ionization
/tally/energy_deposition/Lattice
/tally/energy_deposition/Lost
/tally/energy_deposition/Stored
/tally/ion_stat/Collisions
/tally/ion_stat/Flight_path
/tally/ion_stat/Lost
/tally/pka_damage/Pka
/tally/pka_damage/Pka_energy
/tally/pka_damage/Tdam
/tally/pka_damage/Tdam_LSS
/tally/pka_damage/Vnrt
/tally/pka_damage/Vnrt_LSS
/tally/totals/data
)

set(error_datasets
/tally/damage_events/Implantations_sem
/tally/damage_events/Recombinations_sem
/tally/damage_events/Replacements_sem
/tally/damage_events/Vacancies_sem
/tally/energy_deposition/Ionization_sem
/tally/energy_deposition/Lattice_sem
/tally/energy_deposition/Lost_sem
/tally/energy_deposition/Stored_sem
/tally/ion_stat/Collisions_sem
/tally/ion_stat/Flight_path_sem
/tally/ion_stat/Lost_sem
/tally/pka_damage/Pka_sem
/tally/pka_damage/Pka_energy_sem
/tally/pka_damage/Tdam_sem
/tally/pka_damage/Tdam_LSS_sem
/tally/pka_damage/Vnrt_sem
/tally/pka_damage/Vnrt_LSS_sem
/tally/totals/data_sem
)

foreach(target IN LISTS physics_datasets)
execute_process(
COMMAND "${H5DIFF}" -v --relative=1e-9 "${PRODUCED}" "${TEMPLATE}" "${target}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE error
)
if(result)
message(FATAL_ERROR "h5diff mismatch in ${target}:\n${output}${error}")
endif()
endforeach()
foreach(target IN LISTS error_datasets)
execute_process(
COMMAND "${H5DIFF}" -v --relative=1e-6 "${PRODUCED}" "${TEMPLATE}" "${target}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE error
)
if(result)
message(FATAL_ERROR "h5diff mismatch in ${target}:\n${output}${error}")
endif()
endforeach()
76 changes: 76 additions & 0 deletions test/post-build/in1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"Run": {
"max_no_ions": 100,
"threads": 0
},
"Transport": {
"flight_path_type": "Variable"
},
"IonBeam": {
"ion": {
"symbol": "Fe",
"atomic_mass": 55.935
},
"energy_distribution": {
"center": 2e6
},
"spatial_distribution": {
"center": [
0,
600,
600
]
}
},
"Target": {
"size": [
1200,
1200,
1200
],
"cell_count": [
100,
1,
1
],
"periodic_bc": [
0,
1,
1
],
"materials": [
{
"id": "Fe",
"density": 7.8658,
"composition": [
{
"element": {
"symbol": "Fe"
},
"X": 1,
"Ed": 40,
"El": 3,
"Es": 3,
"Er": 40,
"Rc": 0.8
}
]
}
],
"regions": [
{
"id": "R1",
"material_id": "Fe",
"size": [
1200,
1200,
1200
]
}
]
},
"Output": {
"title": "2MeV Fe on Fe",
"outfilename": "out1"
}
}
85 changes: 85 additions & 0 deletions test/post-build/in2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"Run": {
"max_no_ions": 50,
"threads": 0
},
"Simulation": {
"nrt_calculation": "NRT_average"
},
"IonBeam": {
"ion": {
"symbol": "Xe",
"atomic_mass": 131.904
},
"energy_distribution": {
"center": 3e6
},
"spatial_distribution": {
"center": [
0,
600,
600
]
}
},
"Target": {
"size": [
1200,
1200,
1200
],
"cell_count": [
100,
1,
1
],
"periodic_bc": [
0,
1,
1
],
"materials": [
{
"id": "Uranium oxide",
"density": 10.97,
"composition": [
{
"element": {
"symbol": "U"
},
"X": 1,
"Ed": 40,
"El": 4,
"Es": 4,
"Er": 20
},
{
"element": {
"symbol": "O"
},
"X": 2,
"Ed": 20,
"El": 2,
"Es": 2,
"Er": 20
}
]
}
],
"regions": [
{
"id": "R1",
"material_id": "Uranium oxide",
"size": [
1200,
1200,
1200
]
}
]
},
"Output": {
"title": "3MeV Xe on UO2",
"outfilename": "out2"
}
}
75 changes: 75 additions & 0 deletions test/post-build/in3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"Run": {
"max_no_ions": 10000,
"threads": 0
},
"Transport": {
"flight_path_type": "Variable"
},
"IonBeam": {
"ion": {
"symbol": "H",
"atomic_mass": 1.00784
},
"energy_distribution": {
"center": 3e6
},
"spatial_distribution": {
"center": [
0,
5000,
5000
]
}
},
"Target": {
"size": [
50000,
10000,
10000
],
"cell_count": [
100,
1,
1
],
"periodic_bc": [
0,
1,
1
],
"materials": [
{
"id": "Fe",
"density": 7.8658, // g/cm^3
"composition": [
{
"element": {
"symbol": "Fe"
},
"X": 1,
"Ed": 40,
"El": 3,
"Es": 3,
"Er": 40
}
]
}
],
"regions": [
{
"id": "R1",
"material_id": "Fe",
"size": [
50000,
10000,
10000
]
}
]
},
"Output": {
"title": "3 MeV H on Fe",
"outfilename": "out3"
}
}
Loading