예제 #1
0
파일: rmhd-c2p.c 프로젝트: darien0/Mara
// Using Z=rho*h*W^2, and W, get the primitive variables.
// -----------------------------------------------------------------------------
int rmhd_c2p_reconstruct_prim(double Z, double W, double *Pout)
{
  double P[8]; // Place result into temporary prim state for now.
  const double b0 = BS * W / Z;

  P[rho] =  D/W;
  P[pre] = (D/W) * (Z/(D*W) - 1.0) * gamf;
  P[vx ] = (Cons[Sx] + b0*Cons[Bx]/W) / (Z+B2);
  P[vy ] = (Cons[Sy] + b0*Cons[By]/W) / (Z+B2);
  P[vz ] = (Cons[Sz] + b0*Cons[Bz]/W) / (Z+B2);
  P[Bx ] =  Cons[Bx];
  P[By ] =  Cons[By];
  P[Bz ] =  Cons[Bz];

  int prim_error = rmhd_c2p_check_prim(P);
  if (prim_error) return prim_error;

  // Don't actually modify the user's prim state until we're sure the state is
  // good.
  // ---------------------------------------------------------------------------
  memcpy(Pout, P, 8*sizeof(double));
  return RMHD_C2P_SUCCESS;
}
예제 #2
0
파일: magnetar.cpp 프로젝트: jzrake/ctf
void MagneticBubbleBoundary::set_bc_z0_wall(std::valarray<double> &U) const
{
  const int Nx = Mara->domain->get_N(1);
  const int Ny = Mara->domain->get_N(2);
  const int Ng = Mara->domain->get_Ng();

  const double r0 = rotation_radius;

  ValarrayManager M(Mara->domain->aug_shape(), Mara->domain->get_Nq());
  for (int i=0; i<Nx+2*Ng; ++i) {
    for (int j=0; j<Ny+2*Ng; ++j) {
      for (int k=0; k<Ng; ++k) {

        double x = Mara->domain->x_at(i);
        double y = Mara->domain->y_at(j);
        double r = sqrt(x*x + y*y);
        double Omega;

        switch (rotation_profile) {
        case RIGID_ROTATION:
          if (r < r0) {
            Omega = 1.0;
          }
          else {
            Omega = 0.0;
          }
          break;
        case RIGID_IN_KEPLARIAN_OUT:
          if (r < 0.5*r0) {
            Omega = 1.0;
          }
          else if (r > 2*r0) {
            Omega = 0.0;
          }
          else {
            Omega = pow(2*r/r0, -1.5);
          }
          break;
        }

        std::valarray<double> U1 = U[ M(i,j,2*Ng-k-1) ]; // reflected zone
        std::valarray<double> P1(8); // reflected zone primitive variables
        std::valarray<double> U0(8);
        std::valarray<double> P0(8);

        if (receive_primitive) {
          P1 = U1; // U was actually P (confusing, I know)
        }
        else {
          int err = Mara->fluid->ConsToPrim(&U1[0], &P1[0]);
          if (err) {
            /*
              fprintf(stderr,
              "[MagneticBubbleBoundary] unphysical boundary value\n");
              std::cerr << Mara->fluid->PrintCons(&U1[0]) << std::endl;
              std::cerr << rmhd_c2p_get_error(err) << std::endl;
            */
            //      exit(1);
            continue;
          }
        }

        /* not reflecting vz ensures that v < 1 in the guard zones */
        P0[0] =  P1[0];
        P0[1] =  P1[1];
        P0[2] = -y/r0 * Omega;
        P0[3] =  x/r0 * Omega;
        P0[4] =  0.0;//-P1[4];
        P0[5] = -P1[5];
        P0[6] = -P1[6];
        P0[7] =  P1[7];

        if (receive_primitive) {
          U0 = P0; // U really is P
          int err = rmhd_c2p_check_prim(&P0[0]);
          if (err) {
            std::cerr << rmhd_c2p_get_error(err) << std::endl;
            exit(1);
          }
        }
        else {
          int err = Mara->fluid->PrimToCons(&P0[0], &U0[0]);
          if (err) {
            std::cerr << rmhd_c2p_get_error(err) << std::endl;
            exit(1);
          }
        }
        U[ M(i,j,k) ] = U0;
      }
    }
  }
}
예제 #3
0
파일: rmhd.cpp 프로젝트: jzrake/ctf
int Rmhd::PrimCheck(const double *P) const
{
  return rmhd_c2p_check_prim(P);
}