PLUTO
hlld.c File Reference

HLLD Riemann solver for the relativistic MHD equations. More...

#include "pluto.h"
Include dependency graph for hlld.c:

Go to the source code of this file.

Classes

struct  RIEMANN_STATE
 

Macros

#define MAX_ITER   20
 
#define COUNT_FAILURES   NO
 When set to YES, count number of failures and write the count to "hlld_fails.dat" (works in parallel as well). More...
 
#define DEBUG   NO
 

Typedefs

typedef struct RIEMANN_STATE Riemann_State
 

Functions

static double HLLD_Fstar (Riemann_State *, Riemann_State *, double)
 
static int HLLD_GetRiemannState (Riemann_State *, double, int)
 
static void HLLD_GetAState (Riemann_State *, double p)
 
static void HLLD_GetCState (Riemann_State *, Riemann_State *, double, double *)
 
static double HLLD_TotalPressure (double *)
 
static void HLLD_PrintStates (double *, double *)
 
static void HLLD_PrintWhatsWrong (Riemann_State *, Riemann_State *, double, double *, double *)
 
void HLLD_Solver (const State_1D *state, int beg, int end, double *cmax, Grid *grid)
 

Variables

static double Sc
 
static double Bx
 

Detailed Description

HLLD Riemann solver for the relativistic MHD equations.

Solve the Riemann problem for the relativistic MHD equations using the HLLD solver of Mignone, Ugliano & Bodo (2009). The solver requires the solution of a nonlinear equation (Eq. [48]) and the maximum number of iterations before convergence can be set using the macro MAX_ITER (default 20). A physical relevant solution is accepted if it satisfies the constraints by Eq. [54], implemented in the function HLLD_Fstar(). If this is not the case or if other failure conditions occur during the iteration loop, we switch to the HLL Riemann solver.

The macro COUNT_FAILURES can be set to YES if one wishes to count how many times the solver fails.

On input, it takes left and right primitive state vectors state->vL and state->vR at zone edge i+1/2; On output, return flux and pressure vectors at the same interface i+1/2 (note that the i refers to i+1/2).

Also during this step, compute maximum wave propagation speed (cmax) for explicit time step computation.

Reference:

  • "A five wave Harte-Lax-van Leer Riemann solver for relativistic magnetohydrodynamics" Mignone et al, MNRAS (2009) 393,1141.
Authors
A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t)
Date
Dec 10, 2013

Definition in file hlld.c.

Macro Definition Documentation

#define COUNT_FAILURES   NO

When set to YES, count number of failures and write the count to "hlld_fails.dat" (works in parallel as well).

The number of failures is normalized to the total number of zones: nf/nz where nz is incremented during the main loop and nf is incremented when a failure occur.

Definition at line 37 of file hlld.c.

#define DEBUG   NO

Definition at line 75 of file hlld.c.

#define MAX_ITER   20

Definition at line 36 of file hlld.c.

Typedef Documentation

typedef struct RIEMANN_STATE Riemann_State

Function Documentation

double HLLD_Fstar ( Riemann_State PaL,
Riemann_State PaR,
double  p 
)
static

Return the velocity difference across the contact mode as a function of the total pressure p.

Definition at line 415 of file hlld.c.

