www.mooseframework.org
PenetrationLocator.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "PenetrationLocator.h"
16 
17 #include "ArbitraryQuadrature.h"
18 #include "Conversion.h"
19 #include "GeometricSearchData.h"
20 #include "LineSegment.h"
21 #include "MooseMesh.h"
22 #include "NearestNodeLocator.h"
23 #include "PenetrationThread.h"
24 #include "SubProblem.h"
25 
27  GeometricSearchData & /*geom_search_data*/,
28  MooseMesh & mesh,
29  const unsigned int master_id,
30  const unsigned int slave_id,
31  Order order,
32  NearestNodeLocator & nearest_node)
33  : Restartable(Moose::stringify(master_id) + "to" + Moose::stringify(slave_id),
34  "PenetrationLocator",
35  subproblem,
36  0),
37  _subproblem(subproblem),
38  _mesh(mesh),
39  _master_boundary(master_id),
40  _slave_boundary(slave_id),
41  _fe_type(order),
42  _nearest_node(nearest_node),
43  _penetration_info(declareRestartableDataWithContext<std::map<dof_id_type, PenetrationInfo *>>(
44  "penetration_info", &_mesh)),
45  _has_penetrated(declareRestartableData<std::set<dof_id_type>>("has_penetrated")),
46  _check_whether_reasonable(true),
47  _update_location(declareRestartableData<bool>("update_location", true)),
48  _tangential_tolerance(0.0),
49  _do_normal_smoothing(false),
50  _normal_smoothing_distance(0.0),
51  _normal_smoothing_method(NSM_EDGE_BASED)
52 {
53  // Preconstruct an FE object for each thread we're going to use and for each lower-dimensional
54  // element
55  // This is a time savings so that the thread objects don't do this themselves multiple times
56  _fe.resize(libMesh::n_threads());
57  for (unsigned int i = 0; i < libMesh::n_threads(); i++)
58  {
59  unsigned int n_dims = _mesh.dimension();
60  _fe[i].resize(n_dims + 1);
61  for (unsigned int dim = 0; dim <= n_dims; ++dim)
62  _fe[i][dim] = FEBase::build(dim, _fe_type).release();
63  }
64 
66  {
67  if (!((_subproblem.hasVariable("nodal_normal_x")) &&
68  (_subproblem.hasVariable("nodal_normal_y")) &&
69  (_subproblem.hasVariable("nodal_normal_z"))))
70  {
71  mooseError("To use nodal-normal-based smoothing, the nodal_normal_x, nodal_normal_y, and "
72  "nodal_normal_z variables must exist. Are you missing the [NodalNormals] block?");
73  }
74  }
75 }
76 
78 {
79  for (unsigned int i = 0; i < libMesh::n_threads(); i++)
80  for (unsigned int dim = 0; dim < _fe[i].size(); dim++)
81  delete _fe[i][dim];
82 
83  for (auto & it : _penetration_info)
84  delete it.second;
85 }
86 
87 void
89 {
90  Moose::perf_log.push("detectPenetration()", "Execution");
91 
92  // Data structures to hold the element boundary information
93  std::vector<dof_id_type> elem_list;
94  std::vector<unsigned short int> side_list;
95  std::vector<boundary_id_type> id_list;
96 
97  // Retrieve the Element Boundary data structures from the mesh
98  _mesh.buildSideList(elem_list, side_list, id_list);
99 
100  // Grab the slave nodes we need to worry about from the NearestNodeLocator
101  NodeIdRange & slave_node_range = _nearest_node.slaveNodeRange();
102 
104  _mesh,
114  _fe,
115  _fe_type,
118  elem_list,
119  side_list,
120  id_list);
121 
122  Threads::parallel_reduce(slave_node_range, pt);
123 
124  Moose::perf_log.pop("detectPenetration()", "Execution");
125 }
126 
127 void
129 {
130  // Delete the PenetrationInfo objects we own before clearing the
131  // map, or we have a memory leak.
132  for (auto & it : _penetration_info)
133  delete it.second;
134 
135  _penetration_info.clear();
136 
137  _has_penetrated.clear();
138 
140 }
141 
142 Real
144 {
145  PenetrationInfo * info = _penetration_info[node_id];
146 
147  if (info)
148  return info->_distance;
149  else
150  return 0;
151 }
152 
155 {
156  std::map<dof_id_type, PenetrationInfo *>::const_iterator found_it =
157  _penetration_info.find(node_id);
158 
159  if (found_it != _penetration_info.end())
160  return found_it->second->_normal;
161  else
162  return RealVectorValue(0, 0, 0);
163 }
164 
165 void
167 {
169 }
170 
171 void
173 {
174  _update_location = update;
175 }
176 
177 void
179 {
180  _tangential_tolerance = tangential_tolerance;
181 }
182 
183 void
184 PenetrationLocator::setNormalSmoothingDistance(Real normal_smoothing_distance)
185 {
186  _normal_smoothing_distance = normal_smoothing_distance;
187  if (_normal_smoothing_distance > 0.0)
188  _do_normal_smoothing = true;
189 }
190 
191 void
193 {
194  if (nsmString == "edge_based")
196  else if (nsmString == "nodal_normal_based")
198  else
199  mooseError("Invalid normal_smoothing_method: ", nsmString);
200  _do_normal_smoothing = true;
201 }
virtual bool hasVariable(const std::string &var_name)=0
A class for creating restricted objects.
Definition: Restartable.h:31
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimsension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh m...
Definition: MooseMesh.C:1945
RealVectorValue penetrationNormal(dof_id_type node_id)
void setNormalSmoothingDistance(Real normal_smoothing_distance)
Data structure used to hold penetration information.
StoredRange< std::vector< dof_id_type >::iterator, dof_id_type > NodeIdRange
Definition: MooseTypes.h:81
Finds the nearest node to each node in boundary1 to each node in boundary2 and the other way around...
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
PenetrationLocator(SubProblem &subproblem, GeometricSearchData &geom_search_data, MooseMesh &mesh, const unsigned int master_id, const unsigned int slave_id, Order order, NearestNodeLocator &nearest_node)
std::vector< std::vector< FEBase * > > _fe
std::map< dof_id_type, PenetrationInfo * > & _penetration_info
Data structure of nodes and their associated penetration information.
void setTangentialTolerance(Real tangential_tolerance)
void buildSideList(std::vector< dof_id_type > &el, std::vector< unsigned short int > &sl, std::vector< boundary_id_type > &il)
Calls BoundaryInfo::build_side_list().
Definition: MooseMesh.C:1986
bool _check_whether_reasonable
Check whether found candidates are reasonable.
NodeIdRange & slaveNodeRange()
Returns the NodeIdRange of slave nodes to be used for calling threaded functions operating on the sla...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
PerfLog perf_log
Perflog to be used by applications.
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:66
SubProblem & _subproblem
void setUpdate(bool update)
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
Real penetrationDistance(dof_id_type node_id)
Definition: Moose.h:84
void setNormalSmoothingMethod(std::string nsmString)
void reinit()
Completely redo the search from scratch.
std::set< dof_id_type > & _has_penetrated
void setCheckWhetherReasonable(bool state)
NORMAL_SMOOTHING_METHOD _normal_smoothing_method
NearestNodeLocator & _nearest_node
const std::map< dof_id_type, std::vector< dof_id_type > > & nodeToElemMap()
If not already created, creates a map from every node to all elements to which they are connected...
Definition: MooseMesh.C:642