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 "ContactDOFSetSize.h" 11 : 12 : // MOOSE includes 13 : #include "MooseVariable.h" 14 : #include "FEProblemBase.h" 15 : #include "NonlinearSystemBase.h" 16 : #include "MooseMesh.h" 17 : #include "AllLocalDofIndicesThread.h" 18 : 19 : #include "libmesh/mesh_base.h" 20 : 21 : registerMooseObject("ContactApp", ContactDOFSetSize); 22 : 23 : InputParameters 24 1116 : ContactDOFSetSize::validParams() 25 : { 26 1116 : InputParameters params = GeneralPostprocessor::validParams(); 27 2232 : params.addRequiredParam<VariableName>("variable", "The name of the variable to test for contact"); 28 2232 : params.addRequiredParam<SubdomainName>("subdomain", "The subdomain that the variable lives on"); 29 2232 : params.addParam<Real>( 30 : "tolerance", TOLERANCE, "The tolerance for accepting that the variable indicates contact"); 31 1116 : params.addClassDescription("Outputs the number of dofs greater than a tolerance threshold " 32 : "indicating mechanical contact"); 33 1116 : return params; 34 0 : } 35 : 36 558 : ContactDOFSetSize::ContactDOFSetSize(const InputParameters & parameters) 37 : : GeneralPostprocessor(parameters), 38 558 : _var(_fe_problem.getVariable(_tid, 39 1116 : getParam<VariableName>("variable"), 40 : Moose::VarKindType::VAR_SOLVER, 41 : Moose::VarFieldType::VAR_FIELD_STANDARD)), 42 558 : _mesh(_fe_problem.mesh().getMesh()), 43 1116 : _subdomain_id(_fe_problem.mesh().getSubdomainID(getParam<SubdomainName>("subdomain"))), 44 1674 : _tolerance(getParam<Real>("tolerance")) 45 : { 46 558 : } 47 : 48 : void 49 14663 : ContactDOFSetSize::initialize() 50 : { 51 14663 : _count = 0; 52 14663 : } 53 : 54 : void 55 14663 : ContactDOFSetSize::execute() 56 : { 57 29326 : AllLocalDofIndicesThread aldit(_fe_problem, {_var.name()}); 58 : 59 : // Get the element iterators corresponding to the subdomain id 60 14663 : auto elem_begin = _mesh.active_local_subdomain_elements_begin(_subdomain_id); 61 14663 : auto elem_end = _mesh.active_local_subdomain_elements_end(_subdomain_id); 62 : 63 14663 : ConstElemRange range(elem_begin, elem_end); 64 : 65 14663 : Threads::parallel_reduce(range, aldit); 66 : 67 14663 : const auto & solution = _fe_problem.getNonlinearSystemBase(_sys.number()).solution(); 68 : 69 98356 : for (auto dof : aldit.getDofIndices()) 70 83693 : if (solution(dof) > _tolerance) 71 40107 : ++_count; 72 : 73 14663 : gatherSum(_count); 74 14663 : _console << std::endl << "The number of nodes in contact is " << _count << std::endl << std::endl; 75 29326 : } 76 : 77 : PostprocessorValue 78 14663 : ContactDOFSetSize::getValue() const 79 : { 80 14663 : return _count; 81 : }