Demo entry 6757335

residual and jacobian

   

Submitted by anonymous on Aug 09, 2018 at 02:01
Language: C++. Code size: 1.9 kB.

Real
ElectronsFromIonization::computeQpResidual()
{
  Real electron_flux_mag = (-_muem[_qp] * -_grad_potential[_qp] * _r_units * std::exp(_em[_qp]) -
                            _diffem[_qp] * std::exp(_em[_qp]) * _grad_em[_qp] * _r_units)
                               .norm();
  Real iz_term = _alpha_iz[_qp] * electron_flux_mag;

  return -_test[_i][_qp] * iz_term;
}

Real
ElectronsFromIonization::computeQpJacobian()
{
  if (_var.number() == _em_id)
  {
    Real actual_mean_en = std::exp(_mean_en[_qp] - _em[_qp]);

    Real d_iz_d_em = _d_iz_d_actual_mean_en[_qp] * actual_mean_en * -_phi[_j][_qp];
    Real d_muem_d_em = _d_muem_d_actual_mean_en[_qp] * actual_mean_en * -_phi[_j][_qp];
    Real d_diffem_d_em = _d_diffem_d_actual_mean_en[_qp] * actual_mean_en * -_phi[_j][_qp];

    RealVectorValue electron_flux =
        -_muem[_qp] * -_grad_potential[_qp] * _r_units * std::exp(_em[_qp]) -
        _diffem[_qp] * std::exp(_em[_qp]) * _grad_em[_qp] * _r_units;
    RealVectorValue d_electron_flux_d_em =
        -d_muem_d_em * -_grad_potential[_qp] * _r_units * std::exp(_em[_qp]) -
        _muem[_qp] * -_grad_potential[_qp] * _r_units * std::exp(_em[_qp]) * _phi[_j][_qp] -
        d_diffem_d_em * std::exp(_em[_qp]) * _grad_em[_qp] * _r_units -
        _diffem[_qp] * std::exp(_em[_qp]) * _phi[_j][_qp] * _grad_em[_qp] * _r_units -
        _diffem[_qp] * std::exp(_em[_qp]) * _grad_phi[_j][_qp] * _r_units;
    Real electron_flux_mag = electron_flux.norm();
    Real d_electron_flux_mag_d_em = electron_flux * d_electron_flux_d_em /
                                    (electron_flux_mag + std::numeric_limits<double>::epsilon());

    Real d_iz_term_d_em =
        (electron_flux_mag * d_iz_d_em + _alpha_iz[_qp] * d_electron_flux_mag_d_em);

    return -_test[_i][_qp] * d_iz_term_d_em;
  }
  else
    return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).