Skip to content

Commit 37c53e3

Browse files
committed
initial fix for w5 velocity error
1 parent 6d6cc56 commit 37c53e3

File tree

6 files changed

+187
-55
lines changed

6 files changed

+187
-55
lines changed

source/equilibrium_test.pf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,17 @@ contains
470470
! Test the full solve
471471
call solver%solve(solution, 'uv', u_reac, v_reac, weights)
472472

473+
! write(*,*) "T = ", solution%T, " rel = ", &
474+
! abs((2418.5382574474097d0 - solution%T)/2418.5382574474097d0)
475+
! write(*,*) "ln_nj(1) = ", solution%ln_nj(1), " rel = ", &
476+
! abs((-52.374890133250204d0 - solution%ln_nj(1))/(-52.374890133250204d0))
477+
! write(*,*) "ln_nj(2) = ", solution%ln_nj(2), " rel = ", &
478+
! abs((-8.0940265640663025d0 - solution%ln_nj(2))/(-8.0940265640663025d0))
479+
! write(*,*) "ln_nj(3) = ", solution%ln_nj(3), " rel = ", &
480+
! abs((-42.957051147438705d0 - solution%ln_nj(3))/(-42.957051147438705d0))
481+
! write(*,*) "ln_nj(7) = ", solution%ln_nj(7), " rel = ", &
482+
! abs((-9.7591561204275976d0 - solution%ln_nj(7))/(-9.7591561204275976d0))
483+
473484
@assertRelativelyEqual(2418.5382574474097d0, solution%T, tol)
474485
@assertRelativelyEqual(-52.374890133250204d0, solution%ln_nj(1), tol)
475486
@assertRelativelyEqual(-8.0940265640663025d0, solution%ln_nj(2), tol)

source/input_test.pf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ contains
99
subroutine test_read_input
1010
type(ProblemDB), allocatable :: problems(:)
1111
allocate(problems(0))
12-
write(*,*) 'Testing read_input'
1312
!call set_log_level(log_levels%debug)
1413
problems = read_input('samples/rp1311_examples.inp')
1514
@assertEqual(14, size(problems))

source/main.f90

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ subroutine shock_output(ioout, prob, solver, solutions)
872872
real(dp) :: trace
873873
logical :: incident, reflected, equilibrium, frozen, input_reflected
874874
logical :: write_incd_frz, write_refl_frz, write_incd_eql, write_refl_eql
875-
logical :: use_mach
875+
logical :: use_mach, have_incident_state, have_reflected_state
876876
character(snl), allocatable :: trace_names(:)
877877
logical, allocatable :: is_trace(:)
878878
character(:), allocatable :: eq_fmt
@@ -945,7 +945,7 @@ subroutine shock_output(ioout, prob, solver, solutions)
945945
incd_type = "FROZEN "
946946
refl_type = "FROZEN "
947947
write_refl_eql = .false.
948-
if (reflected) then
948+
if (input_reflected) then
949949
write_refl_frz = .true.
950950
else
951951
write_refl_frz = .false.
@@ -1021,6 +1021,22 @@ subroutine shock_output(ioout, prob, solver, solutions)
10211021
end if
10221022
end if
10231023

1024+
have_incident_state = .false.
1025+
have_reflected_state = .false.
1026+
do i = 1, m
1027+
if (solutions(i, 1, k)%eq_soln(2)%T > 0.0d0) have_incident_state = .true.
1028+
if (solutions(i, 1, k)%eq_soln(3)%T > 0.0d0) have_reflected_state = .true.
1029+
end do
1030+
if (.not. have_incident_state) then
1031+
write_incd_frz = .false.
1032+
write_incd_eql = .false.
1033+
write_refl_frz = .false.
1034+
write_refl_eql = .false.
1035+
else if (.not. have_reflected_state) then
1036+
write_refl_frz = .false.
1037+
write_refl_eql = .false.
1038+
end if
1039+
10241040
! -------------------------------------------------------------------
10251041
! Write results for unshocked gas (equilibrium)
10261042
! -------------------------------------------------------------------

source/rocket_test.pf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ contains
4343
! Products order: H, H2, H2O, H2O2, HO2, O, O2, O3, OH, H2O(L), H2O(cr)
4444