418 {
419  int success = 1;
420  double dK, Bxc, Byc, Bzc;
421  double sBx, fun;
422  double vxcL, KLBc;
423  double vxcR, KRBc;
424 
425  sBx = Bx > 0.0 ? 1.0:-1.0;
426 
427  success *= HLLD_GetRiemannState (PaL, p, -1);
428  success *= HLLD_GetRiemannState (PaR, p, 1);
429 
430 /* -- compute B from average state -- */
431 
432  dK = PaR->Kx - PaL->Kx + 1.e-12;
433 
434  EXPAND(Bxc = Bx*dK; ,
435 
436  Byc = PaR->By*(PaR->Kx - PaR->vx)
437  - PaL->By*(PaL->Kx - PaL->vx)
438  + Bx*(PaR->vy - PaL->vy); ,
439 
440  Bzc = PaR->Bz*(PaR->Kx - PaR->vx)
441  - PaL->Bz*(PaL->Kx - PaL->vx)
442  + Bx*(PaR->vz - PaL->vz);)
443 
444  KLBc = EXPAND(PaL->Kx*Bxc, + PaL->Ky*Byc, + PaL->Kz*Bzc);
445  KRBc = EXPAND(PaR->Kx*Bxc, + PaR->Ky*Byc, + PaR->Kz*Bzc);
446 
447  vxcL = PaL->Kx - dK*Bx*(1.0 - PaL->K2)/(PaL->sw*dK - KLBc);
448  vxcR = PaR->Kx - dK*Bx*(1.0 - PaR->K2)/(PaR->sw*dK - KRBc);
449 
450  PaL->Sa = PaL->Kx;
451  PaR->Sa = PaR->Kx;
452  Sc = 0.5*(vxcL + vxcR);
453  fun = vxcL - vxcR; /* -- essentially, Eq. [48] -- */
454 
455 /*
456 fun = dK*(1.0 - Bx*( (1.0 - PaR->K2)/(PaR->sw*dK - KRBc)
457  - (1.0 - PaL->K2)/(PaL->sw*dK - KLBc)) );
458 */
459 
460  /* -- check if state makes physically sense -- */
461 
462  success = (vxcL - PaL->Kx) > -1.e-6;
463  success *= (PaR->Kx - vxcR) > -1.e-6;
464 
465  success *= (PaL->S - PaL->vx) < 0.0;
466  success *= (PaR->S - PaR->vx) > 0.0;
467 
468  success *= (PaR->w - p) > 0.0;
469  success *= (PaL->w - p) > 0.0;
470  success *= (PaL->Sa - PaL->S) > -1.e-6;
471  success *= (PaR->S - PaR->Sa) > -1.e-6;
472 
473  PaL->fail = !success;
474 
475 /*
476 scrh = (1.0 - PaR->K2)*(PaL->sw*dK - KLBc);
477 scrh -= (1.0 - PaL->K2)*(PaR->sw*dK - KRBc);
478 
479 PaL->fun1 = (PaR->sw*dK - KRBc)*(PaL->sw*dK - KLBc) - Bx*scrh;
480 PaL->fun2 = scrh;
481 PaL->denL = (PaL->sw*dK - KLBc);
482 PaL->denR = (PaR->sw*dK - KRBc);
483 */
484  return (fun);
485 }
486 
487 /* ********************************************************************* */
488 int HLLD_GetRiemannState (Riemann_State *Pv, double p, int side)
489 /*!
double w
Definition: hlld.c:52
double K2
Definition: hlld.c:51
double Kx
Definition: hlld.c:51
double vx
Definition: hlld.c:49
static double Sc
Definition: hlld.c:62
double sw
Definition: hlld.c:52
static int HLLD_GetRiemannState(Riemann_State *, double, int)
Definition: hlld.c:492
double Sa
Definition: hlld.c:54
double Kz
Definition: hlld.c:51
static double Bx
Definition: hlld.c:62
double Ky
Definition: hlld.c:51
double vy
Definition: hlld.c:49
double vz
Definition: hlld.c:49
int fail
Definition: hlld.c:48
double By
Definition: hlld.c:50
double S
Definition: hlld.c:54
double Bz
Definition: hlld.c:50

Here is the call graph for this function:

Here is the caller graph for this function:

void HLLD_GetAState ( Riemann_State Pa,
double  p 
)
static

Compute states aL and aR behind fast waves.

Definition at line 578 of file hlld.c.

579 {
580  double vB, *ua, *R, S;
581  double scrh;
582 
583  ua = Pa->u;
584  S = Pa->S;
585  R = Pa->R;
586 
587  scrh = 1.0/(S - Pa->vx);
588 
589  ua[RHO] = R[RHO]*scrh;
590  EXPAND(ua[BXn] = Bx; ,
591  ua[BXt] = (R[BXt] - Bx*Pa->vy)*scrh; ,
592  ua[BXb] = (R[BXb] - Bx*Pa->vz)*scrh;)
593 
594  vB = EXPAND(Pa->vx*ua[BXn], + Pa->vy*ua[BXt], + Pa->vz*ua[BXb]);
595  ua[ENG] = (R[ENG] + p*Pa->vx - vB*Bx)*scrh;
596 
597  EXPAND(ua[MXn] = (ua[ENG] + p)*Pa->vx - vB*ua[BXn]; ,
598  ua[MXt] = (ua[ENG] + p)*Pa->vy - vB*ua[BXt]; ,
599  ua[MXb] = (ua[ENG] + p)*Pa->vz - vB*ua[BXb];)
600 }
601 
602 /* ********************************************************************* */
603 void HLLD_GetCState (Riemann_State *PaL, Riemann_State *PaR, double p,
604  double *Uc)
static void HLLD_GetCState(Riemann_State *, Riemann_State *, double, double *)
Definition: hlld.c:607
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
double vx
Definition: hlld.c:49
double u[NFLX]
Definition: hlld.c:53
int BXn
Definition: globals.h:75
int MXt
Definition: globals.h:74
static double Bx
Definition: hlld.c:62
double vy
Definition: hlld.c:49
int MXn
Definition: globals.h:74
double vz
Definition: hlld.c:49
double R[NVAR]
Definition: hlld.c:53
double S
Definition: hlld.c:54
int BXt
Definition: globals.h:75
int BXb
Definition: globals.h:75
int MXb
Definition: globals.h:74

Here is the caller graph for this function:

void HLLD_GetCState ( Riemann_State PaL,
Riemann_State PaR,
double  p,
double *  Uc 
)
static

Compute states cL and cR across contact mode.

Definition at line 607 of file hlld.c.

