v0.16.3
Loading...
Searching...
No Matches
RunAuxiliaryRestart.cmake
Go to the documentation of this file.
1# Run from the test's private working directory, containing examples,
2# param_file.petsc and the common JSON fixture. Each stage keeps its own files.
3foreach(required EP_MPI_RUN EP_EXECUTABLE EP_COMPARATOR EP_RANKS)
4 if(NOT DEFINED ${required} OR "${${required}}" STREQUAL "")
5 message(FATAL_ERROR "RunAuxiliaryRestart requires ${required}")
6 endif()
7endforeach()
8if(NOT EP_RANKS MATCHES "^[12]$")
9 message(FATAL_ERROR "Auxiliary restart test supports one or two ranks")
10endif()
11if(NOT DEFINED EP_CONFIG)
12 set(EP_CONFIG "ep_cook_auxiliary_logarithmic_stress.json")
13endif()
14if(NOT DEFINED EP_COMPARE_TOLERANCE)
15 set(EP_COMPARE_TOLERANCE 1e-9)
16endif()
17get_filename_component(test_directory "." ABSOLUTE)
18get_filename_component(config_file "${EP_CONFIG}" ABSOLUTE)
19file(READ "${config_file}" configuration)
20if(EP_RANKS EQUAL 1)
21 string(JSON configuration SET "${configuration}" meshes 0 file_name
22 "\"examples/cook_cantilever/cook.cub\"")
23endif()
24
25foreach(stage uninterrupted initial resumed missing_metadata wrong_formulation)
26 set(stage_directory "${test_directory}/${stage}")
27 file(MAKE_DIRECTORY "${stage_directory}")
28 file(WRITE "${stage_directory}/input.json" "${configuration}\n")
29 configure_file("${test_directory}/param_file.petsc"
30 "${stage_directory}/param_file.petsc" COPYONLY)
31 if(NOT EXISTS "${stage_directory}/examples")
32 file(CREATE_LINK "${test_directory}/examples"
33 "${stage_directory}/examples" SYMBOLIC RESULT link_result)
34 if(NOT link_result STREQUAL "0")
35 message(FATAL_ERROR "Cannot link ${stage} mesh fixtures: ${link_result}")
36 endif()
37 endif()
38 file(REMOVE "${stage_directory}/final.vec"
39 "${stage_directory}/final.vec.info")
40endforeach()
41
42function(run_auxiliary_restart_stage stage expected_error)
43 set(stage_directory "${test_directory}/${stage}")
44 execute_process(
45 COMMAND "${EP_MPI_RUN}" ${EP_MPI_RUN_FLAGS} -np "${EP_RANKS}"
46 "${EP_EXECUTABLE}" -json_config input.json ${EP_OPTIONS} ${ARGN}
47 WORKING_DIRECTORY "${stage_directory}"
48 RESULT_VARIABLE run_result
49 OUTPUT_FILE "${stage_directory}/run.log"
50 ERROR_FILE "${stage_directory}/run.log"
51 TIMEOUT 180)
52 file(READ "${stage_directory}/run.log" run_log)
53 if(expected_error STREQUAL "")
54 if(NOT run_result STREQUAL "0")
55 message(FATAL_ERROR
56 "Auxiliary ${stage} solve failed (${run_result}):\n${run_log}")
57 endif()
58 if(NOT EXISTS "${stage_directory}/final.vec")
59 message(FATAL_ERROR "Auxiliary ${stage} solve did not save its final vector")
60 endif()
61 else()
62 string(FIND "${run_log}" "${expected_error}" diagnostic_position)
63 if(NOT run_result MATCHES "^[1-9][0-9]*$" OR
64 diagnostic_position LESS 0)
65 message(FATAL_ERROR
66 "Expected ${stage} failure '${expected_error}', got '${run_result}':\n${run_log}")
67 endif()
68 endif()
69endfunction()
70
71set(final_vector_option -elastic_snes_view_solution binary:final.vec)
72file(REMOVE "${test_directory}/initial/restart_1.dat"
73 "${test_directory}/initial/restart_1.dat.layout.json")
74run_auxiliary_restart_stage(uninterrupted ""
75 -time 0 -write_restart 0
76 -elastic_ts_dt 0.05 -elastic_ts_max_time 0.1 -elastic_ts_max_steps 2
77 ${final_vector_option})
78run_auxiliary_restart_stage(initial ""
79 -time 0 -write_restart 1 -write_restart_every 1
80 -elastic_ts_dt 0.05 -elastic_ts_max_time 0.05 -elastic_ts_max_steps 1
81 ${final_vector_option})
82
83set(checkpoint "${test_directory}/initial/restart_1.dat")
84set(metadata "${checkpoint}.layout.json")
85if(NOT EXISTS "${checkpoint}" OR NOT EXISTS "${metadata}")
86 message(FATAL_ERROR "Initial auxiliary solve did not write a native restart pair")
87endif()
88file(READ "${metadata}" layout)
89string(JSON formulation GET "${layout}" formulation)
90if(NOT formulation STREQUAL "auxiliary_logarithmic_stress")
91 message(FATAL_ERROR "Checkpoint does not identify the auxiliary formulation")
92endif()
93configure_file("${checkpoint}"
94 "${test_directory}/resumed/restart_1.dat" COPYONLY)
95configure_file("${metadata}"
96 "${test_directory}/resumed/restart_1.dat.layout.json" COPYONLY)
97
98# ep.cpp derives start_step=1 from restart_1.dat, while -time provides .05.
99# TS max_steps is the final total step count, so the resumed run still uses 2.
100run_auxiliary_restart_stage(resumed ""
101 -restart restart_1.dat -time 0.05 -write_restart 0
102 -elastic_ts_dt 0.05 -elastic_ts_max_time 0.1 -elastic_ts_max_steps 2
103 ${final_vector_option})
104execute_process(
105 COMMAND "${EP_MPI_RUN}" ${EP_MPI_RUN_FLAGS} -np "${EP_RANKS}"
106 "${EP_COMPARATOR}"
107 -compare_left "${test_directory}/uninterrupted/final.vec"
108 -compare_right "${test_directory}/resumed/final.vec"
109 -compare_count 1 -compare_tolerance "${EP_COMPARE_TOLERANCE}"
110 RESULT_VARIABLE comparison_result
111 OUTPUT_FILE "${test_directory}/comparison.log"
112 ERROR_FILE "${test_directory}/comparison.log"
113 TIMEOUT 60)
114if(NOT comparison_result STREQUAL "0")
115 file(READ "${test_directory}/comparison.log" comparison_log)
116 message(FATAL_ERROR "Auxiliary restart comparison failed:\n${comparison_log}")
117endif()
118
119# Invalid vector bytes establish that metadata is checked before VecLoad.
120# The original checkpoint and its metadata remain intact in initial/.
121foreach(stage missing_metadata wrong_formulation)
122 file(WRITE "${test_directory}/${stage}/restart_1.dat"
123 "This fixture is deliberately not a PETSc vector.\n")
124endforeach()
125file(REMOVE "${test_directory}/missing_metadata/restart_1.dat.layout.json")
126string(JSON wrong_layout SET "${layout}" formulation "\"direct_stretch\"")
127file(WRITE "${test_directory}/wrong_formulation/restart_1.dat.layout.json"
128 "${wrong_layout}\n")
129run_auxiliary_restart_stage(missing_metadata
130 "Auxiliary logarithmic-stress restart requires"
131 -restart restart_1.dat -time 0.05 -write_restart 0)
132run_auxiliary_restart_stage(wrong_formulation
133 "Restart layout mismatch for 'formulation'"
134 -restart restart_1.dat -time 0.05 -write_restart 0)
135
136message(STATUS
137 "Auxiliary ${EP_RANKS}-rank restart matches the uninterrupted solve; missing and incompatible metadata fail before vector loading")