4545
! Test the chamber conditions
46+
! write(*,*) "st1 T = ", soln%eq_soln(1)%T, " rel = ", &
47+
! abs((3383.8446259451043d0 - soln%eq_soln(1)%T)/3383.8446259451043d0)
48+
! write(*,*) "st1 ln_nj(H2) = ", soln%eq_soln(1)%ln_nj(2), " rel = ", &
49+
! abs((-3.7643107135196541d0 - soln%eq_soln(1)%ln_nj(2))/(-3.7643107135196541d0))
4650
@assertRelativelyEqual(3383.8446259451043d0, soln%eq_soln(1)%T, tol)
4751
@assertRelativelyEqual(-5.9391066300902899d0, soln%eq_soln(1)%ln_nj(1), tol)
4852
@assertRelativelyEqual(-3.7643107135196541d0, soln%eq_soln(1)%ln_nj(2), tol)
@@ -58,6 +62,10 @@ contains
5862
@assertRelativelyEqual(1.1446952882630981d0, soln%eq_partials(1)%gamma_s, tol)
5963

6064
! Test the throat conditions
65+
! write(*,*) "st2 T = ", soln%eq_soln(2)%T, " rel = ", &
66+
! abs((3185.6731730807096d0 - soln%eq_soln(2)%T)/3185.6731730807096d0)
67+
! write(*,*) "st2 ln_nj(H2) = ", soln%eq_soln(2)%ln_nj(2), " rel = ", &
68+
! abs((-3.7758918668469459d0 - soln%eq_soln(2)%ln_nj(2))/(-3.7758918668469459d0))
6169
@assertRelativelyEqual(3185.6731730807096d0, soln%eq_soln(2)%T, tol)
6270
@assertRelativelyEqual(-6.1821344716750914d0, soln%eq_soln(2)%ln_nj(1), tol)
6371
@assertRelativelyEqual(-3.7758918668469459d0, soln%eq_soln(2)%ln_nj(2), tol)
@@ -72,6 +80,10 @@ contains
7280
@assertEqual(0.0d0, soln%eq_soln(1)%nj(11), tol)
7381

7482
! Test the exit conditions (pi_p)
83+
! write(*,*) "st3 T = ", soln%eq_soln(3)%T, " rel = ", &
84+
! abs((2567.3401804441942d0 - soln%eq_soln(3)%T)/2567.3401804441942d0)
85+
! write(*,*) "st3 ln_nj(H2) = ", soln%eq_soln(3)%ln_nj(2), " rel = ", &
86+
! abs((-3.7880413204534467d0 - soln%eq_soln(3)%ln_nj(2))/(-3.7880413204534467d0))
7587
@assertRelativelyEqual(2567.3401804441942d0, soln%eq_soln(3)%T, tol)
7688
@assertRelativelyEqual(-7.4110702063645491d0, soln%eq_soln(3)%ln_nj(1), tol)
7789
@assertRelativelyEqual(-3.7880413204534467d0, soln%eq_soln(3)%ln_nj(2), tol)

source/shock.f90

Lines changed: 96 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,71 @@ subroutine ShockSolver_update_solution(self, soln, X1, X2, p21, t21, iter)
145145

146146
end subroutine
147147

