LCOV - code coverage report
Current view: top level - src/materials - ADInterfaceOrientationMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #30119 (aa6062) with base 79f9bd Lines: 32 34 94.1 %
Date: 2025-03-20 17:26:41 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://www.mooseframework.org
       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 "ADInterfaceOrientationMaterial.h"
      11             : #include "MooseMesh.h"
      12             : #include "MathUtils.h"
      13             : 
      14             : registerMooseObject("PhaseFieldApp", ADInterfaceOrientationMaterial);
      15             : 
      16             : InputParameters
      17          19 : ADInterfaceOrientationMaterial::validParams()
      18             : {
      19          19 :   InputParameters params = Material::validParams();
      20          19 :   params.addClassDescription("2D interfacial anisotropy");
      21          38 :   params.addParam<Real>(
      22          38 :       "anisotropy_strength", 0.04, "Strength of the anisotropy (typically < 0.05)");
      23          38 :   params.addParam<unsigned int>("mode_number", 6, "Mode number for anisotropy");
      24          38 :   params.addParam<Real>(
      25          38 :       "reference_angle", 90, "Reference angle for defining anisotropy in degrees");
      26          38 :   params.addParam<Real>("eps_bar", 0.01, "Average value of the interface parameter epsilon");
      27          38 :   params.addRequiredCoupledVar("op", "Order parameter defining the solid phase");
      28          19 :   return params;
      29           0 : }
      30             : 
      31          15 : ADInterfaceOrientationMaterial::ADInterfaceOrientationMaterial(const InputParameters & parameters)
      32             :   : Material(parameters),
      33          15 :     _delta(getParam<Real>("anisotropy_strength")),
      34          30 :     _j(getParam<unsigned int>("mode_number")),
      35          30 :     _theta0(getParam<Real>("reference_angle")),
      36          30 :     _eps_bar(getParam<Real>("eps_bar")),
      37          15 :     _eps(declareADProperty<Real>("eps")),
      38          15 :     _deps(declareADProperty<Real>("deps")),
      39          15 :     _op(adCoupledValue("op")),
      40          30 :     _grad_op(adCoupledGradient("op"))
      41             : {
      42             :   // this currently only works in 2D simulations
      43          15 :   if (_mesh.dimension() != 2)
      44           0 :     mooseError("ADInterfaceOrientationMaterial requires a two-dimensional mesh.");
      45          15 : }
      46             : 
      47             : void
      48      897024 : ADInterfaceOrientationMaterial::computeQpProperties()
      49             : {
      50             :   const Real tol = 1e-9;
      51      897024 :   const Real cutoff = 1.0 - tol;
      52             : 
      53             :   // cosine of the gradient orientation angle
      54      897024 :   ADReal n = 0.0;
      55      897024 :   const ADReal nsq = _grad_op[_qp].norm_sq();
      56      897024 :   if (nsq > tol)
      57     1334496 :     n = std::max(-cutoff, std::min(_grad_op[_qp](0) / std::sqrt(nsq), cutoff));
      58             : 
      59             :   // Calculate interfacial parameter epsilon and its derivative
      60     1794048 :   const ADReal angle = std::acos(n) * MathUtils::sign(_grad_op[_qp](1));
      61     3588096 :   _eps[_qp] = _eps_bar * (_delta * std::cos(_j * (angle - _theta0 * libMesh::pi / 180.0)) + 1.0);
      62     2691072 :   _deps[_qp] = -_eps_bar * _delta * _j * std::sin(_j * (angle - _theta0 * libMesh::pi / 180.0));
      63      897024 : }

Generated by: LCOV version 1.14