LCOV - code coverage report
Current view: top level - src/auxkernels - FeatureFloodCountAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 31 38 81.6 %
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 "FeatureFloodCountAux.h"
      11             : #include "FeatureFloodCount.h"
      12             : #include "GrainTrackerInterface.h"
      13             : #include "MooseEnum.h"
      14             : 
      15             : #include <algorithm>
      16             : 
      17             : registerMooseObject("PhaseFieldApp", FeatureFloodCountAux);
      18             : 
      19             : InputParameters
      20       10363 : FeatureFloodCountAux::validParams()
      21             : {
      22       10363 :   InputParameters params = AuxKernel::validParams();
      23       10363 :   params.addClassDescription("Feature detection by connectivity analysis");
      24       20726 :   params.addDeprecatedParam<UserObjectName>("bubble_object",
      25             :                                             "The FeatureFloodCount UserObject to get values from.",
      26             :                                             "Use \"flood_counter\" instead.");
      27       20726 :   params.addRequiredParam<UserObjectName>("flood_counter",
      28             :                                           "The FeatureFloodCount UserObject to get values from.");
      29       20726 :   params.addParam<unsigned int>("map_index",
      30             :                                 "The index of which map to retrieve values from when "
      31             :                                 "using FeatureFloodCount with multiple maps.");
      32             :   MooseEnum field_display("UNIQUE_REGION VARIABLE_COLORING GHOSTED_ENTITIES HALOS CENTROID "
      33             :                           "ACTIVE_BOUNDS INTERSECTS_SPECIFIED_BOUNDARY",
      34       20726 :                           "UNIQUE_REGION");
      35       20726 :   params.addParam<MooseEnum>("field_display",
      36             :                              field_display,
      37             :                              "Determines how the auxilary field should be colored. "
      38             :                              "(UNIQUE_REGION and VARIABLE_COLORING are nodal, CENTROID is "
      39             :                              "elemental, default: UNIQUE_REGION)");
      40             : 
      41       41452 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
      42             : 
      43       10363 :   return params;
      44       20726 : }
      45             : 
      46        5492 : FeatureFloodCountAux::FeatureFloodCountAux(const InputParameters & parameters)
      47             :   : AuxKernel(parameters),
      48        5492 :     _flood_counter(getUserObject<FeatureFloodCount>("flood_counter")),
      49       16852 :     _var_idx(isParamValid("map_index") ? getParam<unsigned int>("map_index")
      50             :                                        : std::numeric_limits<std::size_t>::max()),
      51       10984 :     _field_type(getParam<MooseEnum>("field_display").getEnum<FieldType>()),
      52        5492 :     _var_coloring(_field_type == FeatureFloodCount::FieldType::VARIABLE_COLORING)
      53             : {
      54        5492 :   if (_flood_counter.isElemental() == isNodal() &&
      55             :       (_field_type == FieldType::UNIQUE_REGION || _field_type == FieldType::VARIABLE_COLORING ||
      56           5 :        _field_type == FieldType::GHOSTED_ENTITIES || _field_type == FieldType::HALOS))
      57           3 :     paramError("field_display",
      58             :                "UNIQUE_REGION, VARIABLE_COLORING, GHOSTED_ENTITIES and HALOS must be on variable "
      59             :                "types that match the entity mode of the FeatureFloodCounter");
      60             : 
      61        5489 :   if (isNodal() && (_field_type == FieldType::ACTIVE_BOUNDS || _field_type == FieldType::CENTROID ||
      62             :                     _field_type == FieldType::INTERSECTS_SPECIFIED_BOUNDARY))
      63           2 :     paramError("field_display",
      64             :                "The selected option is only available for elemental aux variables");
      65        5487 : }
      66             : 
      67             : void
      68     5850434 : FeatureFloodCountAux::precalculateValue()
      69             : {
      70     5850434 :   switch (_field_type)
      71             :   {
      72     5850434 :     case FieldType::UNIQUE_REGION:
      73             :     case FieldType::VARIABLE_COLORING:
      74             :     case FieldType::GHOSTED_ENTITIES:
      75             :     case FieldType::HALOS:
      76             :     case FieldType::CENTROID:
      77             :     case FieldType::INTERSECTS_SPECIFIED_BOUNDARY:
      78     5850434 :       _value = _flood_counter.getEntityValue(
      79     5850434 :           (isNodal() ? _current_node->id() : _current_elem->id()), _field_type, _var_idx);
      80     5850434 :       break;
      81             : 
      82           0 :     case FieldType::ACTIVE_BOUNDS:
      83             :     {
      84           0 :       const auto & var_to_features = _flood_counter.getVarToFeatureVector(_current_elem->id());
      85           0 :       _value = std::count_if(var_to_features.begin(),
      86             :                              var_to_features.end(),
      87             :                              [](unsigned int feature_id)
      88           0 :                              { return feature_id != FeatureFloodCount::invalid_id; });
      89             : 
      90           0 :       break;
      91             :     }
      92             : 
      93           0 :     default:
      94           0 :       paramError("field_display", "Unimplemented type");
      95             :   }
      96     5850434 : }
      97             : 
      98             : Real
      99    21238925 : FeatureFloodCountAux::computeValue()
     100             : {
     101    21238925 :   return _value;
     102             : }

Generated by: LCOV version 1.14