148+
logical function ShockSolver_state_valid(soln, idx) result(valid)
149+
type(ShockSolution), intent(in) :: soln
150+
integer, intent(in) :: idx
151+
152+
valid = .false.
153+
if (idx < 1 .or. idx > soln%num_pts) return
154+
155+
valid = soln%eq_soln(idx)%converged .and. &
156+
soln%eq_soln(idx)%T > 0.0d0 .and. &
157+
soln%eq_soln(idx)%n > 0.0d0
158+
end function
159+
160+
subroutine ShockSolver_fail_state(soln, idx, message)
161+
type(ShockSolution), intent(inout) :: soln
162+
integer, intent(in) :: idx
163+
character(*), intent(in) :: message
164+
165+
if (len_trim(message) > 0) call log_warning(trim(message))
166+
call log_warning("Shock calculation stopped after the last valid point.")
167+
168+
soln%converged = .false.
169+
soln%pressure(idx) = 0.0d0
170+
soln%mach(idx) = 0.0d0
171+
soln%u(idx) = 0.0d0
172+
soln%v_sonic(idx) = 0.0d0
173+
soln%eq_soln(idx)%T = 0.0d0
174+
soln%eq_soln(idx)%n = 0.0d0
175+
soln%eq_soln(idx)%converged = .false.
176+
soln%eq_partials(idx)%dlnV_dlnP = 0.0d0
177+
soln%eq_partials(idx)%dlnV_dlnT = 0.0d0
178+
soln%eq_partials(idx)%gamma_s = 0.0d0
179+
180+
select case (idx)
181+
case (2)
182+
soln%rho12 = 0.0d0
183+
soln%p21 = 0.0d0
184+
soln%t21 = 0.0d0
185+
soln%M21 = 0.0d0
186+
soln%v2 = 0.0d0
187+
if (soln%num_pts >= 3) then
188+
soln%pressure(3) = 0.0d0
189+
soln%mach(3) = 0.0d0
190+
soln%u(3) = 0.0d0
191+
soln%v_sonic(3) = 0.0d0
192+
soln%eq_soln(3)%T = 0.0d0
193+
soln%eq_soln(3)%n = 0.0d0
194+
soln%eq_soln(3)%converged = .false.
195+
soln%eq_partials(3)%dlnV_dlnP = 0.0d0
196+
soln%eq_partials(3)%dlnV_dlnT = 0.0d0
197+
soln%eq_partials(3)%gamma_s = 0.0d0
198+
soln%rho52 = 0.0d0
199+
soln%p52 = 0.0d0
200+
soln%t52 = 0.0d0
201+
soln%M52 = 0.0d0
202+
soln%u5_p_v2 = 0.0d0
203+
end if
204+
case (3)
205+
soln%rho52 = 0.0d0
206+
soln%p52 = 0.0d0
207+
soln%t52 = 0.0d0
208+
soln%M52 = 0.0d0
209+
soln%u5_p_v2 = 0.0d0
210+
end select
211+
end subroutine
212+
148213
subroutine ShockSolver_solve_incident(self, soln, weights, T0, P0)
149214
! Solve the incident shock conditions
150215

@@ -198,6 +263,11 @@ subroutine ShockSolver_solve_incident(self, soln, weights, T0, P0)
198263

199264
soln%pressure(idx) = p21*P0
200265
call self%eq_solver%solve(soln%eq_soln(idx), "hp", h0, soln%pressure(idx), weights, partials=soln%eq_partials(idx))
266+
if (.not. ShockSolver_state_valid(soln, idx)) then
267+
call ShockSolver_fail_state(soln, idx, &
268+
"ShockSolver_solve_incident: incident equilibrium initialization failed.")
269+
return
270+
end if
201271

202272
t21 = soln%eq_soln(idx)%T/T0
203273
ttmax = 1.05*T_gas_max/T0
@@ -209,6 +279,11 @@ subroutine ShockSolver_solve_incident(self, soln, weights, T0, P0)
209279
T2 = t21*T0
210280

211281
call self%eq_solver%solve(soln%eq_soln(idx), "tp", T2, soln%pressure(idx), weights, partials=soln%eq_partials(idx))
282+
if (.not. ShockSolver_state_valid(soln, idx)) then
283+
call ShockSolver_fail_state(soln, idx, &
284+
"ShockSolver_solve_incident: incident equilibrium iteration failed.")
285+
return
286+
end if
212287

213288
! Update properties after the equilibrium shock
214289
wm_k = 1.0d0/soln%eq_soln(idx)%n
@@ -244,10 +319,8 @@ subroutine ShockSolver_solve_incident(self, soln, weights, T0, P0)
244319
call self%update_solution(soln, X(1), X(2), p21, t21, i)
245320

246321
if (i == 1 .and. .not. soln%converged .and. t21 >= ttmax) then
247-
call log_warning("ShockSolver_solve_incident: first-iteration update hit " // &
248-
"temperature cap; marking incident point as failed.")
249-
soln%eq_soln(idx)%T = 0.0d0
250-
soln%pressure(idx) = 0.0d0
322+
call ShockSolver_fail_state(soln, idx, "ShockSolver_solve_incident: first-iteration update hit " // &
323+
"temperature cap; marking incident point as failed.")
251324
return
252325
end if
253326

@@ -268,14 +341,7 @@ subroutine ShockSolver_solve_incident(self, soln, weights, T0, P0)
268341

