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 28 : CrackFrontNonlocalMaterialBase::validParams() 15 : { 16 28 : InputParameters params = ElementVectorPostprocessor::validParams(); 17 56 : params.addRequiredParam<UserObjectName>("crack_front_definition", 18 : "The CrackFrontDefinition user object name"); 19 56 : params.addRequiredParam<Real>( 20 : "box_length", "Dimension of property-averaging box in direction of crack extension."); 21 56 : params.addRequiredParam<Real>( 22 : "box_height", "Dimension of property-averaging box in direction normal to crack."); 23 56 : params.addParam<Real>("box_width", 1.0, "Distance tangent to front of crack front."); 24 56 : 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 28 : params.set<bool>("use_displaced_mesh") = false; 29 84 : params.set<ExecFlagEnum>("execute_on") = {EXEC_TIMESTEP_BEGIN}; 30 28 : params.addClassDescription("Computes the average material property at a crack front."); 31 28 : return params; 32 28 : } 33 : 34 14 : CrackFrontNonlocalMaterialBase::CrackFrontNonlocalMaterialBase(const InputParameters & parameters, 35 14 : const std::string & property_name) 36 : : ElementVectorPostprocessor(parameters), 37 14 : _property_name(property_name), 38 28 : _box_length(getParam<Real>("box_length")), 39 28 : _box_width(getParam<Real>("box_width")), 40 28 : _box_height(getParam<Real>("box_height")), 41 56 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), 42 14 : _x(declareVector("x")), 43 14 : _y(declareVector("y")), 44 14 : _z(declareVector("z")), 45 14 : _position(declareVector("id")), 46 : // get the property name instead of materialname 47 28 : _avg_crack_tip_scalar(declareVector("crack_tip_" + _base_name + _property_name)) 48 : { 49 56 : 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 28 : _depend_uo.insert(getParam<UserObjectName>("crack_front_definition")); 53 14 : } 54 : 55 : void 56 14 : CrackFrontNonlocalMaterialBase::initialSetup() 57 : { 58 14 : const auto uo_name = getParam<UserObjectName>("crack_front_definition"); 59 14 : _crack_front_definition = 60 14 : &(getUserObjectByName<CrackFrontDefinition>(uo_name, /*is_dependency = */ false)); 61 14 : } 62 : 63 : void 64 14 : CrackFrontNonlocalMaterialBase::initialize() 65 : { 66 14 : std::size_t num_pts = _crack_front_definition->getNumCrackFrontPoints(); 67 : 68 14 : _volume.assign(num_pts, 0.0); 69 14 : _x.assign(num_pts, 0.0); 70 14 : _y.assign(num_pts, 0.0); 71 14 : _z.assign(num_pts, 0.0); 72 14 : _position.assign(num_pts, 0.0); 73 14 : _avg_crack_tip_scalar.assign(num_pts, 0.0); 74 14 : } 75 : 76 : void 77 2740 : CrackFrontNonlocalMaterialBase::execute() 78 : { 79 : // icfp crack front point index 80 84940 : for (const auto icfp : index_range(_avg_crack_tip_scalar)) 81 : { 82 82200 : Point crack_front_normal = _crack_front_definition->getCrackFrontNormal(icfp); 83 164400 : for (unsigned int qp = 0; qp < _qrule->n_points(); qp++) 84 : { 85 82200 : Real q = BoxWeightingFunction(icfp, _q_point[qp]); 86 82200 : if (q == 0) 87 80550 : continue; 88 : 89 1650 : Real scalar = getQPCrackFrontScalar(qp, crack_front_normal); 90 1650 : _avg_crack_tip_scalar[icfp] += _JxW[qp] * _coord[qp] * scalar * q; 91 1650 : _volume[icfp] += _JxW[qp] * _coord[qp] * q; 92 : } 93 : } 94 2740 : } 95 : 96 : void 97 14 : CrackFrontNonlocalMaterialBase::finalize() 98 : { 99 14 : gatherSum(_avg_crack_tip_scalar); 100 14 : gatherSum(_volume); 101 434 : for (const auto icfp : index_range(_avg_crack_tip_scalar)) 102 : { 103 420 : if (_volume[icfp] != 0) 104 420 : _avg_crack_tip_scalar[icfp] = _avg_crack_tip_scalar[icfp] / _volume[icfp]; 105 : else 106 0 : _avg_crack_tip_scalar[icfp] = 0; 107 : 108 420 : const auto cfp = _crack_front_definition->getCrackFrontPoint(icfp); 109 420 : _x[icfp] = (*cfp)(0); 110 420 : _y[icfp] = (*cfp)(1); 111 420 : _z[icfp] = (*cfp)(2); 112 420 : _position[icfp] = _crack_front_definition->getDistanceAlongFront(icfp); 113 : } 114 14 : } 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 82200 : CrackFrontNonlocalMaterialBase::BoxWeightingFunction(std::size_t crack_front_point_index, 129 : const Point & qp_coord) const 130 : { 131 82200 : 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 82200 : _crack_front_definition->rotateToCrackFrontCoords(crack_node_to_current_node, 140 : crack_front_point_index); 141 22840 : if ((crack_node_to_current_node_rot(0) > 0) && 142 22840 : (crack_node_to_current_node_rot(0) <= _box_length) && 143 93670 : (std::abs(crack_node_to_current_node_rot(1)) <= _box_height / 2) && 144 8400 : (std::abs(crack_node_to_current_node_rot(2)) <= _box_width / 2)) 145 1650 : return 1.0; 146 : 147 : return 0.0; 148 : }