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