LynxDamageDeformation.C 25.4 KB
Newer Older
Antoine Jacquey's avatar
Antoine Jacquey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/******************************************************************************/
/*                       LYNX, a MOOSE-based application                      */
/*                                                                            */
/*          Copyright (C) 2017 by Antoine B. Jacquey and Mauro Cacace         */
/*             GFZ Potsdam, German Research Centre for Geosciences            */
/*                                                                            */
/*    This program is free software: you can redistribute it and/or modify    */
/*    it under the terms of the GNU General Public License as published by    */
/*      the Free Software Foundation, either version 3 of the License, or     */
/*                     (at your option) any later version.                    */
/*                                                                            */
/*       This program is distributed in the hope that it will be useful,      */
/*       but WITHOUT ANY WARRANTY; without even the implied warranty of       */
/*        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       */
/*                GNU General Public License for more details.                */
/*                                                                            */
/*      You should have received a copy of the GNU General Public License     */
/*    along with this program. If not, see <http://www.gnu.org/licenses/>     */
/******************************************************************************/

#include "LynxDamageDeformation.h"
#include "libmesh/utility.h"

registerMooseObject("LynxApp", LynxDamageDeformation);

template <>
InputParameters
validParams<LynxDamageDeformation>()
{
30
  InputParameters params = validParams<LynxDeformationBase>();
Antoine Jacquey's avatar
Antoine Jacquey committed
31 32 33 34 35 36 37
  params.addClassDescription("Class calculating the deformation of a material following a "
                             "damage viscoelasto-(visco)plastic rheology.");
  // Coupled variables
  params.addCoupledVar("damage", "The damage variable.");
  params.addCoupledVar("porosity", "The porosity variable.");
  // Elastic moduli parameters
  params.addParam<std::vector<Real>>("damage_modulus",
38 39 40 41 42
                                     "The third elastic damage modulus for the damage rheology.");
  // Damage-Plasticity parameters
  params.addParam<std::vector<Real>>(
      "friction_angle",
      "The friction angle of the material for the pressure-dependant part of the yield stress.");
43 44 45
  params.addParam<std::vector<Real>>("cohesion",
                                     "The constant coefficient of the yield stress corresponding "
                                     "to the cohesion of the material.");
46 47 48 49 50 51 52 53 54 55
  params.addParam<std::vector<Real>>(
      "porous_coeff",
      "The porous coefficient controlling the capped yield in the damage rheology.");
  params.addParam<std::vector<Real>>(
      "porous_coeff_linear", "The linear dependency of the porous coefficient to porosity.");
  params.addParam<std::vector<Real>>(
      "plastic_viscosity",
      "The reference viscosity in the generalized Duvaut-Lions viscoplastic formulation.");
  params.addParam<std::vector<Real>>("damage_viscosity",
                                     "The reference viscosity in the damage rheology.");
Antoine Jacquey's avatar
Antoine Jacquey committed
56 57 58 59
  return params;
}

LynxDamageDeformation::LynxDamageDeformation(const InputParameters & parameters)
60
  : LynxDeformationBase(parameters),
Antoine Jacquey's avatar
Antoine Jacquey committed
61 62 63 64 65 66 67 68 69
    // Coupled variables
    _coupled_dam(isCoupled("damage")),
    _damage(_coupled_dam ? coupledValue("damage") : _zero),
    _damage_old(_coupled_dam ? coupledValueOld("damage") : _zero),
    _coupled_phi(isCoupled("porosity")),
    _porosity(_coupled_phi ? coupledValue("porosity") : _zero),
    // Elastic moduli parameters
    _damage_modulus(isParamValid("damage_modulus") ? getLynxParam<Real>("damage_modulus")
                                                   : std::vector<Real>(_n_composition, 0.0)),
70 71 72 73

    // Damage-Plasticity parameters
    _friction_angle(isParamValid("friction_angle") ? getLynxParam<Real>("friction_angle")
                                                   : std::vector<Real>(_n_composition, 0.0)),
74 75
    _cohesion(isParamValid("cohesion") ? getLynxParam<Real>("cohesion")
                                       : std::vector<Real>(_n_composition, 0.0)),
