Release 0.6.0
FemLite CI / build-test (push) Has been cancelled

This commit is contained in:
shenw
2026-07-01 20:44:15 +08:00
parent 2b7962eb96
commit 175531e24d
33 changed files with 2318 additions and 298 deletions
+221
View File
@@ -0,0 +1,221 @@
program test_nonlinear_lifecycle
use fem_precision
use fem_error
use fem_control
use fem_api, only: fem_initialize, fem_finalize
use fem_api_diagnostics, only: fem_get_nl_lifecycle_snapshot
use fem_nonlinear_lifecycle
implicit none
call check_event_names()
call check_empty_snapshot()
call check_recorded_snapshot()
call check_begin_increment()
call check_audit_core()
call check_api_snapshot()
contains
subroutine check_event_names()
character(len=64) :: name
call nl_lifecycle_event_name(NLC_EVENT_NONE, name)
if (trim(name) .ne. 'none') call fail(10)
call nl_lifecycle_event_name(NLC_EVENT_INCREMENT_BEGIN, name)
if (trim(name) .ne. 'increment-begin') call fail(11)
call nl_lifecycle_event_name(NLC_EVENT_TRIAL_BEGIN, name)
if (trim(name) .ne. 'trial-begin') call fail(12)
call nl_lifecycle_event_name(NLC_EVENT_ITERATION_BEGIN, name)
if (trim(name) .ne. 'iteration-begin') call fail(120)
call nl_lifecycle_event_name(NLC_EVENT_ITERATION_RESULT, name)
if (trim(name) .ne. 'iteration-result') call fail(13)
call nl_lifecycle_event_name(NLC_EVENT_ACCEPT, name)
if (trim(name) .ne. 'accept') call fail(14)
call nl_lifecycle_event_name(NLC_EVENT_REJECT, name)
if (trim(name) .ne. 'reject') call fail(15)
call nl_lifecycle_event_name(NLC_EVENT_CUTBACK, name)
if (trim(name) .ne. 'cutback') call fail(16)
call nl_lifecycle_event_name(NLC_EVENT_COMMIT, name)
if (trim(name) .ne. 'commit') call fail(17)
call nl_lifecycle_event_name(NLC_EVENT_ROLLBACK, name)
if (trim(name) .ne. 'rollback') call fail(18)
call nl_lifecycle_event_name(-999, name)
if (trim(name) .ne. 'unknown') call fail(19)
end subroutine check_event_names
subroutine check_empty_snapshot()
integer :: step
integer :: increment
integer :: iteration
integer :: event_id
integer :: reason_id
character(len=64) :: event_name
character(len=64) :: reason_name
real(rk) :: load_factor
real(rk) :: arc_residual
logical :: path_appended
call nl_lifecycle_reset()
call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, &
event_name, reason_id, reason_name)
call nl_lifecycle_get_arc_state(load_factor, arc_residual, path_appended)
if (nl_lifecycle_get_event_count() .ne. 0) call fail(29)
if (step .ne. 0) call fail(30)
if (increment .ne. 0) call fail(31)
if (iteration .ne. 0) call fail(32)
if (event_id .ne. NLC_EVENT_NONE) call fail(33)
if (trim(event_name) .ne. 'none') call fail(34)
if (reason_id .ne. NFAIL_NONE) call fail(35)
if (trim(reason_name) .ne. 'none') call fail(36)
if (abs(load_factor) .gt. 1.0e-14_rk) call fail(37)
if (abs(arc_residual) .gt. 1.0e-14_rk) call fail(38)
if (path_appended) call fail(39)
end subroutine check_empty_snapshot
subroutine check_recorded_snapshot()
integer :: step
integer :: increment
integer :: iteration
integer :: event_id
integer :: reason_id
character(len=64) :: event_name
character(len=64) :: reason_name
call nl_lifecycle_record_event(2, 3, 4, NLC_EVENT_TRIAL_BEGIN, &
NFAIL_LINE_SEARCH)
if (nl_lifecycle_get_event_count() .ne. 1) call fail(49)
call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, &
event_name, reason_id, reason_name)
if (step .ne. 2) call fail(50)
if (increment .ne. 3) call fail(51)
if (iteration .ne. 4) call fail(52)
if (event_id .ne. NLC_EVENT_TRIAL_BEGIN) call fail(53)
if (trim(event_name) .ne. 'trial-begin') call fail(54)
if (reason_id .ne. NFAIL_LINE_SEARCH) call fail(55)
if (trim(reason_name) .ne. 'line-search-failure') call fail(56)
call nl_lifecycle_get_event(1, step, increment, iteration, event_id, &
event_name, reason_id, reason_name)
if (step .ne. 2) call fail(57)
if (increment .ne. 3) call fail(58)
if (iteration .ne. 4) call fail(59)
if (event_id .ne. NLC_EVENT_TRIAL_BEGIN) call fail(60)
if (trim(event_name) .ne. 'trial-begin') call fail(61)
end subroutine check_recorded_snapshot
subroutine check_begin_increment()
integer :: step
integer :: increment
integer :: iteration
integer :: event_id
integer :: reason_id
character(len=64) :: event_name
character(len=64) :: reason_name
call nl_lifecycle_begin_increment(5, 6)
if (nl_lifecycle_get_event_count() .ne. 2) call fail(69)
call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, &
event_name, reason_id, reason_name)
if (step .ne. 5) call fail(70)
if (increment .ne. 6) call fail(71)
if (iteration .ne. 0) call fail(72)
if (event_id .ne. NLC_EVENT_INCREMENT_BEGIN) call fail(73)
if (trim(event_name) .ne. 'increment-begin') call fail(74)
if (reason_id .ne. NFAIL_NONE) call fail(75)
if (trim(reason_name) .ne. 'none') call fail(76)
end subroutine check_begin_increment
subroutine check_audit_core()
integer :: step
integer :: increment
integer :: iteration
integer :: event_id
integer :: reason_id
integer :: audit_status
integer :: begin_trial_count
integer :: rollback_requested_count
integer :: rollback_ok_count
integer :: rollback_failed_count
integer :: commit_ok_count
character(len=64) :: event_name
character(len=64) :: reason_name
character(len=64) :: audit_name
call nl_lifecycle_reset()
call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, &
event_name, reason_id, reason_name, audit_status, audit_name)
if (audit_status .ne. NLC_AUDIT_NONE) call fail(80)
if (trim(audit_name) .ne. 'none') call fail(81)
call nl_lifecycle_audit_status_name(NLC_AUDIT_ROLLBACK_FAILED, &
audit_name)
if (trim(audit_name) .ne. 'rollback-failed') call fail(82)
call nl_lifecycle_audit_status_name(-999, audit_name)
if (trim(audit_name) .ne. 'unknown') call fail(83)
call nl_lifecycle_record_audit(NLC_AUDIT_BEGIN_TRIAL)
call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_REQUESTED)
call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_OK)
call nl_lifecycle_record_audit(NLC_AUDIT_ROLLBACK_FAILED)
call nl_lifecycle_record_audit(NLC_AUDIT_COMMIT_OK)
call nl_lifecycle_get_audit(audit_status, audit_name, &
begin_trial_count, rollback_requested_count, rollback_ok_count, &
rollback_failed_count, commit_ok_count)
if (audit_status .ne. NLC_AUDIT_COMMIT_OK) call fail(84)
if (trim(audit_name) .ne. 'commit-ok') call fail(85)
if (begin_trial_count .ne. 1) call fail(86)
if (rollback_requested_count .ne. 1) call fail(87)
if (rollback_ok_count .ne. 1) call fail(88)
if (rollback_failed_count .ne. 1) call fail(89)
if (commit_ok_count .ne. 1) call fail(900)
call nl_lifecycle_get_snapshot(step, increment, iteration, event_id, &
event_name, reason_id, reason_name, audit_status, audit_name)
if (audit_status .ne. NLC_AUDIT_COMMIT_OK) call fail(901)
if (trim(audit_name) .ne. 'commit-ok') call fail(902)
end subroutine check_audit_core
subroutine check_api_snapshot()
integer :: ierr
integer :: step
integer :: increment
integer :: iteration
integer :: event_id
integer :: reason_id
character(len=64) :: event_name
character(len=64) :: reason_name
call fem_initialize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(90)
call fem_get_nl_lifecycle_snapshot(step, increment, iteration, &
event_id, event_name, reason_id, reason_name, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(91)
if (step .ne. 0) call fail(92)
if (increment .ne. 0) call fail(93)
if (iteration .ne. 0) call fail(94)
if (event_id .ne. NLC_EVENT_NONE) call fail(95)
if (trim(event_name) .ne. 'none') call fail(96)
call nl_lifecycle_record_event(7, 8, 9, NLC_EVENT_CUTBACK, &
NFAIL_MIN_STEP)
call fem_get_nl_lifecycle_snapshot(step, increment, iteration, &
event_id, event_name, reason_id, reason_name, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(97)
if (step .ne. 7) call fail(98)
if (increment .ne. 8) call fail(99)
if (iteration .ne. 9) call fail(100)
if (event_id .ne. NLC_EVENT_CUTBACK) call fail(101)
if (trim(event_name) .ne. 'cutback') call fail(102)
if (reason_id .ne. NFAIL_MIN_STEP) call fail(103)
if (trim(reason_name) .ne. 'minimum-step-exhausted') call fail(104)
call fem_finalize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(105)
end subroutine check_api_snapshot
subroutine fail(code)
integer, intent(in) :: code
write(*,*) 'test_nonlinear_lifecycle failed:', code
stop 1
end subroutine fail
end program test_nonlinear_lifecycle