LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - CrackFrontNonlocalMaterialBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 72 79 91.1 %
Date: 2025-07-25 05:00:39 Functions: 7 8 87.5 %
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 "CrackFrontNonlocalMaterialBase.h"
      11             : #include "CrackFrontDefinition.h"
      12             : 
      13             : InputParameters
      14          24 : CrackFrontNonlocalMaterialBase::validParams()
      15             : {
      16          24 :   InputParameters params = ElementVectorPostprocessor::validParams();
      17          48 :   params.addRequiredParam<UserObjectName>("crack_front_definition",
      18             :                                           "The CrackFrontDefinition user object name");
      19          48 :   params.addRequiredParam<Real>(
      20             :       "box_length", "Dimension of property-averaging box in direction of crack extension.");
      21          48 :   params.addRequiredParam<Real>(
      22             :       "box_height", "Dimension of property-averaging box in direction normal to crack.");
      23          48 :   params.addParam<Real>("box_width", 1.0, "Distance tangent to front of crack front.");
      24          48 :   params.addParam<std::string>("base_name",
      25             :                                "Optional parameter that allows the user to define "
      26             :                                "multiple mechanics material systems on the same "
      27             :                                "block, i.e. for multiple phases");
      28          24 :   params.set<bool>("use_displaced_mesh") = false;
      29          72 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_BEGIN};
      30          24 :   params.addClassDescription("Computes the average material property at a crack front.");
      31          24 :   return params;
      32          24 : }
      33             : 
      34          12 : CrackFrontNonlocalMaterialBase::CrackFrontNonlocalMaterialBase(const InputParameters & parameters,
      35          12 :                                                                const std::string & property_name)
      36             :   : ElementVectorPostprocessor(parameters),
      37          12 :     _property_name(property_name),
      38          24 :     _box_length(getParam<Real>("box_length")),
      39          24 :     _box_width(getParam<Real>("box_width")),
      40          24 :     _box_height(getParam<Real>("box_height")),
      41          48 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      42          12 :     _x(declareVector("x")),
      43          12 :     _y(declareVector("y")),
      44          12 :     _z(declareVector("z")),
      45          12 :     _position(declareVector("id")),
      46             :     // get the property name instead of materialname
      47          24 :     _avg_crack_tip_scalar(declareVector("crack_tip_" + _base_name + _property_name))
      48             : {
      49          48 :   if (_mesh.dimension() == 3 && !isParamSetByUser("box_width"))
      50           0 :     paramError("box_width", "Must define box_width in 3D problems.");
      51             :   // add user object dependencies by name (the UOs do not need to exist yet for this)
      52          24 :   _depend_uo.insert(getParam<UserObjectName>("crack_front_definition"));
      53          12 : }
      54             : 
      55             : void
      56          12 : CrackFrontNonlocalMaterialBase::initialSetup()
      57             : {
      58          12 :   const auto uo_name = getParam<UserObjectName>("crack_front_definition");
      59          12 :   _crack_front_definition =
      60          12 :       &(getUserObjectByName<CrackFrontDefinition>(uo_name, /*is_dependency = */ false));
      61          12 : }
      62             : 
      63             : void
      64          12 : CrackFrontNonlocalMaterialBase::initialize()
      65             : {
      66          12 :   std::size_t num_pts = _crack_front_definition->getNumCrackFrontPoints();
      67             : 
      68          12 :   _volume.assign(num_pts, 0.0);
      69          12 :   _x.assign(num_pts, 0.0);
      70          12 :   _y.assign(num_pts, 0.0);
      71          12 :   _z.assign(num_pts, 0.0);
      72          12 :   _position.assign(num_pts, 0.0);
      73          12 :   _avg_crack_tip_scalar.assign(num_pts, 0.0);
      74          12 : }
      75             : 
      76             : void
      77        2192 : CrackFrontNonlocalMaterialBase::execute()
      78             : {
      79             :   // icfp crack front point index
      80       67952 :   for (const auto icfp : index_range(_avg_crack_tip_scalar))
      81             :   {
      82       65760 :     Point crack_front_normal = _crack_front_definition->getCrackFrontNormal(icfp);
      83      131520 :     for (unsigned int qp = 0; qp < _qrule->n_points(); qp++)
      84             :     {
      85       65760 :       Real q = BoxWeightingFunction(icfp, _q_point[qp]);
      86       65760 :       if (q == 0)
      87       64440 :         continue;
      88             : 
      89        1320 :       Real scalar = getQPCrackFrontScalar(qp, crack_front_normal);
      90        1320 :       _avg_crack_tip_scalar[icfp] += _JxW[qp] * _coord[qp] * scalar * q;
      91        1320 :       _volume[icfp] += _JxW[qp] * _coord[qp] * q;
      92             :     }
      93             :   }
      94        2192 : }
      95             : 
      96             : void
      97          12 : CrackFrontNonlocalMaterialBase::finalize()
      98             : {
      99          12 :   gatherSum(_avg_crack_tip_scalar);
     100          12 :   gatherSum(_volume);
     101         372 :   for (const auto icfp : index_range(_avg_crack_tip_scalar))
     102             :   {
     103         360 :     if (_volume[icfp] != 0)
     104         360 :       _avg_crack_tip_scalar[icfp] = _avg_crack_tip_scalar[icfp] / _volume[icfp];
     105             :     else
     106           0 :       _avg_crack_tip_scalar[icfp] = 0;
     107             : 
     108         360 :     const auto cfp = _crack_front_definition->getCrackFrontPoint(icfp);
     109         360 :     _x[icfp] = (*cfp)(0);
     110         360 :     _y[icfp] = (*cfp)(1);
     111         360 :     _z[icfp] = (*cfp)(2);
     112         360 :     _position[icfp] = _crack_front_definition->getDistanceAlongFront(icfp);
     113             :   }
     114          12 : }
     115             : 
     116             : void
     117           0 : CrackFrontNonlocalMaterialBase::threadJoin(const UserObject & y)
     118             : {
     119             :   const auto & uo = static_cast<const CrackFrontNonlocalMaterialBase &>(y);
     120           0 :   for (const auto i : index_range(_avg_crack_tip_scalar))
     121             :   {
     122           0 :     _volume[i] += uo._volume[i];
     123           0 :     _avg_crack_tip_scalar[i] += uo._avg_crack_tip_scalar[i];
     124             :   }
     125           0 : }
     126             : 
     127             : Real
     128       65760 : CrackFrontNonlocalMaterialBase::BoxWeightingFunction(std::size_t crack_front_point_index,
     129             :                                                      const Point & qp_coord) const
     130             : {
     131       65760 :   const Point * cf_pt = _crack_front_definition->getCrackFrontPoint(crack_front_point_index);
     132             :   RealVectorValue crack_node_to_current_node = qp_coord - *cf_pt;
     133             : 
     134             :   // crackfront coordinates are:
     135             :   // crack_node_to_current_node_rot[0]= crack direction
     136             :   // crack_node_to_current_node_rot[1]= normal to crack face
     137             :   // crack_node_to_current_node_rot[2]= tangent to crack face along crack front (not used in 2D)
     138             :   RealVectorValue crack_node_to_current_node_rot =
     139       65760 :       _crack_front_definition->rotateToCrackFrontCoords(crack_node_to_current_node,
     140             :                                                         crack_front_point_index);
     141       18272 :   if ((crack_node_to_current_node_rot(0) > 0) &&
     142       18272 :       (crack_node_to_current_node_rot(0) <= _box_length) &&
     143       74936 :       (std::abs(crack_node_to_current_node_rot(1)) <= _box_height / 2) &&
     144        6720 :       (std::abs(crack_node_to_current_node_rot(2)) <= _box_width / 2))
     145        1320 :     return 1.0;
     146             : 
     147             :   return 0.0;
     148             : }

Generated by: LCOV version 1.14