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

Generated by: LCOV version 1.14