76 77 78 79 80 81 82 83 84
    _porous_coeff(isParamValid("porous_coeff") ? getLynxParam<Real>("porous_coeff")
                                               : std::vector<Real>(_n_composition, 0.0)),
    _porous_coeff_linear(isParamValid("porous_coeff_linear")
                             ? getLynxParam<Real>("porous_coeff_linear")
                             : std::vector<Real>(_n_composition, 0.0)),
    _one_on_plastic_eta(isParamValid("plastic_viscosity") ? getLynxParam<Real>("plastic_viscosity")
                                                          : std::vector<Real>(_n_composition, 0.0)),
    _one_on_damage_eta(isParamValid("damage_viscosity") ? getLynxParam<Real>("damage_viscosity")
                                                        : std::vector<Real>(_n_composition, 0.0)),
Antoine Jacquey's avatar
Antoine Jacquey committed
85 86
    // Strain properties
    _elastic_strain(declareProperty<RankTwoTensor>("elastic_strain")),
87 88 89 90 91
    _elastic_strain_old(getMaterialPropertyOld<RankTwoTensor>("elastic_strain")),
    // Stress properties
    // _dstress_ddamage(declareProperty<RankTwoTensor>("dstress_ddamage")),
    // Damage properties
    _damage_rate(declareProperty<Real>("damage_rate"))
Antoine Jacquey's avatar
Antoine Jacquey committed
92
{
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  _has_plasticity = isParamValid("friction_angle");

  // Grabing the inverse of plastic and damage viscosities
  for (unsigned int i = 0; i < _n_composition; ++i)
  {
    if (_one_on_plastic_eta[i] < 0.0)
      mooseError("LynxDamageDeformation: 'plastic_viscosity' cannot be negative!");
    else if (_one_on_plastic_eta[i] > 0.0)
      _one_on_plastic_eta[i] = 1.0 / _one_on_plastic_eta[i];

    if (_one_on_damage_eta[i] < 0.0)
      mooseError("LynxDamageDeformation: 'damage_viscosity' cannot be negative!");
    else if (_one_on_damage_eta[i] > 0.0)
      _one_on_damage_eta[i] = 1.0 / _one_on_damage_eta[i];
  }

  // Damage-Plasticity structure
  if (_has_plasticity)
    _damage_plasticity = new damage_plasticity();
Antoine Jacquey's avatar
Antoine Jacquey committed
112 113
}

Antoine Jacquey's avatar
Antoine Jacquey committed
114 115 116 117
void
LynxDamageDeformation::initQpStatefulProperties()
{
  _elastic_strain[_qp].zero();
118
  LynxDeformationBase::initQpStatefulProperties();
Antoine Jacquey's avatar
Antoine Jacquey committed
119 120
}

Antoine Jacquey's avatar
Antoine Jacquey committed
121 122 123 124 125 126
void
LynxDamageDeformation::initializeQpDeformation()
{
  // Need to get _xi0
  initializeDamageParameters();

127 128 129 130
  // Initialize yield derivative
  _dyield_dp_tr = 0.0;
  _dyield_dq_tr = 0.0;

Antoine Jacquey's avatar
Antoine Jacquey committed
131 132 133
  LynxDeformationBase::initializeQpDeformation();
}

Antoine Jacquey's avatar
Antoine Jacquey committed
134 135 136
void
LynxDamageDeformation::elasticModuli()
{
Antoine Jacquey's avatar
Antoine Jacquey committed
137 138 139
  // Strain ratio
  const Real xi = strainRatio(_elastic_strain_old[_qp]);

Antoine Jacquey's avatar
Antoine Jacquey committed
140
  // Bulk modulus
Antoine Jacquey's avatar
Antoine Jacquey committed
141 142 143 144
  _K[_qp] = _has_bulk_modulus ? averageProperty(_bulk_modulus) -
                                    2.0 / 3.0 * _damage_old[_qp] * _damage_plasticity->_gamma *
                                        (xi / 2.0 - _damage_plasticity->_xi0)
                              : 0.0;
Antoine Jacquey's avatar
Antoine Jacquey committed
145 146

  // Shear modulus
Antoine Jacquey's avatar
Antoine Jacquey committed
147 148 149 150
  _G[_qp] = _has_shear_modulus
                ? averageProperty(_shear_modulus) - _damage_old[_qp] * _damage_plasticity->_gamma *
                                                        (xi / 2.0 - _damage_plasticity->_xi0)
                : 0.0;
Antoine Jacquey's avatar
Antoine Jacquey committed
151 152
}

