www.mooseframework.org
ContactDOFSetSize.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
22 
23 template <>
24 InputParameters
26 {
27  InputParameters params = validParams<GeneralPostprocessor>();
28  params.addRequiredParam<VariableName>("variable", "The name of the variable to test for contact");
29  params.addRequiredParam<SubdomainName>("subdomain", "The subdomain that the variable lives on");
30  params.addParam<Real>(
31  "tolerance", TOLERANCE, "The tolerance for accepting that the variable indicates contact");
32  params.addClassDescription("Outputs the number of dofs greater than a tolerance threshold "
33  "indicating mechanical contact");
34  return params;
35 }
36 
37 ContactDOFSetSize::ContactDOFSetSize(const InputParameters & parameters)
38  : GeneralPostprocessor(parameters),
39  _var(_fe_problem.getVariable(_tid,
40  getParam<VariableName>("variable"),
41  Moose::VarKindType::VAR_NONLINEAR,
42  Moose::VarFieldType::VAR_FIELD_STANDARD)),
43  _mesh(_fe_problem.mesh().getMesh()),
44  _subdomain_id(_fe_problem.mesh().getSubdomainID(getParam<SubdomainName>("subdomain"))),
45  _tolerance(getParam<Real>("tolerance"))
46 {
47 }
48 
49 void
51 {
52  _count = 0;
53 }
54 
55 void
57 {
58  AllLocalDofIndicesThread aldit(_fe_problem.getNonlinearSystemBase().system(), {_var.name()});
59 
60  // Get the element iterators corresponding to the subdomain id
61  auto elem_begin = _mesh.active_local_subdomain_elements_begin(_subdomain_id);
62  auto elem_end = _mesh.active_local_subdomain_elements_end(_subdomain_id);
63 
64  ConstElemRange range(elem_begin, elem_end);
65 
66  Threads::parallel_reduce(range, aldit);
67 
68  auto && solution = _fe_problem.getNonlinearSystemBase().solution();
69 
70  for (auto dof : aldit._all_dof_indices)
71  if (solution(dof) > _tolerance)
72  ++_count;
73 
74  gatherSum(_count);
75  _console << std::endl << "The number of nodes in contact is " << _count << std::endl << std::endl;
76 }
77 
78 PostprocessorValue
80 {
81  return _count;
82 }
validParams< ContactDOFSetSize >
InputParameters validParams< ContactDOFSetSize >()
Definition: ContactDOFSetSize.C:25
ContactDOFSetSize::_tolerance
const Real _tolerance
The tolerance used to decide whether the variable indicates contact.
Definition: ContactDOFSetSize.h:46
ContactDOFSetSize
Definition: ContactDOFSetSize.h:25
ContactDOFSetSize::getValue
PostprocessorValue getValue() override
Definition: ContactDOFSetSize.C:79
ContactDOFSetSize.h
ContactDOFSetSize::execute
void execute() override
Definition: ContactDOFSetSize.C:56
ContactDOFSetSize::initialize
void initialize() override
Definition: ContactDOFSetSize.C:50
ContactDOFSetSize::_mesh
const MeshBase & _mesh
The libmesh mesh.
Definition: ContactDOFSetSize.h:40
ContactDOFSetSize::_var
const MooseVariableFEBase & _var
MOOSE variable we compute the contact set from.
Definition: ContactDOFSetSize.h:37
ContactDOFSetSize::_count
unsigned int _count
Represents the number of values in contact.
Definition: ContactDOFSetSize.h:49
ContactDOFSetSize::_subdomain_id
const SubdomainID _subdomain_id
The subdomain over which to query degrees of freedom.
Definition: ContactDOFSetSize.h:43
registerMooseObject
registerMooseObject("ContactApp", ContactDOFSetSize)
ContactDOFSetSize::ContactDOFSetSize
ContactDOFSetSize(const InputParameters &parameters)
Definition: ContactDOFSetSize.C:37