CavityPressureUserObject::CavityPressureUserObject(const std::string & obj_name, InputParameters params) :
    GeneralUserObject(obj_name, params),
   _cavity_pressure(declareRestartableData<Real>("cavity_pressure", 0)),
   _n0(declareRestartableData<Real>("initial_moles", 0)),
   _initial_pressure(getParam<Real>("initial_pressure")),
   _material_input(),
   _R(getParam<Real>("R")),
   _temperature( getPostprocessorValue("temperature")),
   _init_temp_given( isParamValid("initial_temperature") ),
   _init_temp( _init_temp_given ? getParam<Real>("initial_temperature") : 0 ),
   _volume( getPostprocessorValue("volume")),
   _start_time(0),
   _startup_time( getParam<Real>("startup_time")),
   _initialized(declareRestartableData<bool>("initialized", false))
{

  if (isParamValid("material_input"))
  {
    std::vector<PostprocessorName> ppn = params.get<std::vector<PostprocessorName> >("material_input");
    const unsigned len = ppn.size();
    for (unsigned i(0); i < len; ++i)
    {
      _material_input.push_back( &getPostprocessorValueByName(ppn[i]) );
    }
  }

}
Real
OneDEntropyViscosityMethod::computeValue()
{
  Real h=_current_elem->volume();
  Real rho=_rhoA[_qp]/_area[_qp];
  Real rhou=_rhouA[_qp]/_area[_qp];
  Real rhoE=_rhoEA[_qp]/_area[_qp];
  Real vel=rhou/rho;
  Real c=std::sqrt(_eos.c2(rho, rhou, rhoE));
  Real visc_max_tmp = _Cmax*h*(std::fabs(vel)+c);
  Real visc_max = _t_step < 10 ? (11.-_t_step)*visc_max_tmp : visc_max_tmp;
  
  Real vel_avg = std::max(getPostprocessorValueByName(_vel_average), 1.e-6);
  
  Real norm = _norm_type ? 0.5*rho*c*c : 0.5*rho*std::max( vel_avg*vel_avg, vel*vel );
  
  Real press_res=(_press[_qp]-_press_old[_qp])/_dt+vel*_press_grad[_qp](0);
  Real rho_res=(_rho[_qp]-_rho_old[_qp])/_dt+vel*_rho_grad[_qp](0);
  
  Real vel_abs = std::fabs(vel);
  
  Real res = ( _Ce*std::fabs(press_res-c*c*rho_res)+vel_abs*_press_jump[_qp] ) / norm;
  res += vel_abs*_rho_jump[_qp] / _rho[_qp];
  
//  Real res = h*h*( _Ce*std::fabs(press_res-c*c*rho_res)+_press_jump[_qp]+c*c*_rho_jump[_qp] );

//  Real res = h*h*( std::max(_press_jump[_qp], c*c*_rho_jump[_qp]) );
//  Real res = h*h*( _press_jump[_qp]+c*c*_rho_jump[_qp] );
  
  Real visc = _Cejump*h*h*res;

  return _t_step <= 1 ? visc_max : std::min(visc_max, visc);
}
PlenumPressureUserObject::PlenumPressureUserObject(const std::string & name, InputParameters params)
  :GeneralUserObject(name, params),
   _plenum_pressure(declareRestartableData<Real>("plenum_pressure", 0)),
   _n0(declareRestartableData<Real>("initial_moles", 0)),
   _initial_pressure(getParam<Real>("initial_pressure")),
   _material_input(),
   _R(getParam<Real>("R")),
   _temperature( getPostprocessorValue("temperature")),
   _volume( getPostprocessorValue("volume")),
   _start_time(0),
   _startup_time( getParam<Real>("startup_time")),
   _refab_needed(isParamValid("refab_time") ? getParam<std::vector<Real> >("refab_time").size() : 0),
   _refab_gas_released(declareRestartableData<Real>("refab_gas_released", 0)),
   _refab_time( isParamValid("refab_time") ?
                getParam<std::vector<Real> >("refab_time") :
                std::vector<Real>(1, -std::numeric_limits<Real>::max()) ),
   _refab_pressure( isParamValid("refab_pressure") ?
                    getParam<std::vector<Real> >("refab_pressure") :
                    std::vector<Real>(_refab_time.size(), 0) ),
   _refab_temperature( isParamValid("refab_temperature") ?
                       getParam<std::vector<Real> >("refab_temperature") :
                       std::vector<Real>(_refab_time.size(), 0) ),
   _refab_volume( isParamValid("refab_volume") ?
                  getParam<std::vector<Real> >("refab_volume") :
                  std::vector<Real>(_refab_time.size(), 0) ),
   _refab_type( isParamValid("refab_type") ?
                getParam<std::vector<unsigned> >("refab_type") :
                std::vector<unsigned>(_refab_time.size(), 0) ),
   _refab_counter(declareRestartableData<unsigned int>("refab_counter", 0)),
   _initialized(declareRestartableData<bool>("initialized", false))
{

  if (isParamValid("material_input"))
  {
    std::vector<PostprocessorName> ppn = params.get<std::vector<PostprocessorName> >("material_input");
    const unsigned len = ppn.size();
    for (unsigned i(0); i < len; ++i)
    {
      _material_input.push_back( &getPostprocessorValueByName(ppn[i]) );
    }
  }

  if (params.isParamValid("refab_time") &&
      !(params.isParamValid("refab_pressure") &&
        params.isParamValid("refab_temperature") &&
        params.isParamValid("refab_volume")))
  {
    mooseError("PlenumPressureUserObject error: refabrication time given but not complete set of refabrication data");
  }
  if (_refab_time.size() != _refab_pressure.size() ||
      _refab_pressure.size() != _refab_temperature.size() ||
      _refab_temperature.size() != _refab_volume.size() ||
      _refab_volume.size() != _refab_type.size())
  {
    mooseError("Refab parameters do not have equal lengths");
  }

}
// DEPRECATED CONSTRUCTOR
VectorOfPostprocessors::VectorOfPostprocessors(const std::string & deprecated_name, InputParameters parameters) :
    GeneralVectorPostprocessor(deprecated_name, parameters),
    _pp_vec(declareVector(MooseUtils::shortName(parameters.get<std::string>("name"))))
{
  std::vector<PostprocessorName> pps_names(getParam<std::vector<PostprocessorName> >("postprocessors"));
  _pp_vec.resize(pps_names.size());
  for (unsigned int i=0; i<pps_names.size(); ++i)
  {
    if (!hasPostprocessorByName(pps_names[i]))
      mooseError("In VectorOfPostprocessors, postprocessor with name: "<<pps_names[i]<<" does not exist");
    _postprocessor_values.push_back(&getPostprocessorValueByName(pps_names[i]));
  }
}
VectorOfPostprocessors::VectorOfPostprocessors(const InputParameters & parameters)
  : GeneralVectorPostprocessor(parameters),
    _pp_vec(declareVector(MooseUtils::shortName(parameters.get<std::string>("_object_name"))))
{
  std::vector<PostprocessorName> pps_names(
      getParam<std::vector<PostprocessorName>>("postprocessors"));
  _pp_vec.resize(pps_names.size());
  for (const auto & pps_name : pps_names)
  {
    if (!hasPostprocessorByName(pps_name))
      mooseError(
          "In VectorOfPostprocessors, postprocessor with name: ", pps_name, " does not exist");
    _postprocessor_values.push_back(&getPostprocessorValueByName(pps_name));
  }
}
Exemple #6
0
CrackDataSampler::CrackDataSampler(const std::string & name, InputParameters parameters) :
    GeneralVectorPostprocessor(name, parameters),
    SamplerBase(name, parameters, this, _communicator),
    _crack_front_definition(&getUserObject<CrackFrontDefinition>("crack_front_definition")),
    _position_type(getParam<MooseEnum>("position_type"))
{
  std::vector<PostprocessorName> pps_names(getParam<std::vector<PostprocessorName> >("postprocessors"));
  for (unsigned int i=0; i<pps_names.size(); ++i)
  {
    if (!hasPostprocessorByName(pps_names[i]))
      mooseError("In CrackDataSampler, postprocessor with name: "<<pps_names[i]<<" does not exist");
    _domain_integral_postprocessor_values.push_back(&getPostprocessorValueByName(pps_names[i]));
  }
  std::vector<std::string> var_names;
  var_names.push_back(name);
  SamplerBase::setupVariables(var_names);
}
Exemple #7
0
EigenKernel::EigenKernel(const InputParameters & parameters) :
    KernelBase(parameters),
    _u(_is_implicit ? _var.sln() : _var.slnOld()),
    _grad_u(_is_implicit ? _var.gradSln() : _var.gradSlnOld()),
    _eigen(getParam<bool>("eigen")),
    _eigen_sys(dynamic_cast<EigenSystem *>(&_fe_problem.getNonlinearSystem())),
    _eigenvalue(NULL)
{
  // The name to the postprocessor storing the eigenvalue
  std::string eigen_pp_name;

  // If the "eigen_postprocessor" is given, use it. The isParamValid does not work here because of the default value, which
  // you don't want to use if an EigenExecutioner exists.
  if (hasPostprocessor("eigen_postprocessor"))
    eigen_pp_name = getParam<PostprocessorName>("eigen_postprocessor");

  // Attempt to extract the eigenvalue postprocessor from the Executioner
  else
  {
    EigenExecutionerBase * exec = dynamic_cast<EigenExecutionerBase *>(_app.getExecutioner());
    if (exec)
      eigen_pp_name = exec->getParam<PostprocessorName>("bx_norm");
  }

  // If the postprocessor name was not provided and an EigenExecutionerBase is not being used,
  // use the default value from the "eigen_postprocessor" parameter
  if (eigen_pp_name.empty())
    _eigenvalue = &getDefaultPostprocessorValue("eigen_postprocessor");

  // If the name does exist, then use the postprocessor value
  else
  {
    if (_is_implicit)
      _eigenvalue = &getPostprocessorValueByName(eigen_pp_name);
    else
    {
      EigenExecutionerBase * exec = dynamic_cast<EigenExecutionerBase *>(_app.getExecutioner());
      if (exec)
        _eigenvalue = &exec->eigenvalueOld();
      else
        _eigenvalue = &getPostprocessorValueOldByName(eigen_pp_name);
    }
  }
}
Exemple #8
0
// DEPRECATED CONSTRUCTOR
Terminator::Terminator(const std::string & deprecated_name, InputParameters parameters) :
    GeneralUserObject(deprecated_name, parameters),
    _pp_names(),
    _pp_values(),
    _expression(getParam<std::string>("expression")),
    _fp()
{
  // build the expression object
  if (_fp.ParseAndDeduceVariables(_expression, _pp_names) >= 0)
     mooseError(std::string("Invalid function\n" + _expression + "\nin Terminator.\n") + _fp.ErrorMsg());

  _pp_num = _pp_names.size();
  _pp_values.resize(_pp_num);

  // get all necessary postprocessors
  for (unsigned int i = 0; i < _pp_num; ++i)
    _pp_values[i] = &getPostprocessorValueByName(_pp_names[i]);

  _params = new Real[_pp_num];
}
Exemple #9
0
EigenKernel::EigenKernel(const std::string & name, InputParameters parameters) :
    KernelBase(name,parameters),
    _u(_is_implicit ? _var.sln() : _var.slnOld()),
    _grad_u(_is_implicit ? _var.gradSln() : _var.gradSlnOld()),
    _eigen(getParam<bool>("eigen")),
    _eigen_sys(NULL),
    _eigenvalue(NULL)
{
  if (_eigen)
  {
    _eigen_sys = static_cast<EigenSystem *>(&_fe_problem.getNonlinearSystem());
    _eigen_pp = _fe_problem.parameters().get<PostprocessorName>("eigen_postprocessor");
    if (_is_implicit)
      _eigenvalue = &getPostprocessorValueByName(_eigen_pp);
    else
      _eigenvalue = &getPostprocessorValueOldByName(_eigen_pp);
  }
  else
  {
    if (!_fe_problem.parameters().isParamValid("eigenvalue"))
      _fe_problem.parameters().set<Real>("eigenvalue") = 1.0;
    _eigenvalue = &_fe_problem.parameters().get<Real>("eigenvalue");
  }
}
Exemple #10
0
Receiver::Receiver(const std::string & name, InputParameters params) :
    GeneralPostprocessor(name, params),
    _initialize_old(getParam<bool>("initialize_old")),
    _my_value(getPostprocessorValueByName(name))
{
}
Exemple #11
0
void
EigenExecutionerBase::inversePowerIteration(unsigned int min_iter,
                                            unsigned int max_iter,
                                            Real pfactor,
                                            bool cheb_on,
                                            Real tol_eig,
                                            bool echo,
                                            PostprocessorName xdiff,
                                            Real tol_x,
                                            Real & k,
                                            Real & initial_res)
{
  mooseAssert(max_iter>=min_iter, "Maximum number of power iterations must be greater than or equal to its minimum");
  mooseAssert(pfactor>0.0, "Invaid linear convergence tolerance");
  mooseAssert(tol_eig>0.0, "Invalid eigenvalue tolerance");
  mooseAssert(tol_x>0.0, "Invalid solution norm tolerance");

  // obtain the solution diff
  const PostprocessorValue * solution_diff = NULL;
  if (xdiff != "")
  {
    solution_diff = &getPostprocessorValueByName(xdiff);
    ExecFlagType xdiff_execflag = _problem.getUserObject<UserObject>(xdiff).execBitFlags();
    if ((xdiff_execflag & EXEC_LINEAR) == EXEC_NONE)
      mooseError("Postprocessor "+xdiff+" requires execute_on = 'linear'");
  }

  // not perform any iteration when max_iter==0
  if (max_iter==0) return;

  // turn off nonlinear flag so that RHS kernels opterate on previous solutions
  _eigen_sys.eigenKernelOnOld();

  // FIXME: currently power iteration use old and older solutions,
  // so save old and older solutions before they are changed by the power iteration
  _eigen_sys.saveOldSolutions();

  // save solver control parameters to be modified by the power iteration
  Real tol1 = _problem.es().parameters.get<Real> ("linear solver tolerance");
  unsigned int num1 = _problem.es().parameters.get<unsigned int>("nonlinear solver maximum iterations");

  // every power iteration is a linear solve, so set nonlinear iteration number to one
  _problem.es().parameters.set<Real> ("linear solver tolerance") = pfactor;
  _problem.es().parameters.set<unsigned int>("nonlinear solver maximum iterations") = 1;

  if (echo)
  {
    _console << std::endl;
    _console << " Power iterations starts" << std::endl;
    _console << " ________________________________________________________________________________ " << std::endl;
  }

  // some iteration variables
  Real k_old = 0.0;
  Real & source_integral_old = getPostprocessorValueOld("bx_norm");
  Real saved_source_integral_old = source_integral_old;
  Chebyshev_Parameters chebyshev_parameters;

  std::vector<Real> keff_history;
  std::vector<Real> diff_history;

  unsigned int iter = 0;

  // power iteration loop...
  // Note: |Bx|/k will stay constant one!
  makeBXConsistent(k);
  while (true)
  {
    if (echo)
      _console << " Power iteration= "<< iter << std::endl;

    // important: solutions of aux system is also copied
    _problem.advanceState();
    k_old = k;
    source_integral_old = _source_integral;

    preIteration();
    _problem.solve();
    postIteration();

    // save the initial residual
    if (iter==0) initial_res = _eigen_sys._initial_residual_before_preset_bcs;

    // update eigenvalue
    k = k_old * _source_integral / source_integral_old;
    _eigenvalue = k;

    if (echo)
    {
      // output on screen the convergence history only when we want to and MOOSE output system is not used
      keff_history.push_back(k);
      if (solution_diff) diff_history.push_back(*solution_diff);

      std::stringstream ss;
      if (solution_diff)
      {
        ss << std::endl;
        ss << " +================+=====================+=====================+\n";
        ss << " | iteration      | eigenvalue          | solution_difference |\n";
        ss << " +================+=====================+=====================+\n";
        unsigned int j = 0;
        if (keff_history.size()>10)
        {
          ss << " :                :                     :                     :\n";
          j = keff_history.size()-10;
        }
        for (; j<keff_history.size(); j++)
          ss << " | " << std::setw(14) << j
             << " | " << std::setw(19) << std::scientific << std::setprecision(8) << keff_history[j]
             << " | " << std::setw(19) << std::scientific << std::setprecision(8) << diff_history[j]
             << " |\n";
        ss << " +================+=====================+=====================+\n" << std::flush;
      }
      else
      {
        ss << std::endl;
        ss << " +================+=====================+\n";
        ss << " | iteration      | eigenvalue          |\n";
        ss << " +================+=====================+\n";
        unsigned int j = 0;
        if (keff_history.size()>10)
        {
          ss << " :                :                     :\n";
          j = keff_history.size()-10;
        }
        for (; j<keff_history.size(); j++)
          ss << " | " << std::setw(14) << j
             << " | " << std::setw(19) << std::scientific << std::setprecision(8) << keff_history[j]
             << " |\n";
        ss << " +================+=====================+\n" << std::flush;
        ss << std::endl;
      }
      _console << ss.str() << std::endl;
    }

    // increment iteration number here
    iter++;

    if (cheb_on)
    {
      chebyshev(chebyshev_parameters, iter, solution_diff);
      if (echo)
        _console << " Chebyshev step: " << chebyshev_parameters.icheb << std::endl;
    }

    if (echo)
      _console << " ________________________________________________________________________________ "
               << std::endl;

    // not perform any convergence check when number of iterations is less than min_iter
    if (iter>=min_iter)
    {
      // no need to check convergence of the last iteration
      if (iter!=max_iter)
      {
        bool converged = true;
        Real keff_error = fabs(k_old-k)/k;
        if (keff_error>tol_eig) converged = false;
        if (solution_diff)
          if (*solution_diff > tol_x) converged = false;
        if (converged) break;
      }
      else
        break;
    }
  }
  source_integral_old = saved_source_integral_old;

  // restore parameters changed by the executioner
  _problem.es().parameters.set<Real> ("linear solver tolerance") = tol1;
  _problem.es().parameters.set<unsigned int>("nonlinear solver maximum iterations") = num1;

  //FIXME: currently power iteration use old and older solutions, so restore them
  _eigen_sys.restoreOldSolutions();
}
Exemple #12
0
void
ComputeViscCoeff::computeQpProperties()
{
    // Determine h (length used in definition of first and second order derivatives):
    Real h = _current_elem->hmin();
    Real eps = std::sqrt(std::numeric_limits<Real>::min());
    
    /** Compute the first order viscosity and the mach number: **/
    Real c = std::sqrt(_eos.c2_from_p_rho(_rho[_qp], _pressure[_qp]));
    RealVectorValue vel(_vel_x[_qp], _vel_y[_qp], _vel_z[_qp]);
    _mu_max[_qp] = _Cmax*h*vel.size();
    _kappa_max[_qp] = _Cmax*h*(vel.size() + c);
    _beta_max[_qp] = _Cmax*h*_velI[_qp].size();
    
    /** Compute the Mach number: **/
    Real Mach = std::min(vel.size()/c, 1.);
//    Real Mach2 = _areViscEqual ? Mach*Mach: 1.;
    Real Mach2 = Mach*Mach;
    Real fct_of_mach = Mach;
    switch (_fct_of_mach_type) {
        case MACH:
            fct_of_mach = std::min(Mach, 1.);
            break;
        case SQRT_MACH:
            fct_of_mach = std::min(std::sqrt(Mach), 1.);
            break;
        case FCT_OF_MACH:
            fct_of_mach = std::min(Mach*std::sqrt(4+(1.-Mach*Mach)*(1.-Mach*Mach)) / (1.+Mach*Mach),1.);
            break;
        default:
            mooseError("The function with name: \"" << _fct_of_mach_name << "\" is not supported in the \"ComputeViscCoeff\" type of material.");
    }
    
    // Postprocessors:
    Real rhov2_pps = std::max(getPostprocessorValueByName(_rhov2_pps_name), eps);
    Real alpha_var = getPostprocessorValueByName(_alpha_pps_name);
    
    // Initialyze some variables used in the switch statement:
//    h = _current_elem->hmin()/_qrule->get_order();
    Real weight0, weight1, weight2;
    Real mu_e, kappa_e, beta_e;
    Real jump, residual, norm, sigma;
    
    // Switch statement over viscosity type:
    switch (_visc_type) {
        case LAPIDUS:
            if (_t_step == 1) {
                _mu[_qp] = _mu_max[_qp];
                _kappa[_qp] = _kappa_max[_qp];
                _beta[_qp] = _beta_max[_qp];
            }
            else {
                _mu[_qp] = _Ce*h*h*std::fabs(_grad_vel_x[_qp](0));
                _kappa[_qp] = _mu[_qp];
                _beta[_qp] = _mu[_qp];
            }
            break;
        case FIRST_ORDER:
            _mu[_qp] = _kappa_max[_qp];
            _kappa[_qp] = _kappa_max[_qp];
            _beta[_qp] = _beta_max[_qp];
            break;
        case FIRST_ORDER_MACH:
            _mu[_qp] = Mach*Mach*_mu_max[_qp];
            _kappa[_qp] = _kappa_max[_qp];
            _beta[_qp] = _beta_max[_qp];
            break;
        case ENTROPY:
            // Compute the weights for BDF2
            if (_t_step > 1)
            {
                weight0 = (2.*_dt+_dt_old)/(_dt*(_dt+_dt_old));
                weight1 = -(_dt+_dt_old)/(_dt*_dt_old);
                weight2 = _dt/(_dt_old*(_dt+_dt_old));
            }
            else
            {
                weight0 =  1. / _dt;
                weight1 = -1. / _dt;
                weight2 = 0.;
            }
            
        /** Compute viscosity coefficient for void fraction equation: **/
            residual = 0.;
            residual = _velI[_qp]*_grad_alpha_l[_qp];
            residual += (weight0*_alpha_l[_qp]+weight1*_alpha_l_old[_qp]+weight2*_alpha_l_older[_qp]);
            residual *= _Ce;
            if (_isJumpOn)
                jump = _Calpha*std::fabs(_velI[_qp].size()*_jump_grad_alpha[_qp]);
            else
                jump = _Calpha*std::fabs(_velI[_qp].size()*_grad_alpha_l[_qp](0));
//            norm = std::min(_alpha_l[_qp], std::fabs(1.-_alpha_l[_qp]));
            norm = alpha_var;
            beta_e = h*h*(std::fabs(residual)+jump) / norm;
//            beta_e += h*h*std::fabs(vel*_grad_area[_qp])/_area[_qp];
//            if (std::fabs(residual)>1e-3) {
//                std::cout<<"$$$$$$$$$$$$$$$$$"<<std::endl;
//                std::cout<<"alpha="<<_alpha_l[_qp]<<std::endl;
//                std::cout<<"alpha old="<<_alpha_l_old[_qp]<<std::endl;
//                std::cout<<"alpha older="<<_alpha_l_older[_qp]<<std::endl;
//                std::cout<<"grad="<<_grad_alpha_l[_qp](0)<<std::endl;
//                std::cout<<"vel="<<_velI[_qp]<<std::endl;
//                std::cout<<"residual="<<residual<<std::endl;
//                std::cout<<"pps="<<norm<<std::endl;
//            }
        /** Compute viscosity coefficient for continuity, momentum and energy equations: **/
            // Entropy residual:
            residual = 0.;
            residual = vel*_grad_press[_qp];
            residual += (weight0*_pressure[_qp]+weight1*_pressure_old[_qp]+weight2*_pressure_older[_qp]);
            residual -= c*c*vel*_grad_rho[_qp];
            residual -= c*c*(weight0*_rho[_qp]+weight1*_rho_old[_qp]+weight2*_rho_older[_qp]);
            residual *= _Ce;
            
            if (_isShock) // non-isentropic flow.
            {
                // Compute the jumps for mu_e:
                if (_isJumpOn)
                    jump = _Cjump*vel.size()*std::max( _jump_grad_press[_qp], Mach2*c*c*_jump_grad_dens[_qp] );
                else
                    jump = _Cjump*vel.size()*std::max( _grad_press[_qp].size(), Mach2*c*c*_grad_rho[_qp].size() );
                
                // Compute high-order viscosity coefficient mu_e:
                norm = 0.5 * std::max( (1.-Mach)*rhov2_pps, _rho[_qp]*std::min(vel.size_sq(), c*c) );
                mu_e = h*h*(std::fabs(residual) + jump) / norm;
                mu_e += h*h*_pressure[_qp] * std::fabs(vel * _grad_area[_qp]) / ( _area[_qp] * norm );
                                
                // Compute the jumps for kappa_e:
                if (_isJumpOn)
                    jump = _Cjump*vel.size()*std::max( _jump_grad_press[_qp], c*c*_jump_grad_dens[_qp] );
                else
                    jump = _Cjump*vel.size()*std::max( _grad_press[_qp].size(), c*c*_grad_rho[_qp].size() );

                // Compute high-order viscosity coefficient kappa_e:
//                norm = 0.5*( std::fabs(1.-Mach)*_rho[_qp]*c*c + Mach*_rho[_qp]*std::min(vel.size_sq(), c*c) );
                if (!_areViscEqual)
                    norm = 0.5*_rho[_qp]*c*c;
                kappa_e = h*h*(std::fabs(residual) + jump) / norm;
                kappa_e += h*h*_pressure[_qp] * std::fabs(vel * _grad_area[_qp]) / ( _area[_qp] * norm );
            }
            else // with function sigma.
            {
                // Compute the jumps:
                if (_isJumpOn)
                    jump = _Cjump*vel.size()*std::max( _jump_grad_press[_qp], c*c*_jump_grad_dens[_qp] );
                else
                    jump = _Cjump*vel.size()*std::max( _grad_press[_qp].size(), c*c*_grad_rho[_qp].size() );
                
                // Compute the function sigma:
                sigma = 0.5 * std::tanh(_a_coeff*(Mach-_Mthres));
                sigma += 0.5 * std::abs(std::tanh(_a_coeff*(Mach-_Mthres)));
                
                // Compute mu_e:
                norm = (1.-sigma) * _rho[_qp] * c * c;
                norm += sigma * _rho[_qp] * vel.size_sq();
                norm *= 0.5;
                mu_e = h*h*(std::fabs(residual) + jump) / norm;
                
                // Compute kappa_e:
                norm = 0.5 * _rho[_qp] * c * c;
                kappa_e = h*h*(std::fabs(residual) + jump) / norm;
                
//                // Compute high-order viscosity coefficients:
//                norm = 0.5*( std::fabs(1.-Mach)*_rho[_qp]*c*c + Mach*_rho[_qp]*vel.size_sq() );
//                kappa_e = h*h*std::max(std::fabs(residual), jump) / norm;
////                kappa_e += h*h*_pressure[_qp] * std::fabs(vel * _grad_area[_qp]) / ( _area[_qp] * norm );
//                kappa_e += h*h*std::fabs(vel*_grad_area[_qp])/_area[_qp];
//                mu_e = kappa_e;
            }
            
        /** Compute the viscosity coefficients: **/
            if (_t_step == 1)
            {
                _mu[_qp] = 2*_kappa_max[_qp];
                _kappa[_qp] = 2*_kappa_max[_qp];
                _beta[_qp] = 2*_beta_max[_qp];
            }
            else
            {
                _beta[_qp] = std::min(_beta_max[_qp], beta_e);
                _kappa[_qp] = std::min( _kappa_max[_qp], kappa_e );
                _mu[_qp] = std::min( _kappa_max[_qp], mu_e );
            }
            break;
        default:
            mooseError("The viscosity type entered in the input file is not implemented.");
            break;
    }
}