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 1012 : ContactDOFSetSize::validParams() 25 : { 26 1012 : InputParameters params = GeneralPostprocessor::validParams(); 27 2024 : params.addRequiredParam<VariableName>("variable", "The name of the variable to test for contact"); 28 2024 : params.addRequiredParam<SubdomainName>("subdomain", "The subdomain that the variable lives on"); 29 2024 : params.addParam<Real>( 30 : "tolerance", TOLERANCE, "The tolerance for accepting that the variable indicates contact"); 31 1012 : params.addClassDescription("Outputs the number of dofs greater than a tolerance threshold " 32 : "indicating mechanical contact"); 33 1012 : return params; 34 0 : } 35 : 36 506 : ContactDOFSetSize::ContactDOFSetSize(const InputParameters & parameters) 37 : : GeneralPostprocessor(parameters), 38 506 : _var(_fe_problem.getVariable(_tid, 39 1012 : getParam<VariableName>("variable"), 40 : Moose::VarKindType::VAR_SOLVER, 41 : Moose::VarFieldType::VAR_FIELD_STANDARD)), 42 506 : _mesh(_fe_problem.mesh().getMesh()), 43 1012 : _subdomain_id(_fe_problem.mesh().getSubdomainID(getParam<SubdomainName>("subdomain"))), 44 1518 : _tolerance(getParam<Real>("tolerance")) 45 : { 46 506 : } 47 : 48 : void 49 12943 : ContactDOFSetSize::initialize() 50 : { 51 12943 : _count = 0; 52 12943 : } 53 : 54 : void 55 12943 : ContactDOFSetSize::execute() 56 : { 57 25886 : AllLocalDofIndicesThread aldit(_fe_problem, {_var.name()}); 58 : 59 : // Get the element iterators corresponding to the subdomain id 60 12943 : auto elem_begin = _mesh.active_local_subdomain_elements_begin(_subdomain_id); 61 12943 : auto elem_end = _mesh.active_local_subdomain_elements_end(_subdomain_id); 62 : 63 12943 : ConstElemRange range(elem_begin, elem_end); 64 : 65 12943 : Threads::parallel_reduce(range, aldit); 66 : 67 12943 : const auto & solution = _fe_problem.getNonlinearSystemBase(_sys.number()).solution(); 68 : 69 82315 : for (auto dof : aldit.getDofIndices()) 70 69372 : if (solution(dof) > _tolerance) 71 32677 : ++_count; 72 : 73 12943 : gatherSum(_count); 74 12943 : _console << std::endl << "The number of nodes in contact is " << _count << std::endl << std::endl; 75 25886 : } 76 : 77 : PostprocessorValue 78 12943 : ContactDOFSetSize::getValue() const 79 : { 80 12943 : return _count; 81 : }