https://mooseframework.inl.gov
MeshAlignment1D3D.C
Go to the documentation of this file.
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 "MeshAlignment1D3D.h"
11 #include "Assembly.h"
12 #include "KDTree.h"
13 
14 #include "libmesh/elem.h"
15 
17 
18 void
20  const std::vector<dof_id_type> & primary_elem_ids,
21  const std::vector<std::tuple<dof_id_type, unsigned short int>> & secondary_boundary_info)
22 {
23  _primary_elem_ids = primary_elem_ids;
26 
27  extractFromBoundaryInfo(secondary_boundary_info,
33 
34  buildMapping();
35 }
36 
37 void
39 {
40  for (const auto & primary_elem_id : _primary_elem_ids)
41  {
42  const Elem * primary_elem = _mesh.queryElemPtr(primary_elem_id);
43  // The PID check is needed to exclude ghost elements, since those don't
44  // necessarily have a coupled element on this processor:
45  if (primary_elem && primary_elem->processor_id() == _mesh.processor_id())
46  {
47  assembly.setCurrentSubdomainID(primary_elem->subdomain_id());
48  assembly.reinit(primary_elem);
49  std::vector<Point> primary_qps = assembly.qPoints().stdVector();
50  _n_qp_primary = primary_qps.size();
51 
52  const auto & secondary_elem_ids = getCoupledSecondaryElemIDs(primary_elem_id);
53  for (const auto & secondary_elem_id : secondary_elem_ids)
54  {
55  auto it =
56  std::find(_secondary_elem_ids.begin(), _secondary_elem_ids.end(), secondary_elem_id);
57  mooseAssert(it != _secondary_elem_ids.end(), "Secondary element ID not found.");
58  const unsigned int i_secondary = std::distance(_secondary_elem_ids.begin(), it);
59  const unsigned short int secondary_side_id = _secondary_side_ids[i_secondary];
60 
61  const Elem * secondary_elem = _mesh.elemPtr(secondary_elem_id);
62  assembly.setCurrentSubdomainID(secondary_elem->subdomain_id());
63  assembly.reinit(secondary_elem, secondary_side_id);
64  const std::vector<Point> secondary_qps = assembly.qPointsFace().stdVector();
65  _n_qp_secondary = secondary_qps.size();
66 
67  _secondary_elem_id_to_qp_indices[secondary_elem_id].resize(secondary_qps.size());
68  KDTree kd_tree_qp(primary_qps, _mesh.getMaxLeafSize());
69  for (std::size_t i = 0; i < secondary_qps.size(); i++)
70  {
71  unsigned int patch_size = 1;
72  std::vector<std::size_t> return_index(patch_size);
73  kd_tree_qp.neighborSearch(secondary_qps[i], patch_size, return_index);
74  _secondary_elem_id_to_qp_indices[secondary_elem_id][i] = return_index[0];
75  }
76  }
77  }
78  }
79 }
void extractFrom1DElements(const std::vector< dof_id_type > &elem_ids, std::vector< Point > &elem_points, std::vector< dof_id_type > &node_ids, std::vector< Point > &node_points) const
Extracts mesh information from 1D elements.
std::vector< Point > _secondary_elem_points
List of secondary element points.
virtual Elem * elemPtr(const dof_id_type i)
void initialize(const std::vector< dof_id_type > &primary_elem_ids, const std::vector< std::tuple< dof_id_type, unsigned short int >> &secondary_boundary_info)
Extracts mesh information and builds the mapping.
Builds mapping between a 1D/2D boundary and a 3D boundary.
std::map< dof_id_type, std::vector< unsigned int > > _secondary_elem_id_to_qp_indices
Map of secondary element ID to vector of coupled quadrature points.
const MooseMesh & _mesh
Mesh.
MeshBase & mesh
std::vector< dof_id_type > _secondary_elem_ids
List of secondary element IDs.
const MooseArray< Point > & qPoints() const
std::vector< dof_id_type > _secondary_node_ids
List of secondary node IDs.
std::vector< unsigned short int > _secondary_side_ids
List of secondary side IDs (if any)
void reinit(const Elem *elem)
virtual Elem * queryElemPtr(const dof_id_type i)
void buildMapping()
Builds the mapping using the extracted mesh information.
unsigned int getMaxLeafSize() const
unsigned int _n_qp_primary
Number of quadrature points for faces on the primary boundary.
unsigned int _n_qp_secondary
Number of quadrature points for faces on the secondary boundary.
std::vector< Point > stdVector() const
std::vector< dof_id_type > _primary_node_ids
List of primary node IDs.
std::vector< Point > _primary_elem_points
List of primary element points.
std::vector< Point > _primary_node_points
List of primary node points.
void setCurrentSubdomainID(SubdomainID i)
MeshAlignment1D3D(const MooseMesh &mesh)
Constructor.
const MooseArray< Point > & qPointsFace() const
void extractFromBoundaryInfo(const std::vector< std::tuple< dof_id_type, unsigned short int >> &boundary_info, std::vector< dof_id_type > &elem_ids, std::vector< unsigned short int > &side_ids, std::vector< Point > &side_points, std::vector< dof_id_type > &node_ids, std::vector< Point > &node_points) const
Extracts mesh information from boundary info.
void buildCoupledElemQpIndexMap(Assembly &assembly)
Builds the map used for getting the coupled quadrature point index.
std::vector< dof_id_type > _primary_elem_ids
List of primary element IDs.
const std::vector< dof_id_type > & getCoupledSecondaryElemIDs(const dof_id_type &primary_elem_id) const
Gets the coupled secondary element IDs for a given primary element ID.
processor_id_type processor_id() const
std::vector< Point > _secondary_node_points
List of secondary node points.