Antoine Jacquey's avatar
Antoine Jacquey committed
153 154 155
void
LynxDamageDeformation::plasticCorrection(Real & pressure, RankTwoTensor & stress_dev)
{
156 157 158 159 160 161 162
  Real eqv_stress = std::sqrt(1.5) * stress_dev.L2norm();
  RankTwoTensor flow_dir = (eqv_stress != 0.0) ? stress_dev / eqv_stress : RankTwoTensor();

  computeDamageProperties(pressure, eqv_stress);

  // Check wether the yield is capped
  if (_damage_plasticity->_p_cr == 0.0)
Antoine Jacquey's avatar
Antoine Jacquey committed
163
  {
164 165
    // No capped yield - only deviatoric correction
    _plastic_yield_function[_qp] = computePlasticityYield(pressure, eqv_stress);
Antoine Jacquey's avatar
Antoine Jacquey committed
166 167

    // Plastic correction
168 169 170
    if (_plastic_yield_function[_qp] > 0.0)
    {
      Real plastic_incr = plasticIncrement(pressure, eqv_stress);
Antoine Jacquey's avatar
Antoine Jacquey committed
171

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
      _plastic_strain_incr[_qp] = 1.5 * plastic_incr * flow_dir;
      stress_dev -= 3.0 * _G[_qp] * plastic_incr * flow_dir;
      // Update yield
      _plastic_yield_function[_qp] -= 3.0 * _G[_qp] * plastic_incr;
    }
  }
  else
  {
    // Capped yield
    Real yield_squared = computeConvexPlasticityYield2(pressure, eqv_stress);
    _plastic_yield_function[_qp] =
        (yield_squared > 0.0) ? std::sqrt(yield_squared) : -std::sqrt(-yield_squared);

    if (_plastic_yield_function[_qp] > 0.0)
    {
      Real vol_plastic_incr = 0.0, eqv_plastic_incr = 0.0;
      Real rho_0 = convexPlasticIncrement(vol_plastic_incr, eqv_plastic_incr);

      _plastic_strain_incr[_qp] = 1.5 * eqv_plastic_incr * flow_dir;
      _plastic_strain_incr[_qp].addIa(-vol_plastic_incr / 3.0);

      pressure -= _K[_qp] * vol_plastic_incr;
      stress_dev -= 3.0 * _G[_qp] * eqv_plastic_incr * flow_dir;
      eqv_stress = std::sqrt(1.5) * stress_dev.L2norm();
      // Update yield
      _plastic_yield_function[_qp] =
          std::sqrt(Utility::pow<2>(pressure - _damage_plasticity->_p_r) +
                    Utility::pow<2>(eqv_stress - _damage_plasticity->_q_r)) -
          rho_0;
    }
Antoine Jacquey's avatar
Antoine Jacquey committed
202
  }
Antoine Jacquey's avatar
Antoine Jacquey committed
203 204 205 206 207 208 209 210 211 212 213 214

  // Update elastic strain
  _elastic_strain[_qp] = spinRotation(_elastic_strain_old[_qp].deviatoric());
  _elastic_strain[_qp].addIa(_elastic_strain_old[_qp].trace() / 3.0);

  _elastic_strain[_qp] +=
      _strain_increment[_qp] - _viscous_strain_incr[_qp] - _plastic_strain_incr[_qp];
}

void
LynxDamageDeformation::damageCorrection()
{
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
  // Rotate old elastic strain
  RankTwoTensor strain_el = spinRotation(_elastic_strain_old[_qp].deviatoric());
  strain_el.addIa(_elastic_strain_old[_qp].trace() / 3.0);
  Real xi = strainRatio(_elastic_strain_old[_qp]);

  // Build damage correction to the elasticity tensor
  RankTwoTensor e = (strain_el.L2norm() != 0.0) ? strain_el / strain_el.L2norm() : RankTwoTensor();
  _damaged_tensor =
      _damage_plasticity->_gamma *
      (e.outerProduct(_identity_two) + _identity_two.outerProduct(e) - xi * e.outerProduct(e));

  // Damage stress
  _damaged_stress = _damage_plasticity->_gamma * (xi - 2.0 * _damage_plasticity->_xi0) * strain_el;
  _damaged_stress.addIa(_damage_plasticity->_gamma * _elastic_strain_old[_qp].L2norm());

  // _dstress_ddamage[_qp] = -damaged_stress;

  // Correct stress
  _stress[_qp] -=
      _damage_old[_qp] * _damaged_tensor *
          (_strain_increment[_qp] - _viscous_strain_incr[_qp] - _plastic_strain_incr[_qp]) +
      _damaged_stress * (_damage[_qp] - _damage_old[_qp]);

  // Damage rate
  if ((_plastic_yield_function[_qp] > 0.0))
    _damage_rate[_qp] = _damage_plasticity->_eta_d * _plastic_yield_function[_qp];
  else
    _damage_rate[_qp] = 0.0;
}

