LCOV - code coverage report
Current view: top level - src/userobjects - MeshCut2DFunctionUserObject.C (source / functions) Hit Total Coverage
Test: idaholab/moose xfem: #31405 (292dce) with base fef103 Lines: 35 36 97.2 %
Date: 2025-09-04 07:58:55 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 "MeshCut2DFunctionUserObject.h"
      11             : #include "CrackFrontDefinition.h"
      12             : 
      13             : #include "libmesh/string_to_enum.h"
      14             : #include "MooseMesh.h"
      15             : #include "MooseEnum.h"
      16             : #include "libmesh/edge_edge2.h"
      17             : #include "libmesh/serial_mesh.h"
      18             : #include "libmesh/mesh_tools.h"
      19             : #include "Function.h"
      20             : 
      21             : registerMooseObject("XFEMApp", MeshCut2DFunctionUserObject);
      22             : 
      23             : InputParameters
      24           8 : MeshCut2DFunctionUserObject::validParams()
      25             : {
      26           8 :   InputParameters params = MeshCut2DUserObjectBase::validParams();
      27           8 :   params.addClassDescription("Creates a UserObject for a mesh cutter in 2D problems where crack "
      28             :                              "growth is specified by functions.");
      29          16 :   params.addRequiredParam<FunctionName>("growth_direction_x",
      30             :                                         "Function defining x-component of crack growth direction.");
      31          16 :   params.addRequiredParam<FunctionName>("growth_direction_y",
      32             :                                         "Function defining y-component of crack growth direction.");
      33          16 :   params.addRequiredParam<FunctionName>("growth_rate", "Function defining crack growth rate.");
      34           8 :   return params;
      35           0 : }
      36             : 
      37           4 : MeshCut2DFunctionUserObject::MeshCut2DFunctionUserObject(const InputParameters & parameters)
      38             :   : MeshCut2DUserObjectBase(parameters),
      39           4 :     _func_x(&getFunction("growth_direction_x")),
      40           4 :     _func_y(&getFunction("growth_direction_y")),
      41           4 :     _growth_function(&getFunction("growth_rate")),
      42           4 :     _time_of_previous_call_to_UO(std::numeric_limits<Real>::lowest())
      43             : {
      44           4 : }
      45             : 
      46             : void
      47          36 : MeshCut2DFunctionUserObject::initialize()
      48             : {
      49             :   // Only call crack growth function if time changed.
      50          36 :   if (_t > _time_of_previous_call_to_UO)
      51             :   {
      52          20 :     addNucleatedCracksToMesh();
      53          20 :     findActiveBoundaryGrowth();
      54          20 :     growFront();
      55             :   }
      56          36 :   _time_of_previous_call_to_UO = _t;
      57             : 
      58             :   // always trigger crack_front_definition to be updated
      59          36 :   _is_mesh_modified = true;
      60          36 :   _crack_front_definition->isCutterModified(_is_mesh_modified);
      61          36 : }
      62             : 
      63             : void
      64          20 : MeshCut2DFunctionUserObject::findActiveBoundaryGrowth()
      65             : {
      66          20 :   _active_front_node_growth_vectors.clear();
      67             :   Point zero; // Used for checking whether direction is zero
      68          60 :   for (unsigned int i = 0; i < _original_and_current_front_node_ids.size(); ++i)
      69             :   {
      70             :     // compute growth direction
      71             :     Point dir;
      72          40 :     Node * this_node = _cutter_mesh->node_ptr(_original_and_current_front_node_ids[i].second);
      73             :     mooseAssert(this_node, "Node is NULL");
      74          40 :     Point & this_point = *this_node;
      75          40 :     dir(0) = _func_x->value(_t, this_point);
      76          40 :     dir(1) = _func_y->value(_t, this_point);
      77          40 :     dir = dir / dir.norm();
      78             : 
      79             :     // compute growth amount/velocity
      80             :     Point nodal_offset;
      81          40 :     Real velo = _growth_function->value(_t, Point(0, 0, 0));
      82          40 :     nodal_offset = dir * velo * _dt;
      83             :     // only increment the crack if the growth is positive
      84          40 :     if (!nodal_offset.absolute_fuzzy_equals(zero))
      85             :       _active_front_node_growth_vectors.push_back(
      86          32 :           std::make_pair(_original_and_current_front_node_ids[i].second, nodal_offset));
      87             :   }
      88          20 : }

Generated by: LCOV version 1.14