LCOV - code coverage report
Current view: top level - src/auxkernels - GrainAdvectionAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 38 39 97.4 %
Date: 2025-09-04 07:55:36 Functions: 4 4 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 "GrainAdvectionAux.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", GrainAdvectionAux);
      13             : 
      14             : InputParameters
      15         218 : GrainAdvectionAux::validParams()
      16             : {
      17         218 :   InputParameters params = AuxKernel::validParams();
      18         218 :   params.addClassDescription(
      19             :       "Calculates the advection velocity of grain due to rigid body translation and rotation");
      20         436 :   params.addParam<Real>(
      21         436 :       "translation_constant", 1.0, "constant value characterizing grain translation");
      22         436 :   params.addParam<Real>("rotation_constant", 1.0, "constant value characterizing grain rotation");
      23         436 :   params.addParam<UserObjectName>("grain_tracker_object",
      24             :                                   "userobject for getting volume and center of mass of grains");
      25         436 :   params.addParam<VectorPostprocessorName>("grain_volumes",
      26             :                                            "The feature volume VectorPostprocessorValue.");
      27         436 :   params.addParam<UserObjectName>("grain_force",
      28             :                                   "userobject for getting force and torque acting on grains");
      29         436 :   MooseEnum component("x=0 y=1 z=2");
      30         436 :   params.addParam<MooseEnum>("component", component, "The gradient component to compute");
      31         218 :   return params;
      32         218 : }
      33             : 
      34         114 : GrainAdvectionAux::GrainAdvectionAux(const InputParameters & parameters)
      35             :   : AuxKernel(parameters),
      36         114 :     _grain_tracker(
      37         114 :         dynamic_cast<const GrainTrackerInterface &>(getUserObjectBase("grain_tracker_object"))),
      38         114 :     _grain_volumes(getVectorPostprocessorValue("grain_volumes", "feature_volumes")),
      39         114 :     _grain_force_torque(
      40         114 :         dynamic_cast<const GrainForceAndTorqueInterface &>(getUserObjectBase("grain_force"))),
      41         114 :     _grain_forces(_grain_force_torque.getForceValues()),
      42         114 :     _grain_torques(_grain_force_torque.getTorqueValues()),
      43         228 :     _mt(getParam<Real>("translation_constant")),
      44         228 :     _mr(getParam<Real>("rotation_constant")),
      45         456 :     _component(getParam<MooseEnum>("component"))
      46             : {
      47         114 :   if (isNodal())
      48           0 :     mooseError("Advection velocity can be assigned to elemental variables only.");
      49         114 : }
      50             : 
      51             : void
      52       97436 : GrainAdvectionAux::precalculateValue()
      53             : {
      54             :   // ID of unique grain at current point
      55       97436 :   const auto grain_id = _grain_tracker.getEntityValue(
      56       97436 :       _current_elem->id(), FeatureFloodCount::FieldType::UNIQUE_REGION, 0);
      57       97436 :   if (grain_id >= 0)
      58             :   {
      59             :     mooseAssert(grain_id < _grain_volumes.size(), "grain index is out of bounds");
      60       38540 :     const auto volume = _grain_volumes[grain_id];
      61       38540 :     const auto centroid = _grain_tracker.getGrainCentroid(grain_id);
      62             : 
      63       38540 :     const RealGradient velocity_translation = _mt / volume * _grain_forces[grain_id];
      64             :     const RealGradient velocity_rotation =
      65       38540 :         _mr / volume * (_grain_torques[grain_id].cross(_current_elem->vertex_average() - centroid));
      66       38540 :     _velocity_advection = velocity_translation + velocity_rotation;
      67             :   }
      68             :   else
      69             :     _velocity_advection.zero();
      70       97436 : }
      71             : 
      72             : Real
      73      461088 : GrainAdvectionAux::computeValue()
      74             : {
      75      461088 :   return _velocity_advection(_component);
      76             : }

Generated by: LCOV version 1.14