RankFourTensor
LynxDamageDeformation::damageTangentOperator(const RankTwoTensor & flow_direction,
                                             const RankFourTensor & tme)
{
  RankTwoTensor dyield_dstrain_tr = RankTwoTensor();
  if ((_damage_rate[_qp] > 0.0) && (_damage_old[_qp] > 0.0) && (_damage[_qp] != _damage_old[_qp]))
  {
    dyield_dstrain_tr = 3.0 * _G[_qp] * _dyield_dq_tr * flow_direction;
    dyield_dstrain_tr.addIa(-_K[_qp] * _dyield_dp_tr);
  }

  return _damage_old[_qp] * _damaged_tensor * tme +
         _damage_plasticity->_eta_d * _damaged_stress.outerProduct(dyield_dstrain_tr) * _dt;
Antoine Jacquey's avatar
Antoine Jacquey committed
258 259
}

260 261
Real
LynxDamageDeformation::computePlasticityYield(const Real & pressure, const Real & eqv_stress)
Antoine Jacquey's avatar
Antoine Jacquey committed
262
{
263
  return eqv_stress - _damage_plasticity->_alpha0 * pressure - _damage_plasticity->_k0;
264
}
Antoine Jacquey's avatar
Antoine Jacquey committed
265

266 267 268 269
Real
LynxDamageDeformation::plasticIncrement(const Real & /*pressure*/, const Real & eqv_stress)
{
  Real eqv_p_strain_incr = 0.0;
Antoine Jacquey's avatar
Antoine Jacquey committed
270

271 272
  Real vp_correction = 1.0;
  eqv_p_strain_incr = _plastic_yield_function[_qp] / (3.0 * _G[_qp]);
Antoine Jacquey's avatar
Antoine Jacquey committed
273

274 275 276 277
  // Viscoplastic correction
  if (_damage_plasticity->_eta_p != 0.0)
  {
    vp_correction = (3.0 * _G[_qp]) * _dt * _damage_plasticity->_eta_p /
278
                    (1.0 + 3.0 * _G[_qp] * _dt * _damage_plasticity->_eta_p);
279 280
    eqv_p_strain_incr *= vp_correction;
  }
Antoine Jacquey's avatar
Antoine Jacquey committed
281

282 283
  // Update yield
  _plastic_yield_function[_qp] -= (3.0 * _G[_qp]) * eqv_p_strain_incr;
Antoine Jacquey's avatar
Antoine Jacquey committed
284

285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
  // Tangent operator
  if (_fe_problem.currentlyComputingJacobian())
  {

    _stress_corr_p =
        (eqv_stress != 0.0) ? (eqv_stress - 3.0 * _G[_qp] * eqv_p_strain_incr) / eqv_stress : 1.0;
    _dp_dp_tr_p = 1.0;
    _dp_dq_tr_p = 0.0;
    _dq_dp_tr_p = _damage_plasticity->_alpha0 * vp_correction;
    _dq_dq_tr_p = 1.0 - vp_correction;

    // Update yield derivative
    _dyield_dp_tr = _dq_dp_tr_p - _damage_plasticity->_alpha0 * _dp_dp_tr_p;
    _dyield_dq_tr = _dq_dq_tr_p - _damage_plasticity->_alpha0 * _dp_dq_tr_p;
    // _dyield_dp_tr = -_damage_plasticity->_alpha0;
    // _dyield_dq_tr = 1.0;
  }
Antoine Jacquey's avatar
Antoine Jacquey committed
302

303 304
  return eqv_p_strain_incr;
}
Antoine Jacquey's avatar
Antoine Jacquey committed
305

306 307 308 309 310
Real
LynxDamageDeformation::computeConvexPlasticityYield2(const Real & pressure, const Real & eqv_stress)
{
  if ((pressure == 0.0) && (eqv_stress == 0.0))
    return 0.0;
Antoine Jacquey's avatar
Antoine Jacquey committed
311

312
  updateDamageConvexParameters(pressure, eqv_stress);
Antoine Jacquey's avatar
Antoine Jacquey committed
313

314 315 316 317
  return Utility::pow<2>(eqv_stress) - _damage_plasticity->_alpha2 *
                                           Utility::pow<2>(pressure + _damage_plasticity->_p_k) *
                                           ((0.0 < pressure + _damage_plasticity->_p_k) -
                                            (pressure + _damage_plasticity->_p_k < 0.0));
Antoine Jacquey's avatar
Antoine Jacquey committed
318 319 320
}