269342
! Not converged; compute shock properties
270343
if (.not. soln%converged) then
271-
soln%rho12 = rho12
272-
soln%p21 = p21
273-
soln%t21 = t21
274-
soln%u(idx) = u1*rho12
275-
soln%M21 = wm_k/wm
276-
soln%mach(idx) = soln%M21*mach1
277-
soln%v_sonic(idx) = (R*T2*(cp/(cp - 1.0/wm_k))/wm_k)**0.5d0
278-
soln%v2 = u1 - soln%u(idx)
344+
call ShockSolver_fail_state(soln, idx, "ShockSolver_solve_incident: incident equilibrium solve did not converge.")
279345
end if
280346

281347
end subroutine
@@ -394,10 +460,8 @@ subroutine ShockSolver_solve_incident_frozen(self, soln, weights, T0, P0)
394460
call self%update_solution(soln, X(1), X(2), p21, t21, i)
395461

396462
if (i == 1 .and. .not. soln%converged .and. t21 >= ttmax) then
397-
call log_warning("ShockSolver_solve_incident_frozen: first-iteration update hit " // &
398-
"temperature cap; marking incident point as failed.")
399-
soln%eq_soln(idx)%T = 0.0d0
400-
soln%pressure(idx) = 0.0d0
463+
call ShockSolver_fail_state(soln, idx, "ShockSolver_solve_incident_frozen: first-iteration update hit " // &
464+
"temperature cap; marking incident point as failed.")
401465
return
402466
end if
403467

@@ -419,14 +483,7 @@ subroutine ShockSolver_solve_incident_frozen(self, soln, weights, T0, P0)
419483

420484
! Not converged; compute shock properties
421485
if (.not. soln%converged) then
422-
soln%rho12 = rho12
423-
soln%p21 = p21
424-
soln%t21 = t21
425-
soln%u(idx) = u1*rho12
426-
soln%M21 = wm_k/wm
427-
soln%mach(idx) = soln%M21*mach1
428-
soln%v_sonic(idx) = (R*T2*(cp/(cp - 1.0/wm_k))/wm_k)**0.5d0
429-
soln%v2 = u1 - soln%u(idx)
486+
call ShockSolver_fail_state(soln, idx, "ShockSolver_solve_incident_frozen: incident frozen solve did not converge.")
430487
end if
431488

432489
end subroutine
@@ -456,7 +513,7 @@ subroutine ShockSolver_solve_reflected(self, soln, weights, T0, P0)
456513
real(dp) :: G(2, 3) ! Solution matrix
457514
real(dp) :: X(3) ! Solution vector
458515
real(dp) :: dlnV_dlnP, dlnV_dlnT ! Partial derivatives
459-
real(dp) :: rho12 ! Ratios of chemical potential and density across the incident shock
516+
real(dp) :: rho12 ! Incident-shock density ratio carried into reflected solve
460517
real(dp) :: mu25rt, rho52 ! Ratios of chemical potential and density across the reflected shock
461518
real(dp) :: tmp ! Intermediate variabls
462519
real(dp), allocatable :: nj_g(:) ! Total/gas species concentrations [kmol-per-kg]
@@ -492,6 +549,11 @@ subroutine ShockSolver_solve_reflected(self, soln, weights, T0, P0)
492549
T5 = t52*T2
493550

494551
call self%eq_solver%solve(soln%eq_soln(idx), "tp", T5, soln%pressure(idx), weights, partials=soln%eq_partials(idx))
552+
if (.not. ShockSolver_state_valid(soln, idx)) then
553+
call ShockSolver_fail_state(soln, idx, &
554+
"ShockSolver_solve_reflected: reflected equilibrium iteration failed.")
555+
return
556+
end if
495557

496558
! Update properties after the equilibrium shock
497559
wm_k = 1.0d0/soln%eq_soln(idx)%n
@@ -531,10 +593,8 @@ subroutine ShockSolver_solve_reflected(self, soln, weights, T0, P0)
531593
call self%update_solution(soln, X(1), X(2), p52, t52, i)
532594

533595
if (i == 1 .and. .not. soln%converged .and. t52 >= ttmax) then
534-
call log_warning("ShockSolver_solve_reflected: first-iteration update hit " // &
535-
"temperature cap; marking reflected point as failed.")
536-
soln%eq_soln(idx)%T = 0.0d0
537-
soln%pressure(idx) = 0.0d0
596+
call ShockSolver_fail_state(soln, idx, "ShockSolver_solve_reflected: first-iteration update hit " // &
597+
"temperature cap; marking reflected point as failed.")
538598
return
539599
end if
540600

