LCOV - code coverage report
Current view: top level - src/postprocessors - CrackFrontData.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 35 39 89.7 %
Date: 2025-07-25 05:00:39 Functions: 6 6 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 "CrackFrontData.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseMesh.h"
      14             : #include "MooseVariable.h"
      15             : #include "SubProblem.h"
      16             : 
      17             : #include "libmesh/boundary_info.h"
      18             : 
      19             : registerMooseObject("SolidMechanicsApp", CrackFrontData);
      20             : 
      21             : InputParameters
      22         180 : CrackFrontData::validParams()
      23             : {
      24         180 :   InputParameters params = GeneralPostprocessor::validParams();
      25         180 :   params.addClassDescription("Determines which nodes are along the crack front");
      26         360 :   params.addRequiredParam<VariableName>(
      27             :       "variable", "The name of a variable whose value at the crack front is to be reported");
      28         360 :   params.addRequiredParam<UserObjectName>("crack_front_definition",
      29             :                                           "The CrackFrontDefinition user object name");
      30         360 :   params.addParam<unsigned int>(
      31             :       "crack_front_point_index",
      32             :       "The index of the point on the crack front where data is to be reported");
      33         360 :   params.addParam<Real>("scale_factor", 1, "A scale factor to be applied to the reported quantity");
      34         180 :   return params;
      35           0 : }
      36             : 
      37         120 : CrackFrontData::CrackFrontData(const InputParameters & parameters)
      38             :   : GeneralPostprocessor(parameters),
      39         120 :     _crack_front_definition(&getUserObject<CrackFrontDefinition>("crack_front_definition")),
      40         120 :     _crack_front_point_index(isParamValid("crack_front_point_index")
      41         360 :                                  ? getParam<unsigned int>("crack_front_point_index")
      42             :                                  : 0),
      43         120 :     _crack_front_node(NULL),
      44         120 :     _mesh(_subproblem.mesh()),
      45         120 :     _var_name(parameters.get<VariableName>("variable")),
      46         240 :     _scale_factor(getParam<Real>("scale_factor")),
      47         120 :     _field_var(_subproblem.getStandardVariable(_tid, _var_name)),
      48         120 :     _value(0)
      49             : {
      50         120 :   if (!_field_var.isNodal())
      51           0 :     mooseError("CrackFrontData can be output only for nodal variables, variable '",
      52             :                _var_name,
      53             :                "' is not nodal");
      54         120 : }
      55             : 
      56             : void
      57         120 : CrackFrontData::initialize()
      58             : {
      59         120 :   if (!(_crack_front_point_index < _crack_front_definition->getNumCrackFrontPoints()))
      60           0 :     mooseError("crack_front_point_index out of range in CrackFrontData");
      61         120 :   if (!_crack_front_definition->hasCrackFrontNodes())
      62           0 :     mooseError("CrackFrontData not currently supported if crack front is defined with points "
      63             :                "rather than nodes");
      64             : 
      65         120 :   _crack_front_node = _crack_front_definition->getCrackFrontNodePtr(_crack_front_point_index);
      66         120 : }
      67             : void
      68         120 : CrackFrontData::execute()
      69             : {
      70         120 :   _value = 0;
      71             : 
      72         120 :   if (_crack_front_node->processor_id() == processor_id())
      73          80 :     _value = _field_var.getNodalValue(*_crack_front_node);
      74         120 : }
      75             : 
      76             : Real
      77         120 : CrackFrontData::getValue() const
      78             : {
      79             : 
      80         120 :   return _scale_factor * _value;
      81             : }
      82             : 
      83             : void
      84         120 : CrackFrontData::finalize()
      85             : {
      86         120 :   gatherSum(_value);
      87         120 : }

Generated by: LCOV version 1.14