Real
321
LynxDamageDeformation::computeConvexPlasticityYield2(const Real & rho)
Antoine Jacquey's avatar
Antoine Jacquey committed
322
{
323 324
  Real p = _damage_plasticity->_p_r + rho * _damage_plasticity->_rp;
  Real q = _damage_plasticity->_q_r + rho * _damage_plasticity->_rq;
Antoine Jacquey's avatar
Antoine Jacquey committed
325

326
  return computeConvexPlasticityYield2(p, q);
Antoine Jacquey's avatar
Antoine Jacquey committed
327 328 329
}

Real
330
LynxDamageDeformation::convexPlasticIncrement(Real & vol_plastic_incr, Real & eqv_plastic_incr)
Antoine Jacquey's avatar
Antoine Jacquey committed
331
{
332 333 334 335 336 337
  Real vp_correction = 1.0;

  // Find projection on convex yield
  Real rho_neg = 0.0;
  Real rho_pos = _damage_plasticity->_rho_tr;
  Real rho_0 = getConvexProjection(rho_neg, rho_pos);
Antoine Jacquey's avatar
Antoine Jacquey committed
338

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
  // Update projections
  Real p_0 = _damage_plasticity->_p_r + rho_0 * _damage_plasticity->_rp;
  Real q_0 = _damage_plasticity->_q_r + rho_0 * _damage_plasticity->_rq;

  // Plastic strain
  vol_plastic_incr = (_damage_plasticity->_p_tr - p_0) / _K[_qp];
  eqv_plastic_incr = (_damage_plasticity->_q_tr - q_0) / (3.0 * _G[_qp]);

  // Viscoplastic correction
  if (_damage_plasticity->_eta_p != 0.0)
  {
    Real F_tr = _damage_plasticity->_rho_tr - rho_0;
    Real delta_p = std::sqrt(Utility::pow<2>(vol_plastic_incr) + Utility::pow<2>(eqv_plastic_incr));

    vp_correction = (F_tr * _damage_plasticity->_eta_p * _dt / delta_p) /
                    (1.0 + F_tr * _damage_plasticity->_eta_p * _dt / delta_p);

    vol_plastic_incr *= vp_correction;
    eqv_plastic_incr *= vp_correction;
  }

  // Tangent operator
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
  if (_fe_problem.currentlyComputingJacobian())
  {

    _stress_corr_p = (_damage_plasticity->_q_tr != 0.0)
                         ? _damage_plasticity->_q_tr -
                               3.0 * _G[_qp] * eqv_plastic_incr / _damage_plasticity->_q_tr
                         : 1.0;
    Real dF2_dp0 = dConvexPlasticYield2_dp(p_0, q_0) / dConvexPlasticYield2(rho_0);
    Real dF2_dq0 = dConvexPlasticYield2_dq(p_0, q_0) / dConvexPlasticYield2(rho_0);

    // _dp_dp_tr_p =
    //     _dp_r_dp_tr + (1.0 - vp_correction) + vp_correction * rho_0 / _rho_tr * dF2_dq0 * _rq;
    // _dp_dq_tr_p = _dp_r_dq_tr - vp_correction * rho_0 / _rho_tr * dF2_dq0 * _rp;
    // _dq_dp_tr_p = -vp_correction * rho_0 / _rho_tr * dF2_dp0 * _rq;
    // _dq_dq_tr_p = (1.0 - vp_correction) + vp_correction * rho_0 / _rho_tr * dF2_dp0 * _rp;
    _dp_dp_tr_p = (1.0 - vp_correction) + vp_correction * rho_0 / _damage_plasticity->_rho_tr *
                                              dF2_dq0 * _damage_plasticity->_rq;
    _dp_dq_tr_p =
        -vp_correction * rho_0 / _damage_plasticity->_rho_tr * dF2_dq0 * _damage_plasticity->_rp;
    _dq_dp_tr_p =
        -vp_correction * rho_0 / _damage_plasticity->_rho_tr * dF2_dp0 * _damage_plasticity->_rq;
    _dq_dq_tr_p = (1.0 - vp_correction) + vp_correction * rho_0 / _damage_plasticity->_rho_tr *
                                              dF2_dp0 * _damage_plasticity->_rp;
    // Update yield derivative
    // MISSING calculations
    _dyield_dp_tr = 0.0;
    _dyield_dq_tr = 0.0;
  }
389 390

  return rho_0;
Antoine Jacquey's avatar
Antoine Jacquey committed
391 392
}