@@ -555,14 +615,7 @@ subroutine ShockSolver_solve_reflected(self, soln, weights, T0, P0)
555615

556616
! Not converged; compute shock properties
557617
if (.not. soln%converged) then
558-
soln%rho52 = rho52
559-
soln%p52 = p52
560-
soln%t52 = t52
561-
soln%u(idx) = (u1 - u1*rho12)/rho52
562-
soln%M52 = wm_k/wm
563-
soln%mach(idx) = soln%M52*soln%mach(2)
564-
soln%u5_p_v2 = (u1 - u1*rho12)*(1.0d0-1.0d0/rho52)
565-
soln%v_sonic(idx) = (R*T5*(cp/(cp - 1.0/wm_k))/wm_k)**0.5d0
618+
call ShockSolver_fail_state(soln, idx, "ShockSolver_solve_reflected: reflected equilibrium solve did not converge.")
566619
end if
567620

568621
end subroutine
@@ -594,6 +647,7 @@ subroutine ShockSolver_solve_reflected_frozen(self, soln, weights, T0, P0)
594647
real(dp) :: dlnV_dlnP, dlnV_dlnT ! Partial derivatives
595648
real(dp) :: rho12 ! Ratios of chemical potential and density across the incident shock
596649
real(dp) :: mu25rt, rho52 ! Ratios of chemical potential and density across the reflected shock
650+
real(dp) :: rho25_inv ! Reflected-shock inverse density ratio used in the Newton system
597651
real(dp) :: tmp ! Intermediate variabls
598652
integer, parameter :: max_iter = 60
599653
real(dp), parameter :: T_gas_max = 20000.d0 ! Max gas temperature in the thermo database [K]
@@ -652,8 +706,8 @@ subroutine ShockSolver_solve_reflected_frozen(self, soln, weights, T0, P0)
652706
dlnV_dlnP = soln%eq_partials(idx)%dlnV_dlnP
653707
dlnV_dlnT = soln%eq_partials(idx)%dlnV_dlnT
654708

655-
rho12 = wm*t52/(wm_k*p52)
656-
rho52 = 1./rho12
709+
rho25_inv = wm*t52/(wm_k*p52)
710+
rho52 = 1./rho25_inv
657711
soln%rho52 = rho52
658712
tmp = -mu25rt*rho52/(rho52 - 1.0d0)**2
659713

@@ -677,10 +731,8 @@ subroutine ShockSolver_solve_reflected_frozen(self, soln, weights, T0, P0)
677731
call self%update_solution(soln, X(1), X(2), p52, t52, i)
678732

679733
if (i == 1 .and. .not. soln%converged .and. t52 >= ttmax) then
680-
call log_warning("ShockSolver_solve_reflected_frozen: first-iteration update hit " // &
681-
"temperature cap; marking reflected point as failed.")
682-
soln%eq_soln(idx)%T = 0.0d0
683-
soln%pressure(idx) = 0.0d0
734+
call ShockSolver_fail_state(soln, idx, "ShockSolver_solve_reflected_frozen: first-iteration update hit " // &
735+
"temperature cap; marking reflected point as failed.")
684736
return
685737
end if
686738

@@ -701,14 +753,7 @@ subroutine ShockSolver_solve_reflected_frozen(self, soln, weights, T0, P0)
701753

702754
! Not converged; compute shock properties
703755
if (.not. soln%converged) then
704-
soln%rho52 = rho52
705-
soln%p52 = p52
706-
soln%t52 = t52
707-
soln%u(idx) = soln%v2/rho52
708-
soln%M52 = wm_k/wm
709-
soln%mach(idx) = soln%M52*soln%mach(2)
710-
soln%u5_p_v2 = (u1 - u1*rho12)*(1.0d0-1.0d0/rho52)
711-
soln%v_sonic(idx) = (R*T5*(cp/(cp - 1.0/wm_k))/wm_k)**0.5d0
756+
call ShockSolver_fail_state(soln, idx, "ShockSolver_solve_reflected_frozen: reflected frozen solve did not converge.")
712757
end if
713758

714759
end subroutine

0 commit comments

Comments
 (0)