609 {
610  double dK, *ua;
611  double vxcL, vycL, vzcL, KLBc;
612  double vxcR, vycR, vzcR, KRBc;
613  double vxc, vyc, vzc, vBc;
614  double Bxc, Byc, Bzc, Sa, vxa;
615  double scrhL, scrhR;
616 
617  HLLD_GetAState (PaL, p);
618  HLLD_GetAState (PaR, p);
619  dK = (PaR->Kx - PaL->Kx) + 1.e-12;
620 
621  EXPAND(Bxc = Bx*dK; ,
622 
623  Byc = PaR->By*(PaR->Kx - PaR->vx) /* Eq. [45] */
624  - PaL->By*(PaL->Kx - PaL->vx)
625  + Bx*(PaR->vy - PaL->vy); ,
626 
627  Bzc = PaR->Bz*(PaR->Kx - PaR->vx) /* Eq.[45] */
628  - PaL->Bz*(PaL->Kx - PaL->vx)
629  + Bx*(PaR->vz - PaL->vz);)
630 
631  EXPAND(Bxc = Bx; ,
632  Byc /= dK; ,
633  Bzc /= dK;)
634 
635  EXPAND(Uc[BXn] = Bxc; ,
636  Uc[BXt] = Byc; ,
637  Uc[BXb] = Bzc;)
638 
639  KLBc = EXPAND(PaL->Kx*Bxc, + PaL->Ky*Byc, + PaL->Kz*Bzc);
640  KRBc = EXPAND(PaR->Kx*Bxc, + PaR->Ky*Byc, + PaR->Kz*Bzc);
641 
642  scrhL = (1.0 - PaL->K2)/(PaL->sw - KLBc);
643  scrhR = (1.0 - PaR->K2)/(PaR->sw - KRBc);
644 
645  EXPAND(vxcL = PaL->Kx - Uc[BXn]*scrhL; /* Eq [47] */
646  vxcR = PaR->Kx - Uc[BXn]*scrhR; ,
647 
648  vycL = PaL->Ky - Uc[BXt]*scrhL;
649  vycR = PaR->Ky - Uc[BXt]*scrhR; ,
650 
651  vzcL = PaL->Kz - Uc[BXb]*scrhL;
652  vzcR = PaR->Kz - Uc[BXb]*scrhR;)
653 
654  EXPAND(vxc = 0.5*(vxcL + vxcR); ,
655  vyc = 0.5*(vycL + vycR); ,
656  vzc = 0.5*(vzcL + vzcR);)
657 
658  if (vxc > 0.0) {
659  HLLD_GetAState (PaL, p);
660  ua = PaL->u;
661  Sa = PaL->Sa;
662  vxa = PaL->vx;
663  } else {
664  HLLD_GetAState (PaR, p);
665  ua = PaR->u;
666  Sa = PaR->Sa;
667  vxa = PaR->vx;
668  }
669 
670  vBc = EXPAND(vxc*Uc[BXn], + vyc*Uc[BXt], + vzc*Uc[BXb]);
671 
672  Uc[RHO] = ua[RHO]*(Sa - vxa)/(Sa - vxc); /* Eq [32] */
673  Uc[ENG] = (Sa*ua[ENG] - ua[MXn] + p*vxc - vBc*Bx)/(Sa - vxc); /* Eq [33] */
674 
675  EXPAND(Uc[MXn] = (Uc[ENG] + p)*vxc - vBc*Bx; , /* Eq [34] */
676  Uc[MXt] = (Uc[ENG] + p)*vyc - vBc*Uc[BXt]; ,
677  Uc[MXb] = (Uc[ENG] + p)*vzc - vBc*Uc[BXb];)
678 }
679 
680 /* ********************************************************************* */
681 double HLLD_TotalPressure (double *v)
682 /*!
double K2
Definition: hlld.c:51
#define RHO
Definition: mod_defs.h:19
double Kx
Definition: hlld.c:51
double v[NVAR]
Definition: eos.h:106
double vx
Definition: hlld.c:49
static double HLLD_TotalPressure(double *)
Definition: hlld.c:685
double sw
Definition: hlld.c:52
double u[NFLX]
Definition: hlld.c:53
int BXn
Definition: globals.h:75
int MXt
Definition: globals.h:74
double Sa
Definition: hlld.c:54
double Kz
Definition: hlld.c:51
static double Bx
Definition: hlld.c:62
double Ky
Definition: hlld.c:51
double vy
Definition: hlld.c:49
int MXn
Definition: globals.h:74
double vz
Definition: hlld.c:49
double By
Definition: hlld.c:50
static void HLLD_GetAState(Riemann_State *, double p)
Definition: hlld.c:578
int BXt
Definition: globals.h:75
int BXb
Definition: globals.h:75
double Bz
Definition: hlld.c:50
int MXb
Definition: globals.h:74

Here is the call graph for this function:

Here is the caller graph for this function:

int HLLD_GetRiemannState ( Riemann_State Pv,
double  p,
int  side 
)
static

Express the state behind a wave as function of the total pressure p and the right hand side on the other side of the wave.

On output, return 1 if succesful, 0 if w < 0 is encountered. side = -1 : means left side = 1 : means right

When computing Bx, By and Bz, we use Eq. [21] with vx, vy and vz replaced by by Eq. [23,24,25]. The following short MAPLE script is used to verify the correctness.

1 restart;
2 A := R[mx] - lambda*R[E] + p*(1 - lambda^2):
3 G := R[By]*R[By] + R[Bz]*R[Bz]:
4 C := R[my]*R[By] + R[mz]*R[Bz]:
5 Q := - A - G + B[x]*B[x]*(1-lambda^2):
6 X := B[x]*(A*lambda*B[x]+ C) - (A + G)*(lambda*p + R[E]):
7 v[x] := (B[x]*(A*B[x] + lambda*C) - (A + G)*(p + R[mx]))/X:
8 v[y] := (Q*R[my] + R[By]*(C + B[x]*(lambda*R[mx] - R[E])))/X:
9 B[y] := (R[By] - B[x]*v[y])/(lambda - v[x]):
10 simplify(B[y]);

Definition at line 492 of file hlld.c.

494  : means left
495  * side = 1 : means right
496  *
497  *********************************************************************** */
498 {
499  double A, C, G, X, s;
500  double vx, vy, vz, scrh, S, *R;
501 
502  S = Pv->S;
503  R = Pv->R;
504 
505  A = R[MXn] + p*(1.0 - S*S) - S*R[ENG]; /* Eq. [26] */
506  G = EXPAND(0.0, + R[BXt]*R[BXt], + R[BXb]*R[BXb]); /* Eq. [27] */
507  C = EXPAND(0.0, + R[BXt]*R[MXt], + R[BXb]*R[MXb]); /* Eq. [28] */
508  X = Bx*(A*S*Bx + C) - (A + G)*(S*p + R[ENG]); /* Eq. [30] */
509 
510 /* -- compute the numerators of Eqs. [23,23,45] -- */
511 
512  EXPAND(vx = ( Bx*(A*Bx + C*S) - (R[MXn] + p)*(G + A) ); ,
513 
514  vy = ( - (A + G - Bx*Bx*(1.0 - S*S))*R[MXt]
515  + R[BXt]*(C + Bx*(S*R[MXn] - R[ENG])) ); ,
516 
517  vz = ( - (A + G - Bx*Bx*(1.0 - S*S))*R[MXb]
518  + R[BXb]*(C + Bx*(S*R[MXn] - R[ENG])) );)
519 
520  scrh = EXPAND(vx*R[MXn], + vy*R[MXt], + vz*R[MXb]);
521  scrh = X*R[ENG] - scrh;
522  Pv->w = p + scrh/(X*S - vx); /* Eq [31] */
523 
524  if (Pv->w < 0.0) return(0); /* -- failure -- */
525 
526  EXPAND(Pv->vx = vx/X; ,
527  Pv->vy = vy/X; ,
528  Pv->vz = vz/X;)
529 
530 /* -- original Eq. [21] -- */
531 /*
532  EXPAND(Pv->Bx = Bx; ,
533  Pv->By = (R[BXt]*X - Bx*vy)/(X*S - vx); ,
534  Pv->Bz = (R[BXb]*X - Bx*vz)/(X*S - vx);)
535 */
536 /* --------------------------------------------------------------------- */
537 /*! When computing Bx, By and Bz, we use Eq. [21] with
538  vx, vy and vz replaced by by Eq. [23,24,25].
539  The following short MAPLE script is used to verify the
540  correctness.
541  \code
542  restart;
543  A := R[mx] - lambda*R[E] + p*(1 - lambda^2):
544  G := R[By]*R[By] + R[Bz]*R[Bz]:
545  C := R[my]*R[By] + R[mz]*R[Bz]:
546  Q := - A - G + B[x]*B[x]*(1-lambda^2):
547  X := B[x]*(A*lambda*B[x]+ C) - (A + G)*(lambda*p + R[E]):
548  v[x] := (B[x]*(A*B[x] + lambda*C) - (A + G)*(p + R[mx]))/X:
549  v[y] := (Q*R[my] + R[By]*(C + B[x]*(lambda*R[mx] - R[E])))/X:
550  B[y] := (R[By] - B[x]*v[y])/(lambda - v[x]):
551  simplify(B[y]);
552  \endcode
553 */
554 /* --------------------------------------------------------------------- */
555 
556  EXPAND(Pv->Bx = Bx; ,
557  Pv->By = -(R[BXt]*(S*p + R[ENG]) - Bx*R[MXt])/A; ,
558  Pv->Bz = -(R[BXb]*(S*p + R[ENG]) - Bx*R[MXb])/A;)
559 
560  s = Bx > 0.0 ? 1.0:-1.0;
561  if (side < 0) s *= -1.0;
562 
563  Pv->sw = s*sqrt(Pv->w);
564 
565  scrh = 1.0/(S*p + R[ENG] + Bx*Pv->sw);
566  EXPAND(Pv->Kx = scrh*(R[MXn] + p + R[BXn]*Pv->sw); ,
567  Pv->Ky = scrh*(R[MXt] + R[BXt]*Pv->sw); ,
568  Pv->Kz = scrh*(R[MXb] + R[BXb]*Pv->sw);)
569 
570  Pv->K2 = EXPAND(Pv->Kx*Pv->Kx, + Pv->Ky*Pv->Ky, + Pv->Kz*Pv->Kz);
571  return(1); /* -- success -- */
572 }
573 /* ********************************************************************* */
574 void HLLD_GetAState (Riemann_State *Pa, double p)
575 /*!
576  * Compute states aL and aR behind fast waves.
double w
Definition: hlld.c:52
tuple scrh
Definition: configure.py:200
double vx
Definition: hlld.c:49
int BXn
Definition: globals.h:75
int MXt
Definition: globals.h:74
#define X
static double Bx
Definition: hlld.c:62
double vy
Definition: hlld.c:49
if(divB==NULL)
Definition: analysis.c:10
int MXn
Definition: globals.h:74
double vz
Definition: hlld.c:49
#define s
double R[NVAR]
Definition: hlld.c:53
static void HLLD_GetAState(Riemann_State *, double p)
Definition: hlld.c:578
double S
Definition: hlld.c:54
int BXt
Definition: globals.h:75
int BXb
Definition: globals.h:75
int MXb
Definition: globals.h:74

Here is the caller graph for this function:

void HLLD_PrintStates ( double *  vL,
double *  vR 
)
static

Definition at line 703 of file hlld.c.

738 {
void HLLD_PrintWhatsWrong ( Riemann_State PaL,
Riemann_State PaR,
double  pguess,
double *  vL,
double *  vR 
)
static

Definition at line 740 of file hlld.c.

751  {
752  f = HLLD_Fstar(PaL, PaR, p);
753  fprintf (fp,"%f %f %f %f\n", p, f, Sc - PaL->Sa, PaR->Sa - Sc);
754  }
755  fclose(fp);
756  exit(1);
757 }
758 
759 
760 
static double Sc
Definition: hlld.c:62
double Sa
Definition: hlld.c:54
FILE * fp
Definition: analysis.c:7
static double HLLD_Fstar(Riemann_State *, Riemann_State *, double)
Definition: hlld.c:415

Here is the caller graph for this function:

void HLLD_Solver ( const State_1D state,
int  beg,
int  end,
double *  cmax,
Grid grid 
)

Solve the Riemann problem using the HLLD Riemann solver.

Parameters
[in,out]statepointer to State_1D structure
[in]beginitial grid index
[out]endfinal grid index
[out]cmax1D array of maximum characteristic speeds
[in]gridpointer to array of Grid structures.

Definition at line 77 of file hlld.c.

85 {
86  int nv, i, k;
87  int switch_to_hll;
88  double scrh;
89  static double **fluxL, **fluxR;
90  static double *pL, *pR, *a2L, *a2R, *hL, *hR;
91  static double **Uhll, **Fhll, **Vhll;
92  double *vL, *vR, *fL, *fR, *uL, *uR, *SL, *SR;
93  static double **VL, **VR, **UL, **UR;
94 
95  double p0, f0, p, f, dp, dS_1;
96  double Uc[NVAR];
97  Riemann_State PaL, PaR;
98  double pguess;
99 
100 /* -------------------------------------------------------
101  for information purposes, show how many failures
102  have been encountered in every step
103  ------------------------------------------------------- */
104 
105  #if COUNT_FAILURES == YES
106  static double totfail=0.0,totzones=1.0;
107  static int last_step = -1;
108  FILE *fp;
109 
110  if (g_stepNumber == 0 && prank == 0) {
111  fp = fopen("hlld_fails.dat","w");
112  fprintf (fp, "# Step Failures (x 100) \n");
113  fprintf (fp, "# --------------------------\n");
114  fclose(fp);
115  }
116  if (last_step != g_stepNumber){ /* -- at the beginning of new step -- */
117  #ifdef PARALLEL
118  MPI_Allreduce (&totfail, &scrh, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
119  totfail = scrh;
120  MPI_Allreduce (&totzones, &scrh, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
121  totzones = scrh;
122  #endif
123  if (prank == 0){
124  fp = fopen("hlld_fails.dat","a+");
125  fprintf (fp," %d %f\n",g_stepNumber, totfail/totzones*100.);
126  fclose(fp);
127  }
128  totfail = totzones = 0.0;
129  last_step = g_stepNumber;
130  }
131  #endif
132 
133 /* ----------------------------------------------------------- */
134 
135  if (fluxL == NULL){
136  fluxL = ARRAY_2D(NMAX_POINT, NFLX, double);
137  fluxR = ARRAY_2D(NMAX_POINT, NFLX, double);
138  pL = ARRAY_1D(NMAX_POINT, double);
139  pR = ARRAY_1D(NMAX_POINT, double);
140  Uhll = ARRAY_2D(NMAX_POINT, NVAR, double);
141  Fhll = ARRAY_2D(NMAX_POINT, NVAR, double);
142  Vhll = ARRAY_2D(NMAX_POINT, NVAR, double);
143 
144  #ifdef GLM_MHD
145  VL = ARRAY_2D(NMAX_POINT, NVAR, double);
146  VR = ARRAY_2D(NMAX_POINT, NVAR, double);
147  UL = ARRAY_2D(NMAX_POINT, NVAR, double);
148  UR = ARRAY_2D(NMAX_POINT, NVAR, double);
149  #endif
150 
151  a2L = ARRAY_1D(NMAX_POINT, double);
152  a2R = ARRAY_1D(NMAX_POINT, double);
153  hL = ARRAY_1D(NMAX_POINT, double);
154  hR = ARRAY_1D(NMAX_POINT, double);
155  }
156 /*
157  #if DIVB_CONTROL == EIGHT_WAVES
158  print ("! hlld Riemann solver does not work with Powell's 8-wave\n");
159  QUIT_PLUTO(1);
160  #endif
161 */
162 
163  #ifdef GLM_MHD
164  GLM_Solve (state, VL, VR, beg, end, grid);
165  PrimToCons (VL, UL, beg, end);
166  PrimToCons (VR, UR, beg, end);
167  #else
168  VL = state->vL; UL = state->uL;
169  VR = state->vR; UR = state->uR;
170  #endif
171 
172 /* ----------------------------------------------------
173  compute sound speed & fluxes at zone interfaces
174  ---------------------------------------------------- */
175 
176  SoundSpeed2 (VL, a2L, hL, beg, end, FACE_CENTER, grid);
177  SoundSpeed2 (VR, a2R, hR, beg, end, FACE_CENTER, grid);
178 
179  Flux (UL, VL, hL, fluxL, pL, beg, end);
180  Flux (UR, VR, hR, fluxR, pR, beg, end);
181 
182 /* -- compute speeds -- */
183 
184  SL = state->SL; SR = state->SR;
185  HLL_Speed (VL, VR, a2L, a2R, hL, hR, SL, SR, beg, end);
186 
187 /* -------------------------------------------------------
188  Begin main loop
189  ------------------------------------------------------- */
190 
191  for (i = beg; i <= end; i++) {
192 
193 #if DEBUG == YES
194  if (!(grid[IDIR].x[i] < 0.5 && grid[IDIR].x[i+1] > 0.5)) continue;
195 #endif
196 
197  #if COUNT_FAILURES == YES
198  totzones += 1.0;
199  #endif
200 
201  scrh = MAX(fabs(SL[i]), fabs(SR[i]));
202  cmax[i] = scrh;
203 
204  vL = VL[i]; vR = VR[i]; fR = fluxR[i];
205  uL = UL[i]; uR = UR[i]; fL = fluxL[i];
206 
207  if (SL[i] >= 0.0){
208 
209  for (nv = NFLX; nv--; ) state->flux[i][nv] = fL[nv];
210  state->press[i] = pL[i];
211 
212  }else if (SR[i] <= 0.0){
213 
214  for (nv = NFLX; nv--; ) state->flux[i][nv] = fR[nv];
215  state->press[i] = pR[i];
216 
217  }else{
218 
219  /* ---- build the HLL average state ---- */
220 
221  dS_1 = 1.0/(SR[i] - SL[i]);
222  for (nv = NFLX; nv--; ){ /* -- we use NVAR and not NFLX since
223  ConsToPrim may need entropy -- */
224  Uhll[i][nv] = SR[i]*uR[nv] - SL[i]*uL[nv] + fL[nv] - fR[nv];
225  Uhll[i][nv] *= dS_1;
226 
227  Fhll[i][nv] = SR[i]*fL[nv] - SL[i]*fR[nv] + SL[i]*SR[i]*(uR[nv] - uL[nv]);
228  Fhll[i][nv] *= dS_1;
229  }
230  Uhll[i][MXn] += (pL[i] - pR[i])*dS_1;
231 #if NSCL > 0
232  NSCL_LOOP(nv) {
233  double vxR = vR[VXn];
234  double vxL = vL[VXn];
235  Uhll[i][nv] = (SR[i] - vxR)*uR[nv] - (SL[i] - vxL)*uL[nv];
236  Uhll[i][nv] *= dS_1;
237 
238  Fhll[i][nv] = SR[i]*uL[nv]*vL[VXn] - SL[i]*uR[nv]*vR[VXn]
239  + SL[i]*SR[i]*(uR[nv] - uL[nv]);
240  Fhll[i][nv] *= dS_1;
241  }
242 #endif
243 
244  /* ---- revert to HLL in proximity of strong shocks ---- */
245 
246 #if SHOCK_FLATTENING == MULTID
247  if ((state->flag[i] & FLAG_HLL) || (state->flag[i+1] & FLAG_HLL)){
248  for (nv = NFLX; nv--; ) state->flux[i][nv] = Fhll[i][nv];
249  state->press[i] = (SR[i]*pL[i] - SL[i]*pR[i])*dS_1;
250  continue;
251  }
252 #endif
253 
254  /* ---- proceed normally otherwise ---- */
255 
256  PaL.S = SL[i];
257  PaR.S = SR[i];
258  Bx = Uhll[i][BXn];
259  for (nv = 0; nv < NFLX; nv++){
260  PaL.R[nv] = SL[i]*uL[nv] - fL[nv];
261  PaR.R[nv] = SR[i]*uR[nv] - fR[nv];
262  }
263  PaL.R[MXn] -= pL[i];
264  PaR.R[MXn] -= pR[i];
265  #if RMHD_REDUCED_ENERGY == YES
266  PaL.R[ENG] += PaL.R[RHO];
267  PaR.R[ENG] += PaR.R[RHO];
268  #endif
269 
270  /* ---- provide an initial guess ---- */
271 
272  scrh = MAX(pL[i], pR[i]);
273  if (Bx*Bx/scrh < 0.01) { /* -- try the B->0 limit -- */
274 
275  double a,b,c;
276  a = SR[i] - SL[i];
277  b = PaR.R[ENG] - PaL.R[ENG] + SR[i]*PaL.R[MXn] - SL[i]*PaR.R[MXn];
278  c = PaL.R[MXn]*PaR.R[ENG] - PaR.R[MXn]*PaL.R[ENG];
279  scrh = b*b - 4.0*a*c;
280  scrh = MAX(scrh,0.0);
281  p0 = 0.5*(- b + sqrt(scrh))*dS_1;
282 
283  }else{ /* ---- use HLL average ---- */
284 
285  ConsToPrim(Uhll, Vhll, i, i, state->flag);
286  p0 = HLLD_TotalPressure(Vhll[i]);
287  }
288 
289  /* ---- check if guess makes sense ---- */
290 
291  pguess = p0;
292  switch_to_hll = 0;
293  f0 = HLLD_Fstar(&PaL, &PaR, p0);
294  if (f0 != f0 || PaL.fail) switch_to_hll = 1;
295 
296  /* ---- Root finder ---- */
297 
298  k = 0;
299  if (fabs(f0) > 1.e-12 && !switch_to_hll){
300  p = 1.025*p0; f = f0;
301  for (k = 1; k < MAX_ITER; k++){
302 
303 #if DEBUG == YES
304  printf ("k = %d, p = %12.6e, f = %12.6e\n",k,p,f);
305 #endif
306 
307  f = HLLD_Fstar(&PaL, &PaR, p);
308  if (f != f || PaL.fail || (k > 7) || (fabs(f) > fabs(f0) && k > 4)) {
309  switch_to_hll = 1;
310  break;
311  }
312 
313  dp = (p - p0)/(f - f0)*f;
314 
315  p0 = p; f0 = f;
316  p -= dp;
317  if (p < 0.0) p = 1.e-6;
318  if (fabs(dp) < 1.e-5*p || fabs(f) < 1.e-6) break;
319  }
320  }else p = p0;
321 
322 #if DEBUG == YES
323 HLLD_PrintWhatsWrong(&PaL, &PaR, phll, phll, p0Bx, p, vL, vR);
324 #endif
325 
326  /* ---- too many iter ? --> use HLL ---- */
327 
328  if (PaL.fail) switch_to_hll = 1;
329  if (switch_to_hll){
330 
331  #if COUNT_FAILURES == YES
332  totfail += 1.0;
333  #endif
334 
335  for (nv = NFLX; nv--; ) state->flux[i][nv] = Fhll[i][nv];
336  state->press[i] = (SR[i]*pL[i] - SL[i]*pR[i])*dS_1;
337  continue;
338  }
339 
340  /* -- ok, solution should be reliable -- */
341 
343 
344  #ifdef GLM_MHD
345  PaL.u[PSI_GLM] = PaR.u[PSI_GLM] = Uc[PSI_GLM] = uL[PSI_GLM];
346  #endif
347 
348  if (PaL.Sa >= -1.e-6){
349 
350  HLLD_GetAState (&PaL, p);
351  #if RMHD_REDUCED_ENERGY == YES
352  PaL.u[ENG] -= PaL.u[RHO];
353  #endif
354  for (nv = NFLX; nv--; ) {
355  state->flux[i][nv] = fL[nv] + SL[i]*(PaL.u[nv] - uL[nv]);
356  }
357  state->press[i] = pL[i];
358 
359  }else if (PaR.Sa <= 1.e-6){
360 
361  HLLD_GetAState (&PaR, p);
362  #if RMHD_REDUCED_ENERGY == YES
363  PaR.u[ENG] -= PaR.u[RHO];
364  #endif
365  for (nv = NFLX; nv--; ) {
366  state->flux[i][nv] = fR[nv] + SR[i]*(PaR.u[nv] - uR[nv]);
367  }
368  state->press[i] = pR[i];
369 
370  }else{
371 
372  HLLD_GetCState (&PaL, &PaR, p, Uc);
373  if (Sc > 0.0){
374  #if RMHD_REDUCED_ENERGY == YES
375  PaL.u[ENG] -= PaL.u[RHO];
376  Uc[ENG] -= Uc[RHO];
377  #endif
378  for (nv = NFLX; nv--; ) {
379  state->flux[i][nv] = fL[nv] + SL[i]*(PaL.u[nv] - uL[nv])
380  + PaL.Sa*(Uc[nv] - PaL.u[nv]);
381  }
382  state->press[i] = pL[i];
383 
384  }else{
385  #if RMHD_REDUCED_ENERGY == YES
386  PaR.u[ENG] -= PaR.u[RHO];
387  Uc[ENG] -= Uc[RHO];
388  #endif
389  for (nv = NFLX; nv--; ) {
390  state->flux[i][nv] = fR[nv] + SR[i]*(PaR.u[nv] - uR[nv])
391  + PaR.Sa*(Uc[nv] - PaR.u[nv]);
392  }
393  state->press[i] = pR[i];
394  }
395  }
396  } /* --- end if on SL, SR -- */
397  } /* --- end loop on points -- */
398 
399 /* --------------------------------------------------------
400  initialize source term
401  -------------------------------------------------------- */
402 
403  #if DIVB_CONTROL == EIGHT_WAVES
404  HLL_DIVB_SOURCE (state, Uhll, beg + 1, end, grid);
405  #endif
406 
407 }
408 #undef MAX_ITER
409 #undef COUNT_FAILURES
410 /* ********************************************************************* */
411 double HLLD_Fstar (Riemann_State *PaL, Riemann_State *PaR, double p)
static double a
Definition: init.c:135
#define MAX(a, b)
Definition: macros.h:101
#define NSCL_LOOP(n)
Definition: pluto.h:616
void GLM_Solve(const State_1D *state, double **VL, double **VR, int beg, int end, Grid *grid)
Definition: glm.c:24
static void HLLD_GetCState(Riemann_State *, Riemann_State *, double, double *)
Definition: hlld.c:607
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
void Flux(double **u, double **w, double *a2, double **fx, double *p, int beg, int end)
Definition: fluxes.c:23
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
double * SR
Rightmost velocity in the Riemann fan at i+1/2.
Definition: structs.h:167
int g_maxRiemannIter
Maximum number of iterations for iterative Riemann Solver.
Definition: globals.h:93
#define PSI_GLM
Definition: mod_defs.h:34
static double Sc
Definition: hlld.c:62
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
static double HLLD_TotalPressure(double *)
Definition: hlld.c:685
int prank
Processor rank.
Definition: globals.h:33
double u[NFLX]
Definition: hlld.c:53
void SoundSpeed2(double **v, double *cs2, double *h, int beg, int end, int pos, Grid *grid)
Definition: eos.c:16
void HLL_DIVB_SOURCE(const State_1D *, double **, int, int, Grid *)
Definition: source.c:53
int BXn
Definition: globals.h:75
long int g_stepNumber
Gives the current integration step number.
Definition: globals.h:97
double Sa
Definition: hlld.c:54
#define NFLX
Definition: mod_defs.h:32
#define IDIR
Definition: pluto.h:193
#define FACE_CENTER
Definition: pluto.h:206
int ConsToPrim(double **ucons, double **uprim, int ibeg, int iend, unsigned char *flag)
Definition: mappers.c:89
static double Bx
Definition: hlld.c:62
double * SL
Leftmost velocity in the Riemann fan at i+1/2.
Definition: structs.h:166
unsigned char * flag
Definition: structs.h:168
int k
Definition: analysis.c:2
int MXn
Definition: globals.h:74
#define MAX_ITER
Definition: hlld.c:36
tuple c
Definition: menu.py:375
int VXn
Definition: globals.h:73
int fail
Definition: hlld.c:48
double ** uR
same as vR, in conservative vars
Definition: structs.h:145
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
Definition: globals.h:62
void PrimToCons(double **uprim, double **ucons, int ibeg, int iend)
Definition: mappers.c:26
int i
Definition: analysis.c:2
double R[NVAR]
Definition: hlld.c:53
static void HLLD_GetAState(Riemann_State *, double p)
Definition: hlld.c:578
static void HLLD_PrintWhatsWrong(Riemann_State *, Riemann_State *, double, double *, double *)
Definition: hlld.c:740
double S
Definition: hlld.c:54
FILE * fp
Definition: analysis.c:7
void HLL_Speed(double **vL, double **vR, double *a2L, double *a2R, double *SL, double *SR, int beg, int end)
Definition: hll_speed.c:24
double ** vL
Primitive variables to the left of the interface, .
Definition: structs.h:136
double * press
Upwind pressure term computed with the Riemann solver.
Definition: structs.h:164
#define FLAG_HLL
Use HLL Riemann solver.
Definition: pluto.h:181
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
static double HLLD_Fstar(Riemann_State *, Riemann_State *, double)
Definition: hlld.c:415
#define NVAR
Definition: pluto.h:609
double ** uL
same as vL, in conservative vars
Definition: structs.h:144

Here is the call graph for this function:

double HLLD_TotalPressure ( double *  v)
static

Compute total pressure

Definition at line 685 of file hlld.c.

686 {
687  double vel2, Bmag2, vB, lor2;
688  double pt;
689 
690  Bmag2 = EXPAND(v[BX1]*v[BX1], + v[BX2]*v[BX2], + v[BX3]*v[BX3]);
691  vel2 = EXPAND(v[VX1]*v[VX1], + v[VX2]*v[VX2], + v[VX3]*v[VX3]);
692  vB = EXPAND(v[VX1]*v[BX1], + v[VX2]*v[BX2], + v[VX3]*v[BX3]);
693  pt = v[PRS] + 0.5*(Bmag2*(1.0 - vel2) + vB*vB);
694  return(pt);
695 }
696 
697 
698 
699 void HLLD_PrintStates(double *vL, double *vR)
#define VX2
Definition: mod_defs.h:29
double v[NVAR]
Definition: eos.h:106
#define VX1
Definition: mod_defs.h:28
static void HLLD_PrintStates(double *, double *)
Definition: hlld.c:703
list vel2
Definition: Sph_disk.py:39
#define BX3
Definition: mod_defs.h:27
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define BX2
Definition: mod_defs.h:26

Here is the caller graph for this function:

Variable Documentation

double Bx
static

Definition at line 62 of file hlld.c.

double Sc
static

Definition at line 62 of file hlld.c.