393 394
void
LynxDamageDeformation::computeDamageProperties(const Real & pressure, const Real & eqv_stress)
Antoine Jacquey's avatar
Antoine Jacquey committed
395
{
396 397 398 399 400
  updateDamageParameters();

  _damage_plasticity->_alpha0 = std::sqrt(2.0) * _G[_qp] / _K[_qp] *
                                std::sqrt((3.0 - Utility::pow<2>(_damage_plasticity->_xi0)) /
                                          Utility::pow<2>(_damage_plasticity->_xi0));
Antoine Jacquey's avatar
Antoine Jacquey committed
401

402 403 404
  // Properties for convex yield
  if (_damage_plasticity->_p_cr != 0.0)
  {
405 406 407
    // Pressure to fake cohesion
    _damage_plasticity->_p_k = _damage_plasticity->_k0 / _damage_plasticity->_alpha0;

408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
    // Trial pressure - deviatoric stress
    _damage_plasticity->_p_tr = pressure;
    _damage_plasticity->_q_tr = eqv_stress;

    // Reference point for convex yield
    _damage_plasticity->_p_r = convexReferencePressure();
    _damage_plasticity->_q_r = 0.0;

    // Trial distance
    _damage_plasticity->_rho_tr = std::sqrt(Utility::pow<2>(pressure - _damage_plasticity->_p_r) +
                                            Utility::pow<2>(eqv_stress - _damage_plasticity->_q_r));

    // Projection direction
    _damage_plasticity->_rp =
        (_damage_plasticity->_p_tr - _damage_plasticity->_p_r) / _damage_plasticity->_rho_tr;
    _damage_plasticity->_rq =
        (_damage_plasticity->_q_tr - _damage_plasticity->_q_r) / _damage_plasticity->_rho_tr;
  }
Antoine Jacquey's avatar
Antoine Jacquey committed
426 427
}

428 429
void
LynxDamageDeformation::updateDamageParameters()
Antoine Jacquey's avatar
Antoine Jacquey committed
430
{
431 432 433 434
  Real sin_phi = std::sin(averageProperty(_friction_angle) * libMesh::pi / 180.0);
  Real xi0 = -std::sqrt(3.0) / std::sqrt(1.0 + 1.5 * Utility::pow<2>(_K[_qp] / _G[_qp] * sin_phi));
  Real porous_coeff =
      averageProperty(_porous_coeff) + averageProperty(_porous_coeff_linear) * _porosity[_qp];
435 436 437 438
  Real p_cr = (porous_coeff != 0.0) ? _K[_qp] * (std::sqrt(3.0) + xi0) / (3.0 * porous_coeff) : 0.0;
  Real k0 = std::sqrt(3.0) * averageProperty(_cohesion) *
            std::cos(averageProperty(_friction_angle) * libMesh::pi / 180.0);

439 440 441
  _damage_plasticity->fill(xi0,
                           averageProperty(_damage_modulus),
                           p_cr,
442
                           k0,
443 444 445
                           averageProperty(_one_on_plastic_eta),
                           averageProperty(_one_on_damage_eta));
}
Antoine Jacquey's avatar
Antoine Jacquey committed
446

Antoine Jacquey's avatar
Antoine Jacquey committed
447 448 449 450 451 452 453 454 455 456
void
LynxDamageDeformation::initializeDamageParameters()
{
  Real sin_phi = std::sin(averageProperty(_friction_angle) * libMesh::pi / 180.0);
  Real xi0 = -std::sqrt(3.0) /
             std::sqrt(1.0 + 1.5 * Utility::pow<2>(averageProperty(_bulk_modulus) /
                                                   averageProperty(_shear_modulus) * sin_phi));
  Real porous_coeff =
      averageProperty(_porous_coeff) + averageProperty(_porous_coeff_linear) * _porosity[_qp];
  Real p_cr = _K[_qp] * (std::sqrt(3.0) + xi0) / (3.0 * porous_coeff);
457 458 459
  Real k0 = std::sqrt(3.0) * averageProperty(_cohesion) *
            std::cos(averageProperty(_friction_angle) * libMesh::pi / 180.0);

Antoine Jacquey's avatar
Antoine Jacquey committed
460 461 462
  _damage_plasticity->fill(xi0,
                           averageProperty(_damage_modulus),
                           p_cr,
463
                           k0,
Antoine Jacquey's avatar
Antoine Jacquey committed
464 465 466 467
                           averageProperty(_one_on_plastic_eta),
                           averageProperty(_one_on_damage_eta));
}

