LCOV - code coverage report
Current view: top level - src/materials - InterfaceOrientationMultiphaseMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #32971 (54bef8) with base c6cf66 Lines: 74 76 97.4 %
Date: 2026-05-29 20:38:39 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "InterfaceOrientationMultiphaseMaterial.h"
      11             : #include "MooseMesh.h"
      12             : #include "MathUtils.h"
      13             : 
      14             : registerMooseObject("PhaseFieldApp", InterfaceOrientationMultiphaseMaterial);
      15             : 
      16             : InputParameters
      17         124 : InterfaceOrientationMultiphaseMaterial::validParams()
      18             : {
      19         124 :   InputParameters params = Material::validParams();
      20         124 :   params.addClassDescription(
      21             :       "This Material accounts for the the orientation dependence "
      22             :       "of interfacial energy for multi-phase multi-order parameter phase-field model.");
      23         248 :   params.addRequiredParam<MaterialPropertyName>("kappa_name",
      24             :                                                 "Name of the kappa for the given phase");
      25         248 :   params.addRequiredParam<MaterialPropertyName>(
      26             :       "dkappadgrad_etaa_name", "Name of the derivative of kappa w.r.t. the gradient of eta");
      27         248 :   params.addRequiredParam<MaterialPropertyName>(
      28             :       "d2kappadgrad_etaa_name",
      29             :       "Name of the second derivative of kappa w.r.t. the gradient of eta");
      30         248 :   params.addParam<Real>(
      31         248 :       "anisotropy_strength", 0.04, "Strength of the anisotropy (typically < 0.05)");
      32         248 :   params.addParam<unsigned int>("mode_number", 4, "Mode number for anisotropy");
      33         248 :   params.addParam<Real>(
      34         248 :       "reference_angle", 90, "Reference angle for defining anisotropy in degrees");
      35         248 :   params.addParam<Real>("kappa_bar", 0.1125, "Average value of the interface parameter kappa");
      36         248 :   params.addRequiredCoupledVar("etaa", "Order parameter for the current phase alpha");
      37         248 :   params.addRequiredCoupledVar("etab", "Order parameter for the neighboring phase beta");
      38         124 :   return params;
      39           0 : }
      40             : 
      41          96 : InterfaceOrientationMultiphaseMaterial::InterfaceOrientationMultiphaseMaterial(
      42          96 :     const InputParameters & parameters)
      43             :   : Material(parameters),
      44         192 :     _kappa_name(getParam<MaterialPropertyName>("kappa_name")),
      45          96 :     _dkappadgrad_etaa_name(getParam<MaterialPropertyName>("dkappadgrad_etaa_name")),
      46          96 :     _d2kappadgrad_etaa_name(getParam<MaterialPropertyName>("d2kappadgrad_etaa_name")),
      47         192 :     _delta(getParam<Real>("anisotropy_strength")),
      48         192 :     _j(getParam<unsigned int>("mode_number")),
      49         192 :     _theta0(getParam<Real>("reference_angle")),
      50         192 :     _kappa_bar(getParam<Real>("kappa_bar")),
      51          96 :     _kappa(declareProperty<Real>(_kappa_name)),
      52          96 :     _dkappadgrad_etaa(declareProperty<RealGradient>(_dkappadgrad_etaa_name)),
      53          96 :     _d2kappadgrad_etaa(declareProperty<RealTensorValue>(_d2kappadgrad_etaa_name)),
      54          96 :     _etaa(coupledValue("etaa")),
      55          96 :     _grad_etaa(coupledGradient("etaa")),
      56          96 :     _etab(coupledValue("etab")),
      57         192 :     _grad_etab(coupledGradient("etab"))
      58             : {
      59             :   // this currently only works in 2D simulations
      60          96 :   if (_mesh.dimension() != 2)
      61           0 :     mooseError("InterfaceOrientationMultiphaseMaterial requires a two-dimensional mesh.");
      62          96 : }
      63             : 
      64             : void
      65      871200 : InterfaceOrientationMultiphaseMaterial::computeQpProperties()
      66             : {
      67             :   const Real tol = 1e-9;
      68             :   const Real cutoff = 1.0 - tol;
      69             : 
      70             :   // Normal direction of the interface
      71             :   Real n = 0.0;
      72      871200 :   const RealGradient nd = _grad_etaa[_qp] - _grad_etab[_qp];
      73             :   const Real nx = nd(0);
      74             :   const Real ny = nd(1);
      75      871200 :   const Real n2x = nd(0) * nd(0);
      76      871200 :   const Real n2y = nd(1) * nd(1);
      77             :   const Real nsq = nd.norm_sq();
      78      871200 :   const Real n2sq = nsq * nsq;
      79      871200 :   if (nsq > tol)
      80      703890 :     n = nx / std::sqrt(nsq);
      81             : 
      82      703890 :   if (n > cutoff)
      83             :     n = cutoff;
      84             : 
      85      845944 :   if (n < -cutoff)
      86             :     n = -cutoff;
      87             : 
      88             :   // Calculate the orientation angle
      89      871200 :   const Real angle = std::acos(n) * MathUtils::sign(ny);
      90             : 
      91             :   // Compute derivatives of the angle wrt n
      92      871200 :   const Real dangledn = -MathUtils::sign(ny) / std::sqrt(1.0 - n * n);
      93      871200 :   const Real d2angledn2 = -MathUtils::sign(ny) * n / (1.0 - n * n) / std::sqrt(1.0 - n * n);
      94             : 
      95             :   // Compute derivative of n wrt grad_eta
      96             :   RealGradient dndgrad_etaa;
      97      871200 :   if (nsq > tol)
      98             :   {
      99      703890 :     dndgrad_etaa(0) = ny * ny;
     100      703890 :     dndgrad_etaa(1) = -nx * ny;
     101      703890 :     dndgrad_etaa /= nsq * std::sqrt(nsq);
     102             :   }
     103             : 
     104             :   // Compute the square of dndgrad_etaa
     105             :   RealTensorValue dndgrad_etaa_sq;
     106      871200 :   if (nsq > tol)
     107             :   {
     108      703890 :     dndgrad_etaa_sq(0, 0) = n2y * n2y;
     109      703890 :     dndgrad_etaa_sq(0, 1) = -nx * ny * n2y;
     110      703890 :     dndgrad_etaa_sq(1, 0) = -nx * ny * n2y;
     111      703890 :     dndgrad_etaa_sq(1, 1) = n2x * n2y;
     112      703890 :     dndgrad_etaa_sq /= n2sq * nsq;
     113             :   }
     114             : 
     115             :   // Compute the second derivative of n wrt grad_eta
     116             :   RealTensorValue d2ndgrad_etaa2;
     117      871200 :   if (nsq > tol)
     118             :   {
     119      703890 :     d2ndgrad_etaa2(0, 0) = -3.0 * nx * n2y;
     120      703890 :     d2ndgrad_etaa2(0, 1) = -ny * n2y + 2.0 * ny * n2x;
     121      703890 :     d2ndgrad_etaa2(1, 0) = -ny * n2y + 2.0 * ny * n2x;
     122      703890 :     d2ndgrad_etaa2(1, 1) = -nx * n2x + 2.0 * nx * n2y;
     123      703890 :     d2ndgrad_etaa2 /= n2sq * std::sqrt(nsq);
     124             :   }
     125             : 
     126             :   // Calculate interfacial coefficient kappa and its derivatives wrt the angle
     127      871200 :   Real anglediff = _j * (angle - _theta0 * libMesh::pi / 180.0);
     128      871200 :   _kappa[_qp] =
     129      871200 :       _kappa_bar * (1.0 + _delta * std::cos(anglediff)) * (1.0 + _delta * std::cos(anglediff));
     130      871200 :   Real dkappadangle =
     131      871200 :       -2.0 * _kappa_bar * _delta * _j * (1.0 + _delta * std::cos(anglediff)) * std::sin(anglediff);
     132      871200 :   Real d2kappadangle =
     133      871200 :       2.0 * _kappa_bar * _delta * _delta * _j * _j * std::sin(anglediff) * std::sin(anglediff) -
     134      871200 :       2.0 * _kappa_bar * _delta * _j * _j * (1.0 + _delta * std::cos(anglediff)) *
     135             :           std::cos(anglediff);
     136             : 
     137             :   // Compute derivatives of kappa wrt grad_eta
     138      871200 :   _dkappadgrad_etaa[_qp] = dkappadangle * dangledn * dndgrad_etaa;
     139      871200 :   _d2kappadgrad_etaa[_qp] = d2kappadangle * dangledn * dangledn * dndgrad_etaa_sq +
     140      871200 :                             dkappadangle * d2angledn2 * dndgrad_etaa_sq +
     141      871200 :                             dkappadangle * dangledn * d2ndgrad_etaa2;
     142      871200 : }

Generated by: LCOV version 1.14