4This is a standalone Riemann solver, based on the exact Riemann solver that is
5part of Shadowfax (https://github.com/AstroUGent/shadowfax), CMacIonize
6(https://github.com/bwvdnbro/CMacIonize) and SWIFT.
8It is based on the description given in Toro, E., Riemann Solvers and
9Numerical Methods for Fluid Dynamics, 3rd edition (Springer, 2009).
11This file should not be run directly (it just runs some unit tests if this is
12done). Instead, include it in another script as follows:
14(make sure the folder containing the file is part of the system PATH).
16Once included, you can create a RiemannSolver object for an ideal gas with a
17given polytropic index (e.g. 5/3):
18solver = riemannsolver.RiemannSolver(5./3.)
19This object has a member function solve which can be used to solve the Riemann
20problem with a given left and right state:
21rhosol, usol, psol, flag = solver.solver(rhoL, uL, pL, rhoR, uR, pR)
22rhosol, rhoL, and rhoR are the densities of respectively the solution, the
23left state, and the right state.
24usol, uL, and uR are the fluid velocities
25psol, pL, and pR are the pressures
26flag is an extra return variable that is set to -1, 1, or 0 if respectively
27the left state, the right state, or a vacuum state was sampled.
29By default, the Riemann solution is sampled for a reference velocity dxdt = 0.
30Alternatively, you can sample the solution for another reference velocity
31dxdt = x / t by providing dxdt as an extra argument to solve().
39 @brief Exact Riemann solver.
46 @param gamma Adiabatic index \f$\gamma{}\f$.
50 print(
"The adiabatic index needs to be larger than 1!")
57 self.
_gp1d2g = 0.5 * (gamma + 1.0) / gamma
59 self.
_gm1d2g = 0.5 * (gamma - 1.0) / gamma
69 self.
_tgdgm1 = 2.0 * gamma / (gamma - 1.0)
75 @brief Get the soundspeed corresponding to the given density and pressure.
77 @param rho Density value.
78 @param P Pressure value.
82 return np.sqrt(self.
_gamma * P / rho)
86 def fb(self, rho, P, a, Pstar):
88 @brief Riemann fL or fR function.
90 @param rho Density of the left or right state.
91 @param P Pressure of the left or right state.
92 @param a Soundspeed of the left or right state.
93 @param Pstar (Temporary) pressure of the middle state.
94 @return Value of the fL or fR function.
99 fval = (Pstar - P) * np.sqrt(A / (Pstar + B))
101 fval = self.
_tdgm1 * a * ((Pstar / P) ** (self.
_gm1d2g) - 1.0)
105 def f(self, rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pstar):
107 @brief Riemann f function.
109 @param rhoL Density of the left state.
110 @param uL Velocity of the left state.
111 @param PL Pressure of the left state.
112 @param aL Soundspeed of the left state.
113 @param rhoR Density of the right state.
114 @param uR Velocity of the right state.
115 @param PR Pressure of the right state.
116 @param aR Soundspeed of the right state.
117 @param Pstar (Temporary) pressure of the middle state.
118 @return Value of the Riemann f function.
120 return self.
fb(rhoL, PL, aL, Pstar) + self.
fb(rhoR, PR, aR, Pstar) + (uR - uL)
124 @brief Derivative of the Riemann fL or fR function.
126 @param rho Density of the left or right state.
127 @param P Pressure of the left or right state.
128 @param a Soundspeed of the left or right state.
129 @param Pstar (Temporary) pressure of the middle state.
130 @return Value of the derivative of the Riemann fL or fR function.
135 fval = (1.0 - 0.5 * (Pstar - P) / (B + Pstar)) * np.sqrt(A / (Pstar + B))
137 fval = 1.0 / (rho * a) * (Pstar / P) ** (-self.
_gp1d2g)
141 def fprime(self, rhoL, PL, aL, rhoR, PR, aR, Pstar):
143 @brief Derivative of the Riemann f function.
145 @param rhoL Density of the left state.
146 @param PL Pressure of the left state.
147 @param aL Soundspeed of the left state.
148 @param rhoR Density of the right state.
149 @param PR Pressure of the right state.
150 @param aR Soundspeed of the right state.
151 @param Pstar (Temporary) pressure of the middle state.
152 @return Value of the derivative of the Riemann f function.
154 return self.
fprimeb(rhoL, PL, aL, Pstar) + self.
fprimeb(rhoR, PR, aR, Pstar)
156 def gb(self, rho, P, Pstar):
158 @brief Riemann gL or gR function.
160 @param rho Density of the left or right state.
161 @param P Pressure of the left or right state.
162 @param Pstar (Temporary) pressure in the middle state.
163 @return Value of the gL or gR function.
167 return np.sqrt(A / (Pstar + B))
169 def guess_P(self, rhoL, uL, PL, aL, rhoR, uR, PR, aR):
171 @brief Get an initial guess for the pressure in the middle state.
173 @param rhoL Left state density.
174 @param uL Left state velocity.
175 @param PL Left state pressure.
176 @param aL Left state soundspeed.
177 @param rhoR Right state density.
178 @param uR Right state velocity.
179 @param PR Right state pressure.
180 @param aR Right state soundspeed.
181 @return Initial guess for the pressure in the middle state.
186 Ppv = 0.5 * (PL + PR) - 0.125 * (uR - uL) * (PL + PR) * (aL + aR)
187 Ppv = max(5.0e-9 * (PL + PR), Ppv)
188 if qmax <= 2
and Pmin <= Ppv
and Ppv <= Pmax:
194 (aL + aR - self.
_gm1d2 * (uR - uL))
199 gL = self.
gb(rhoL, PL, Ppv)
200 gR = self.
gb(rhoR, PR, Ppv)
201 Pguess = (gL * PL + gR * PR - uR + uL) / (gL + gR)
207 Pguess = max(5.0e-9 * (PL + PR), Pguess)
210 def solve_brent(self, rhoL, uL, PL, aL, rhoR, uR, PR, aR, Plow, Phigh):
212 @brief Find the pressure of the middle state by using Brent's method.
214 @param rhoL Density of the left state.
215 @param uL Velocity of the left state.
216 @param PL Pressure of the left state.
217 @param aL Soundspeed of the left state.
218 @param rhoR Density of the right state.
219 @param uR Velocity of the right state.
220 @param PR Pressure of the right state.
221 @param aR Soundspeed of the right state.
222 @param Plow Lower bound guess for the pressure of the middle state.
223 @param Phigh Higher bound guess for the pressure of the middle state.
224 @return Pressure of the middle state, with a 1.e-8 relative error precision.
231 fa = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, a)
232 fb = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, b)
239 print(
"Equal sign function values provided to solve_brent!")
243 if abs(fa) < abs(fb):
255 while (
not fb == 0.0)
and (abs(a - b) > 5.0e-9 * (a + b)):
256 if (
not fa == fc)
and (
not fb == fc):
259 a * fb * fc / (fa - fb) / (fa - fc)
260 + b * fa * fc / (fb - fa) / (fb - fc)
261 + c * fa * fb / (fc - fa) / (fc - fb)
265 s = b - fb * (b - a) / (fb - fa)
267 tmp2 = 0.25 * (3.0 * a + b)
269 (
not (((s > tmp2)
and (s < b))
or ((s < tmp2)
and (s > b))))
270 or (mflag
and (abs(s - b) >= 0.5 * abs(b - c)))
271 or ((
not mflag)
and (abs(s - b) >= 0.5 * abs(c - d)))
272 or (mflag
and (abs(b - c) < 5.0e-9 * (b + c)))
273 or ((
not mflag)
and (abs(c - d) < 5.0e-9 * (c + d)))
279 fs = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, s)
291 if abs(fa) < abs(fb):
302 self, rhoR, uR, PR, aR, ustar, Pstar, dxdt=np.array([0.0])
305 @brief Sample the Riemann problem solution for a position in the right
308 @param rhoR Density of the right state.
309 @param uR Velocity of the right state.
310 @param PR Pressure of the right state.
311 @param aR Soundspeed of the right state.
312 @param ustar Velocity of the middle state.
313 @param Pstar Pressure of the middle state.
314 @param rhosol Density solution.
315 @param usol Velocity solution.
316 @param Psol Pressure solution.
317 @param dxdt Point in velocity space where we want to sample the solution.
318 @return Density, velocity and pressure solution.
320 rhosol = np.zeros(dxdt.shape)
321 usol = np.zeros(dxdt.shape)
322 Psol = np.zeros(dxdt.shape)
328 middle_state = SR > dxdt
329 right_state = ~middle_state
331 rhosol[middle_state] = (
334 usol[middle_state] = ustar
335 Psol[middle_state] = Pstar
337 rhosol[right_state] = rhoR
338 usol[right_state] = uR
339 Psol[right_state] = PR
341 return rhosol, usol, Psol
344 self, rhoR, uR, PR, aR, ustar, Pstar, dxdt=np.array([0.0])
347 @brief Sample the Riemann problem solution for a position in the right
348 rarefaction wave regime.
350 @param rhoR Density of the right state.
351 @param uR Velocity of the right state.
352 @param PR Pressure of the right state.
353 @param aR Soundspeed of the right state.
354 @param ustar Velocity of the middle state.
355 @param Pstar Pressure of the middle state.
356 @param dxdt Point in velocity space where we want to sample the solution.
357 @return Density, velocity and pressure solution.
359 rhosol = np.zeros(dxdt.shape)
360 usol = np.zeros(dxdt.shape)
361 Psol = np.zeros(dxdt.shape)
365 rarefaction_regime = SHR > dxdt
366 right_state = ~rarefaction_regime
371 STR = ustar + aR * PdPR**self.
_gm1d2g
372 middle_state = rarefaction_regime & (STR > dxdt)
373 rarefaction_fan = rarefaction_regime & (~middle_state)
375 rhosol[middle_state] = rhoR * PdPR**self.
_ginv
376 usol[middle_state] = ustar
377 Psol[middle_state] = Pstar
380 base = self.
_tdgp1 - self.
_gm1dgp1 * (uR - dxdt[rarefaction_fan]) / aR
381 rhosol[rarefaction_fan] = rhoR * base**self.
_tdgm1
382 usol[rarefaction_fan] = self.
_tdgp1 * (
383 -aR + self.
_gm1d2 * uR + dxdt[rarefaction_fan]
385 Psol[rarefaction_fan] = PR * base**self.
_tgdgm1
387 rhosol[right_state] = rhoR
388 usol[right_state] = uR
389 Psol[right_state] = PR
391 return rhosol, usol, Psol
395 @brief Sample the Riemann problem solution in the right state regime.
397 @param rhoR Density of the right state.
398 @param uR Velocity of the right state.
399 @param PR Pressure of the right state.
400 @param aR Soundspeed of the right state.
401 @param ustar Velocity of the middle state.
402 @param Pstar Pressure of the middle state.
403 @param dxdt Point in velocity space where we want to sample the solution.
404 @return Density, velocity and pressure solution.
409 rhoR, uR, PR, aR, ustar, Pstar, dxdt
414 rhoR, uR, PR, aR, ustar, Pstar, dxdt
417 return rhosol, usol, Psol
420 self, rhoL, uL, PL, aL, ustar, Pstar, dxdt=np.array([0.0])
423 @brief Sample the Riemann problem solution for a position in the left shock
426 @param rhoL Density of the left state.
427 @param uL Velocity of the left state.
428 @param PL Pressure of the left state.
429 @param aL Soundspeed of the left state.
430 @param ustar Velocity of the middle state.
431 @param Pstar Pressure of the middle state.
432 @param dxdt Point in velocity space where we want to sample the solution.
433 @return Density, velocity and pressure solution.
435 rhosol = np.zeros(dxdt.shape)
436 usol = np.zeros(dxdt.shape)
437 Psol = np.zeros(dxdt.shape)
443 middle_state = SL < dxdt
444 left_state = ~middle_state
445 if np.any(middle_state):
447 rhosol[middle_state] = (
450 usol[middle_state] = ustar
451 Psol[middle_state] = Pstar
452 if np.any(left_state):
454 rhosol[left_state] = rhoL
455 usol[left_state] = uL
456 Psol[left_state] = PL
458 return rhosol, usol, Psol
461 self, rhoL, uL, PL, aL, ustar, Pstar, dxdt=np.array([0.0])
464 @brief Sample the Riemann problem solution for a position in the left
465 rarefaction wave regime.
467 @param rhoL Density of the left state.
468 @param uL Velocity of the left state.
469 @param PL Pressure of the left state.
470 @param aL Soundspeed of the left state.
471 @param ustar Velocity of the middle state.
472 @param Pstar Pressure of the middle state.
473 @param dxdt Point in velocity space where we want to sample the solution.
474 @return Density, velocity and pressure solution.
476 rhosol = np.zeros(dxdt.shape)
477 usol = np.zeros(dxdt.shape)
478 Psol = np.zeros(dxdt.shape)
482 rarefaction_wave = SHL < dxdt
483 left_state = ~rarefaction_wave
484 if np.any(rarefaction_wave):
489 STL = ustar - aL * PdPL**self.
_gm1d2g
490 rarefaction_fan = rarefaction_wave & (STL > dxdt)
491 middle_state = rarefaction_wave & (~rarefaction_fan)
492 if np.any(rarefaction_fan):
495 base = self.
_tdgp1 + self.
_gm1dgp1 * (uL - dxdt[rarefaction_fan]) / aL
496 rhosol[rarefaction_fan] = rhoL * base**self.
_tdgm1
497 usol[rarefaction_fan] = self.
_tdgp1 * (
498 aL + self.
_gm1d2 * uL + dxdt[rarefaction_fan]
500 Psol[rarefaction_fan] = PL * base**self.
_tgdgm1
501 if np.any(middle_state):
503 rhosol[middle_state] = rhoL * PdPL**self.
_ginv
504 usol[middle_state] = ustar
505 Psol[middle_state] = Pstar
506 if np.any(left_state):
508 rhosol[left_state] = rhoL
509 usol[left_state] = uL
510 Psol[left_state] = PL
512 return rhosol, usol, Psol
516 @brief Sample the Riemann problem solution in the left state regime.
518 @param rhoL Density of the left state.
519 @param uL Velocity of the left state.
520 @param PL Pressure of the left state.
521 @param aL Soundspeed of the left state.
522 @param ustar Velocity of the middle state.
523 @param Pstar Pressure of the middle state.
524 @param dxdt Point in velocity space where we want to sample the solution.
525 @return Density, velocity and pressure solution.
530 rhoL, uL, PL, aL, ustar, Pstar, dxdt
535 rhoL, uL, PL, aL, ustar, Pstar, dxdt
538 return rhosol, usol, Psol
542 @brief Sample the vacuum Riemann problem if the right state is a vacuum.
544 @param rhoL Density of the left state.
545 @param uL Velocity of the left state.
546 @param PL Pressure of the left state.
547 @param aL Soundspeed of the left state.
548 @param dxdt Point in velocity space where we want to sample the solution.
549 @return Density, velocity and pressure solution, and a flag indicating
550 wether the left state (-1), the right state (1), or a vacuum state (0) was
553 rhosol = np.zeros(dxdt.shape)
554 usol = np.zeros(dxdt.shape)
555 Psol = np.zeros(dxdt.shape)
556 flagsol = np.zeros(dxdt.shape, dtype=np.int32)
558 vacuum_regime = uL - aL < dxdt
559 left_state = ~vacuum_regime
560 if np.any(vacuum_regime):
563 SL = uL + self.
_tdgm1 * aL
564 rarefaction_wave = vacuum_regime & (SL > dxdt)
565 if np.any(rarefaction_wave):
568 base = self.
_tdgp1 + self.
_gm1dgp1 * (uL - dxdt[rarefaction_wave]) / aL
569 rhosol[rarefaction_wave] = rhoL * base**self.
_tdgm1
570 usol[rarefaction_wave] = self.
_tdgp1 * (
571 aL + self.
_gm1d2 * uL + dxdt[rarefaction_wave]
573 Psol[rarefaction_wave] = PL * base**self.
_tgdgm1
574 flagsol[rarefaction_wave] = -1
577 if np.any(left_state):
579 rhosol[left_state] = rhoL
580 usol[left_state] = uL
581 Psol[left_state] = PL
582 flagsol[left_state] = -1
584 return rhosol, usol, Psol, flagsol
588 @brief Sample the vacuum Riemann problem if the left state is a vacuum.
590 @param rhoR Density of the right state.
591 @param uR Velocity of the right state.
592 @param PR Pressure of the right state.
593 @param aR Soundspeed of the right state.
594 @param dxdt Point in velocity space where we want to sample the solution.
595 @return Density, velocity and pressure solution, and a flag indicating
596 wether the left state (-1), the right state (1), or a vacuum state (0) was
599 rhosol = np.zeros(dxdt.shape)
600 usol = np.zeros(dxdt.shape)
601 Psol = np.zeros(dxdt.shape)
602 flagsol = np.zeros(dxdt.shape, dtype=np.int32)
604 vacuum_regime = dxdt < uR + aR
605 right_state = ~vacuum_regime
606 if np.any(vacuum_regime):
609 SR = uR - self.
_tdgm1 * aR
610 rarefaction_wave = vacuum_regime & (SR < dxdt)
611 if np.any(rarefaction_wave):
614 base = self.
_tdgp1 - self.
_gm1dgp1 * (uR - dxdt[rarefaction_wave]) / aR
615 rhosol[rarefaction_wave] = rhoR * base**self.
_tdgm1
616 usol[rarefaction_wave] = self.
_tdgp1 * (
617 -aR + self.
_tdgm1 * uR + dxdt[rarefaction_wave]
619 Psol[rarefaction_wave] = PR * base**self.
_tgdgm1
620 flagsol[rarefaction_wave] = 1
624 if np.any(right_state):
625 rhosol[right_state] = rhoR
626 usol[right_state] = uR
627 Psol[right_state] = PR
628 flagsol[right_state] = 1
630 return rhosol, usol, Psol, flagsol
634 @brief Sample the vacuum Riemann problem in the case vacuum is generated in
635 between the left and right state.
637 @param rhoL Density of the left state.
638 @param uL Velocity of the left state.
639 @param PL Pressure of the left state.
640 @param aL Soundspeed of the left state.
641 @param rhoR Density of the right state.
642 @param uR Velocity of the right state.
643 @param PR Pressure of the right state.
644 @param aR Soundspeed of the right state.
645 @param dxdt Point in velocity space where we want to sample the solution.
646 @return Density, velocity and pressure solution, and a flag indicating
647 wether the left state (-1), the right state (1), or a vacuum state (0) was
650 rhosol = np.zeros(dxdt.shape)
651 usol = np.zeros(dxdt.shape)
652 Psol = np.zeros(dxdt.shape)
653 flagsol = np.zeros(dxdt.shape, dtype=np.int32)
656 SR = uR - self.
_tdgm1 * aR
657 SL = uL + self.
_tdgm1 * aL
658 vacuum = (SR > dxdt) & (SL < dxdt)
659 rarefaction_regime = ~vacuum
662 if np.any(rarefaction_regime):
664 right_rarefaction_regime = rarefaction_regime & (SL < dxdt)
665 left_rarefaction_regime = rarefaction_regime & (~right_rarefaction_regime)
666 if np.any(right_rarefaction_regime):
668 right_rarefaction = right_rarefaction_regime & (dxdt < uR + aR)
669 right_state = right_rarefaction_regime & (~right_rarefaction)
670 if np.any(right_rarefaction):
675 - self.
_gm1dgp1 * (uR - dxdt[right_rarefaction]) / aR
677 rhosol[right_rarefaction] = rhoR * base**self.
_tdgm1
678 usol[right_rarefaction] = self.
_tdgp1 * (
679 -aR + self.
_tdgm1 * uR + dxdt[right_rarefaction]
681 Psol[right_rarefaction] = PR * base**self.
_tgdgm1
682 if np.any(right_state):
684 rhosol[right_state] = rhoR
685 usol[right_state] = uR
686 Psol[right_state] = PR
687 flagsol[right_rarefaction_regime] = 1
688 if np.any(left_rarefaction_regime):
690 left_rarefaction = left_rarefaction_regime & (dxdt > uL - aL)
691 left_state = left_rarefaction_regime & (~left_rarefaction)
692 if np.any(left_rarefaction):
698 rhosol[left_rarefaction] = rhoL * base**self.
_tdgm1
699 usol[left_rarefaction] = self.
_tdgp1 * (
700 aL + self.
_tdgm1 * uL + dxdt[left_rarefaction]
702 Psol[left_rarefaction] = PL * base**self.
_tgdgm1
703 if np.any(left_state):
705 rhosol[left_state] = rhoL
706 usol[left_state] = uL
707 Psol[left_state] = PL
708 flagsol[left_rarefaction_regime] = -1
710 return rhosol, usol, Psol, flagsol
712 def solve_vacuum(self, rhoL, uL, PL, aL, rhoR, uR, PR, aR, dxdt=np.array([0.0])):
714 @brief Vacuum Riemann solver.
716 This solver is called when one or both states have a zero density, or when
717 the vacuum generation condition is satisfied (meaning vacuum is generated
718 in the middle state, although strictly speaking there is no "middle"
719 state if vacuum is involved).
721 @param rhoL Density of the left state.
722 @param uL Velocity of the left state.
723 @param PL Pressure of the left state.
724 @param aL Soundspeed of the left state.
725 @param rhoR Density of the right state.
726 @param uR Velocity of the right state.
727 @param PR Pressure of the right state.
728 @param aR Soundspeed of the right state.
729 @param dxdt Point in velocity space where we want to sample the solution.
730 @return Density, velocity and pressure solution, and a flag indicating
731 wether the left state (-1), the right state (1), or a vacuum state (0) was
735 if rhoL == 0.0
and rhoR == 0.0:
736 rhosol = np.zeros(dxdt.shape)
737 usol = np.zeros(dxdt.shape)
738 Psol = np.zeros(dxdt.shape)
739 flagsol = np.zeros(dxdt.shape, dtype=np.int32)
740 return rhosol, usol, Psol, flagsol
752 rhoL, uL, PL, aL, rhoR, uR, PR, aR, dxdt
755 def solve(self, rhoL, uL, PL, rhoR, uR, PR, dxdt=np.array([0.0])):
757 @brief Solve the Riemann problem with the given left and right state.
759 @param rhoL Left state density.
760 @param uL Left state velocity.
761 @param PL Left state pressure.
762 @param rhoR Right state density.
763 @param uR Right state velocity.
764 @param PR Right state pressure.
765 @param dxdt Point in velocity space where we want to sample the solution.
766 @return Density, velocity and pressure solution, and a flag indicating
767 wether the left state (-1), the right state (1), or a vacuum state (0) was
776 if rhoL == 0.0
or rhoR == 0.0:
777 return self.
solve_vacuum(rhoL, uL, PL, aL, rhoR, uR, PR, aR, dxdt)
780 if self.
_tdgm1 * (aL + aR) <= uR - uL:
781 return self.
solve_vacuum(rhoL, uL, PL, aL, rhoR, uR, PR, aR, dxdt)
796 Pguess = self.
guess_P(rhoL, uL, PL, aL, rhoR, uR, PR, aR)
801 fPstar = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pstar)
802 fPguess = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pguess)
803 if fPstar * fPguess >= 0.0:
806 while abs(Pstar - Pguess) > 5.0e-9 * (Pstar + Pguess)
and fPguess < 0.0:
808 Pguess = Pguess - fPguess / self.
fprime(
809 rhoL, PL, aL, rhoR, PR, aR, Pguess
811 fPguess = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pguess)
814 if abs(Pstar - Pguess) > 5.0e-9 * (Pstar + Pguess)
and fPguess > 0.0:
815 Pstar = self.
solve_brent(rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pstar, Pguess)
820 ustar = 0.5 * (uL + uR) + 0.5 * (
821 self.
fb(rhoR, PR, aR, Pstar) - self.
fb(rhoL, PL, aL, Pstar)
827 rhosol = np.zeros(dxdt.shape)
828 usol = np.zeros(dxdt.shape)
829 Psol = np.zeros(dxdt.shape)
830 flagsol = np.zeros(dxdt.shape, dtype=np.int32)
832 right_state = ustar < dxdt
833 left_state = ~right_state
835 if np.any(right_state):
841 rhoR, uR, PR, aR, ustar, Pstar, dxdt[right_state]
843 flagsol[right_state] = 1
844 if np.any(left_state):
850 flagsol[left_state] = -1
852 return rhosol, usol, Psol, flagsol
856 @brief Solve the Riemann problem with the given left and right state for
857 the velocity and pressure (but do not sample the solution).
859 @param rhoL Left state density.
860 @param uL Left state velocity.
861 @param PL Left state pressure.
862 @param rhoR Right state density.
863 @param uR Right state velocity.
864 @param PR Right state pressure.
865 @return Velocity and pressure in the middle region.
873 if rhoL == 0.0
or rhoR == 0.0:
874 print(
"Vacuum not handled yet!")
878 if self.
_tdgm1 * (aL + aR) <= uR - uL:
879 print(
"Vacuum not handled yet!")
895 Pguess = self.
guess_P(rhoL, uL, PL, aL, rhoR, uR, PR, aR)
900 fPstar = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pstar)
901 fPguess = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pguess)
902 if fPstar * fPguess >= 0.0:
905 while abs(Pstar - Pguess) > 5.0e-9 * (Pstar + Pguess)
and fPguess < 0.0:
907 Pguess = Pguess - fPguess / self.
fprime(
908 rhoL, PL, aL, rhoR, PR, aR, Pguess
910 fPguess = self.
f(rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pguess)
913 if abs(Pstar - Pguess) > 5.0e-9 * (Pstar + Pguess)
and fPguess > 0.0:
914 Pstar = self.
solve_brent(rhoL, uL, PL, aL, rhoR, uR, PR, aR, Pstar, Pguess)
919 ustar = 0.5 * (uL + uR) + 0.5 * (
920 self.
fb(rhoR, PR, aR, Pstar) - self.
fb(rhoL, PL, aL, Pstar)