468 469 470
void
LynxDamageDeformation::updateDamageConvexParameters(const Real & pressure, const Real & eqv_stress)
{
Antoine Jacquey's avatar
Antoine Jacquey committed
471 472 473 474 475
  Real pq_term =
      (pressure != 0.0)
          ? 1.0 / (1.0 + 0.5 * Utility::pow<2>(_K[_qp] * eqv_stress / (_G[_qp] * pressure)))
          : 0.0;

476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
  _damage_plasticity->_xi_cr =
      (pressure > 0.0)
          ? _damage_plasticity->_xi0 - (std::sqrt(3.0) + _damage_plasticity->_xi0) * pressure /
                                           _damage_plasticity->_p_cr * pq_term
          : _damage_plasticity->_xi0;

  _damage_plasticity->_alpha2 = (_damage_plasticity->_xi_cr != 0.0)
                                    ? 2.0 * Utility::pow<2>(_G[_qp] / _K[_qp]) *
                                          (3.0 - Utility::pow<2>(_damage_plasticity->_xi_cr)) /
                                          Utility::pow<2>(_damage_plasticity->_xi_cr)
                                    : 0.0;
  _damage_plasticity->_dxi_cr_dp = (pressure != 0.0)
                                       ? -(_damage_plasticity->_xi0 - _damage_plasticity->_xi_cr) /
                                             pressure * (3.0 - 2.0 * pq_term)
                                       : 0.0;

  _damage_plasticity->_dxi_cr_dq =
      (eqv_stress != 0.0) ? 2.0 * (_damage_plasticity->_xi0 - _damage_plasticity->_xi_cr) /
                                eqv_stress * (1.0 - pq_term)
                          : 0.0;

  _damage_plasticity->_dmu2_dxi_cr =
      (_damage_plasticity->_xi_cr != 0.0)
          ? -12.0 * Utility::pow<2>(_G[_qp] / _K[_qp]) / Utility::pow<3>(_damage_plasticity->_xi_cr)
          : 0.0;
}
Antoine Jacquey's avatar
Antoine Jacquey committed
502

503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
Real
LynxDamageDeformation::convexReferencePressure()
{
  Real p_proj =
      (1.0 - Utility::pow<2>(_damage_plasticity->_alpha0) * _K[_qp] /
                 (3.0 * _G[_qp] + Utility::pow<2>(_damage_plasticity->_alpha0) * _K[_qp])) *
          _damage_plasticity->_p_tr +
      _damage_plasticity->_alpha0 * _K[_qp] * _damage_plasticity->_q_tr /
          (3.0 * _G[_qp] + Utility::pow<2>(_damage_plasticity->_alpha0) * _K[_qp]);

  return ((p_proj > 0.0) && (p_proj < _damage_plasticity->_p_cr))
             ? p_proj
             : 2.0 * _damage_plasticity->_p_cr / 3.0;
}

Real
LynxDamageDeformation::dConvexPlasticYield2(const Real & rho)
{
  Real p = _damage_plasticity->_p_r + rho * _damage_plasticity->_rp;
  Real q = _damage_plasticity->_q_r + rho * _damage_plasticity->_rq;

  return dConvexPlasticYield2_dp(p, q) * _damage_plasticity->_rp +
         dConvexPlasticYield2_dq(p, q) * _damage_plasticity->_rq;
Antoine Jacquey's avatar
Antoine Jacquey committed
526 527 528 529 530 531 532 533
}

Real
LynxDamageDeformation::dConvexPlasticYield2_dp(const Real & pressure, const Real & eqv_stress)
{
  if ((pressure == 0.0) && (eqv_stress == 0.0))
    return 0.0;

534 535
  updateDamageConvexParameters(pressure, eqv_stress);

536 537
  return -(_damage_plasticity->_dmu2_dxi_cr * _damage_plasticity->_dxi_cr_dp *
               (pressure + _damage_plasticity->_p_k) +
538
           2.0 * _damage_plasticity->_alpha2) *
539 540 541
         pressure *
         ((0.0 < pressure + _damage_plasticity->_p_k) -
          (pressure + _damage_plasticity->_p_k < 0.0));
Antoine Jacquey's avatar
Antoine Jacquey committed
542 543 544 545 546 547 548 549
}

