Ejemplo n.º 1
0
int Rmhd::ConsToPrim(const double *U, double *P) const
{
  int error = 1;

  // This piece of code drives cons to prim inversions for an arbitrary equation
  // of state.
  // ---------------------------------------------------------------------------
  if (typeid(*EOS) != typeid(AdiabaticEos)) {

    rmhd_c2p_eos_set_eos(EOS);
    rmhd_c2p_eos_new_state(U);

    if (error) {
      rmhd_c2p_eos_set_starting_prim(P);
      error = rmhd_c2p_eos_solve_noble2dzt(P);
    }
    if (error) {
      //      printf("c2p failed once. using reset.\n");
      rmhd_c2p_eos_estimate_from_cons();
      error = rmhd_c2p_eos_solve_noble2dzt(P);
    }
    if (error) {
      //      printf("c2p failed twice. using duffell3d.\n");
      rmhd_c2p_eos_set_starting_prim(P);
      error = rmhd_c2p_eos_solve_duffell3d(P);
    }

    return error;
  }

  // This piece of code drives cons to prim inversions for a gamma-law equation
  // of state.
  // ---------------------------------------------------------------------------
  rmhd_c2p_set_gamma(Mara->GetEos<AdiabaticEos>().Gamma);
  rmhd_c2p_new_state(U);

  if (error) {
    rmhd_c2p_set_starting_prim(P);
    error = rmhd_c2p_solve_anton2dzw(P);
  }
  if (error) {
    rmhd_c2p_estimate_from_cons();
    error = rmhd_c2p_solve_anton2dzw(P);
  }
  if (error) {
    rmhd_c2p_set_starting_prim(P);
    error = rmhd_c2p_solve_noble1dw(P);
  }
  if (error) {
    rmhd_c2p_estimate_from_cons();
    error = rmhd_c2p_solve_noble1dw(P);
  }

  return error;
}
Ejemplo n.º 2
0
Archivo: rmhd.cpp Proyecto: jzrake/ctf
int Rmhd::ConsToPrim(const double *U, double *P) const
{
  int error = rmhd_c2p_check_cons(U);

  if (error) {
    fprintf(stderr, "[0] %s\n", rmhd_c2p_get_error(error));
    std::cerr << PrintCons(U) << std::endl;
    return error;
  }
  else {
    error = 1;
  }

  // This piece of code drives cons to prim inversions for an arbitrary equation
  // of state.
  // ---------------------------------------------------------------------------
  if (typeid(*EOS) != typeid(AdiabaticEos)) {

    rmhd_c2p_eos_set_eos(EOS);
    rmhd_c2p_eos_new_state(U);

    //    std::cout << PrintPrim(P) << std::endl;
    //    std::cout << PrintCons(U) << std::endl;

    if (error) {
      rmhd_c2p_eos_set_starting_prim(P);
      error = rmhd_c2p_eos_solve_duffell3d(P);
    }
    if (error) {

      // NOTE: disregarding further c2p trials for debugging purposes
      return error;
      // ------------------------------------------------------------

      rmhd_c2p_eos_set_starting_prim(P);
      error = rmhd_c2p_eos_solve_noble2dzt(P);
    }
    if (error) {
      rmhd_c2p_eos_estimate_from_cons();
      error = rmhd_c2p_eos_solve_noble2dzt(P);
    }

    return error;
  }

  // This piece of code drives cons to prim inversions for a gamma-law equation
  // of state.
  // ---------------------------------------------------------------------------
  rmhd_c2p_set_gamma(Mara->GetEos<AdiabaticEos>().Gamma);
  rmhd_c2p_new_state(U);

  if (error) {
    rmhd_c2p_estimate_from_cons();
    error = rmhd_c2p_solve_anton2dzw(P);
    //    if (error) fprintf(stderr, "[1] %s\n", rmhd_c2p_get_error(error));
  }
  if (error) {
    rmhd_c2p_set_starting_prim(P);
    error = rmhd_c2p_solve_anton2dzw(P);
    //    if (error) fprintf(stderr, "[2] %s\n", rmhd_c2p_get_error(error));
  }
  if (error) {
    rmhd_c2p_estimate_from_cons();
    error = rmhd_c2p_solve_noble1dw(P);
    //    if (error) fprintf(stderr, "[3] %s\n", rmhd_c2p_get_error(error));
  }
  if (error) {
    rmhd_c2p_set_starting_prim(P);
    error = rmhd_c2p_solve_noble1dw(P);
    //    if (error) fprintf(stderr, "[4] %s\n", rmhd_c2p_get_error(error));
  }

  return error;
}