Skip to content

Commit 159f02c

Browse files
authored
Fix/rocket fail gracefully (#62)
* fixed rocket failure path
1 parent ce9ed9e commit 159f02c

File tree

5 files changed

+403
-122
lines changed

5 files changed

+403
-122
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ All notable user-visible changes to this project are documented here.
66

77
### Changed
88
- Legacy CLI `.out` files now echo each problem’s original input block before the corresponding equilibrium, rocket, shock, or detonation output section.
9+
- Frozen rocket failure handling was aligned with the established partial-output behavior: successful upstream stations are retained, output truncates at the last valid station, and the existing warning text is emitted after the partial report.
10+
- Frozen rocket stop checks now use the active thermo-fit interval for condensed species plus the existing lower-temperature frozen-fit guard, and frozen retained points now populate transport properties before output.
911

1012
### Fixed
13+
- Non-converging frozen rocket cases no longer produce empty output, overrun into invalid exit columns, or crash while writing partial results.
14+
- Difficult frozen rocket chamber solves can now retain a usable reduced-component state after repeated singular matrices, restoring partial output for reproduced failure cases.
1115

1216
### Added
1317

source/equilibrium.f90

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ module cea_equilibrium
9191
procedure :: test_condensed => EqSolver_test_condensed
9292
procedure :: correct_singular => EqSolver_correct_singular
9393
procedure :: update_transport_basis => EqSolver_update_transport_basis
94+
procedure :: compute_transport_state => EqSolver_compute_transport_state
9495
procedure :: assemble_matrix => EqSolver_assemble_matrix
9596
procedure :: post_process => EqSolver_post_process
9697
procedure :: solve => EqSolver_solve
@@ -739,6 +740,15 @@ subroutine EqSolver_restore_reduced_elements(self, soln, num_swaps, swap_from, s
739740
self%reduced_elements = 0
740741
end subroutine
741742

743+
subroutine EqSolver_compute_transport_state(self, soln)
744+
class(EqSolver), intent(in) :: self
745+
type(EqSolution), intent(inout) :: soln
746+
747+
if (.not. self%transport) return
748+
call self%update_transport_basis(soln)
749+
call compute_transport_properties(self, soln)
750+
end subroutine
751+
742752
function EqSolver_compute_damped_update_factor(self, soln) result(lambda)
743753
! Compute the damped update factor, lambda, for the Newton solver
744754

@@ -1865,7 +1875,7 @@ subroutine EqSolver_test_condensed(self, soln, iter, singular_index)
18651875

18661876
end subroutine
18671877

1868-
subroutine EqSolver_correct_singular(self, soln, iter, ierr, singular_index, reduced_from, reduced_to)
1878+
subroutine EqSolver_correct_singular(self, soln, iter, ierr, singular_index, reduced_from, reduced_to, times_singular)
18691879
! Try to correct the singular Jacobian matrix
18701880

18711881
! Arguments
@@ -1876,6 +1886,7 @@ subroutine EqSolver_correct_singular(self, soln, iter, ierr, singular_index, red
18761886
integer, intent(out), optional :: singular_index
18771887
integer, intent(out), optional :: reduced_from
18781888
integer, intent(out), optional :: reduced_to
1889+
integer, intent(in), optional :: times_singular
18791890

18801891
! Locals
18811892
integer :: i, j, k ! Iterators
@@ -2013,7 +2024,8 @@ subroutine EqSolver_correct_singular(self, soln, iter, ierr, singular_index, red
20132024
end if
20142025

20152026
! Component-reduction fallback for persistent element-row singularities.
2016-
if (.not. made_change .and. ierr >= 1 .and. ierr <= ne .and. iter < 1 .and. &
2027+
if (.not. made_change .and. ierr >= 1 .and. ierr <= ne .and. &
2028+
(iter < 1 .or. (present(times_singular) .and. times_singular >= 4)) .and. &
20172029
ne > 1 .and. .not. (self%ions .and. self%active_ions)) then
20182030
call log_info("Reducing active element equations after singular restart on "// &
20192031
trim(self%products%element_names(ierr)))
@@ -2458,10 +2470,21 @@ subroutine EqSolver_solve(self, soln, type, state1, state2, reactant_weights, pa
24582470
times_singular = times_singular + 1
24592471
if (times_singular > 8) then
24602472
soln%converged = .false.
2461-
if (EqSolution_has_transport_seed(soln)) then
2462-
call EqSolution_restore_seed(soln)
2463-
else if (soln%T > 0.0d0 .and. soln%n > 0.0d0) then
2464-
call EqSolution_restore_transport_seed(soln)
2473+
if (num_reduced > 0 .and. soln%T > 0.0d0 .and. soln%n > 0.0d0) then
2474+
! Retain the reduced-component state at the current
2475+
! point after repeated singular matrices instead of
2476+
! restoring the previous seed.
2477+
if (self%transport) then
2478+
call self%update_transport_basis(soln)
2479+
call compute_transport_properties(self, soln)
2480+
end if
2481+
call self%post_process(soln, .false.)
2482+
else
2483+
if (EqSolution_has_transport_seed(soln)) then
2484+
call EqSolution_restore_seed(soln)
2485+
else if (soln%T > 0.0d0 .and. soln%n > 0.0d0) then
2486+
call EqSolution_restore_transport_seed(soln)
2487+
end if
24652488
end if
24662489
call EqSolver_restore_reduced_elements(self, soln, num_reduced, reduced_from, reduced_to)
24672490
call log_warning('EqSolver_solve: Too many singular matrices encountered.')
@@ -2472,7 +2495,8 @@ subroutine EqSolver_solve(self, soln, type, state1, state2, reactant_weights, pa
24722495
singular_index_iter = 0
24732496
reduced_from_iter = 0
24742497
reduced_to_iter = 0
2475-
call self%correct_singular(soln, iter, ierr, singular_index_iter, reduced_from_iter, reduced_to_iter)
2498+
call self%correct_singular(soln, iter, ierr, singular_index_iter, reduced_from_iter, reduced_to_iter, &
2499+
times_singular)
24762500
if (singular_index_iter > 0) singular_index = singular_index_iter
24772501
if (reduced_to_iter > 0) then
24782502
num_reduced = num_reduced + 1
@@ -5063,7 +5087,7 @@ subroutine compute_transport_properties(eq_solver, eq_soln, frozen_shock)
50635087
! Compute the transport properties of a mixture for a given equilibrium solution
50645088

50655089
! Arguments
5066-
class(EqSolver), target :: eq_solver
5090+
class(EqSolver), intent(in), target :: eq_solver
50675091
type(EqSolution), intent(inout) :: eq_soln
50685092
logical, intent(in), optional :: frozen_shock ! TODO: Estimate mole fractions for a frozen shock problem
50695093

0 commit comments

Comments
 (0)