Real
LynxDamageDeformation::dConvexPlasticYield2_dq(const Real & pressure, const Real & eqv_stress)
{
  if ((pressure == 0.0) && (eqv_stress == 0.0))
    return 0.0;

550
  updateDamageConvexParameters(pressure, eqv_stress);
Antoine Jacquey's avatar
Antoine Jacquey committed
551 552

  return 2.0 * eqv_stress -
553
         _damage_plasticity->_dmu2_dxi_cr * _damage_plasticity->_dxi_cr_dq *
554 555 556 557 558
             Utility::pow<2>(
                 pressure +
                 _damage_plasticity->_p_k); // *
                                            // ((0.0 < pressure + _damage_plasticity->_p_k) -
                                            // (pressure + _damage_plasticity->_p_k < 0.0));
Antoine Jacquey's avatar
Antoine Jacquey committed
559 560 561 562 563 564 565 566
}

Real
LynxDamageDeformation::getConvexProjection(const Real & x1, const Real & x2)
{
  // Machine floating-point precision
  const Real eps = std::numeric_limits<Real>::epsilon();
  // Declare some stuff here
567 568
  Real a = x1, b = x2, c = x2, d, e, fa = computeConvexPlasticityYield2(a),
       fb = computeConvexPlasticityYield2(b), fc, p, q, r, s, tol1, xm;
Antoine Jacquey's avatar
Antoine Jacquey committed
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
  // Chek if x1 and x2 bracket a root
  if (fa * fb > 0.0) // fa and fb are of the same sign
    throw MooseException("LynxDamageDeformation: in Brent's method, the points x1 and x2 must "
                         "bracket a root of the function!\n");

  fc = fb;
  for (unsigned int iter = 0; iter < _itmax; ++iter)
  {
    if (fb * fc > 0.0) // fb and fc are of the same sign
    {
      // Rename a, b, c and adjust bounding interval d
      c = a;
      fc = fa;
      e = d = b - a;
    }
    if (std::abs(fc) < std::abs(fb))
    {
      a = b;
      b = c;
      c = a;
      fa = fb;
      fb = fc;
      fc = fa;
    }
    // Convergence check
    tol1 = 2.0 * eps * std::abs(b) + 0.5 * _tol;
    xm = 0.5 * (c - b);
    if (std::abs(xm) <= tol1 || fb == 0.0) // Exit of the algorithm
      return b;
    if (std::abs(e) >= tol1 && std::abs(fa) > std::abs(fb))
    {
      s = fb / fa;
      if (a == c)
      {
        p = 2.0 * xm * s;
        q = 1.0 - s;
      }
      else
      {
        q = fa / fc;
        r = fb / fc;
        p = s * (2.0 * xm * q * (q - r) - (b - a) * (r - 1.0));
        q = (q - 1.0) * (r - 1.0) * (s - 1.0);
      }
      // Check wether in bounds
      if (p > 0.0)
        q = -q;
      p = std::abs(p);
      Real min1 = 3.0 * xm * q - std::abs(tol1 * q);
      Real min2 = std::abs(e * q);
      if (2.0 * p < (min1 < min2 ? min1 : min2))
      {
        // Accept interpolation
        e = d;
        d = p / q;
      }
      else
      {
        // Interpolation failed, use bisection
        d = xm;
        e = d;
      }
    }
    else
    {
      // Bounds decreasing too slowly, use bisection
      d = xm;
      e = d;
    }
    // Move last guess to a
    a = b;
    fa = fb;
    // Evaluate new trial root
    if (std::abs(d) > tol1)
      b += d;
    else
      b += (xm < 0 ? -std::abs(tol1) : std::abs(tol1));
646
    fb = computeConvexPlasticityYield2(b);
Antoine Jacquey's avatar
Antoine Jacquey committed
647 648 649
  }
  throw MooseException(
      "LynxDamageDeformation: maximum number of iterations exceeded in solveBrent!");
Antoine Jacquey's avatar
Antoine Jacquey committed
650 651 652 653 654 655 656 657 658 659 660 661 662
}

Real
LynxDamageDeformation::strainRatio(const RankTwoTensor & elastic_strain)
{
  const Real strain_v = elastic_strain.trace();
  const Real strain_norm = elastic_strain.L2norm();

  if (strain_norm != 0.0)
    return strain_v / strain_norm;
  else
    return -std::sqrt(3.0);
}
Antoine Jacquey's avatar
Antoine Jacquey committed
663 664 665 666 667 668 669 670 671 672

RankTwoTensor
LynxDamageDeformation::rotatedElasticStrain(const RankTwoTensor & elastic_strain)
{
  const Real strain_v = elastic_strain.trace();
  RankTwoTensor strain_rot = spinRotation(elastic_strain.deviatoric());
  strain_rot.addIa(strain_v / 3.0);

  return strain_rot;
}