https://mooseframework.inl.gov
MeshAlignment2D3D.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 "MeshAlignment2D3D.h"
11 #include "Assembly.h"
12 #include "KDTree.h"
13 #include "MooseUtils.h"
14 
15 #include "libmesh/elem.h"
16 
18 
19 void
21  const std::vector<std::tuple<dof_id_type, unsigned short int>> & primary_boundary_info,
22  const std::vector<std::tuple<dof_id_type, unsigned short int>> & secondary_boundary_info,
23  const Point & axis_point,
24  const RealVectorValue & axis_direction)
25 {
26  extractFromBoundaryInfo(primary_boundary_info,
32 
33  extractFromBoundaryInfo(secondary_boundary_info,
39 
40  buildMapping();
41  checkAlignment(axis_point, axis_direction);
42 }
43 
44 void
46 {
47  for (const auto i_secondary : index_range(_secondary_elem_ids))
48  {
49  const auto secondary_elem_id = _secondary_elem_ids[i_secondary];
50  const Elem * secondary_elem = _mesh.queryElemPtr(secondary_elem_id);
51  // The PID check is needed to exclude ghost elements, since those don't
52  // necessarily have a coupled element on this processor:
53  if (secondary_elem && secondary_elem->processor_id() == _mesh.processor_id())
54  {
55  const auto secondary_side_id = _secondary_side_ids[i_secondary];
56  assembly.setCurrentSubdomainID(secondary_elem->subdomain_id());
57  assembly.reinit(secondary_elem, secondary_side_id);
58  const auto secondary_qps = assembly.qPointsFace().stdVector();
59  _n_qp_secondary = secondary_qps.size();
60 
61  const auto primary_elem_id = getCoupledPrimaryElemID(secondary_elem_id);
62  auto it = std::find(_primary_elem_ids.begin(), _primary_elem_ids.end(), primary_elem_id);
63  const auto i_primary = std::distance(_primary_elem_ids.begin(), it);
64  const auto primary_side_id = _primary_side_ids[i_primary];
65 
66  // This element should be ghosted, so this should be safe
67  const Elem * primary_elem = _mesh.elemPtr(primary_elem_id);
68  assembly.setCurrentSubdomainID(primary_elem->subdomain_id());
69  assembly.reinit(primary_elem, primary_side_id);
70  auto primary_qps = assembly.qPointsFace().stdVector();
71  _n_qp_primary = primary_qps.size();
72 
73  // compute the area for each quadrature point on the primary side
74  if (_primary_elem_id_to_area.find(primary_elem_id) == _primary_elem_id_to_area.end())
75  {
76  const auto & JxW = assembly.JxWFace();
77  const auto & coord = assembly.coordTransformation();
78  std::vector<Real> area(_n_qp_primary, 0.0);
79  for (unsigned int qp = 0; qp < _n_qp_primary; qp++)
80  area[qp] = JxW[qp] * coord[qp];
81  _primary_elem_id_to_area[primary_elem_id] = area;
82  }
83 
84  _secondary_elem_id_to_qp_indices[secondary_elem_id].resize(secondary_qps.size());
85  KDTree kd_tree_qp(primary_qps, _mesh.getMaxLeafSize());
86  for (const auto i : index_range(secondary_qps))
87  {
88  unsigned int patch_size = 1;
89  std::vector<std::size_t> return_index(patch_size);
90  kd_tree_qp.neighborSearch(secondary_qps[i], patch_size, return_index);
91  _secondary_elem_id_to_qp_indices[secondary_elem_id][i] = return_index[0];
92  }
93  }
94  }
95 }
96 
97 const std::vector<Real> &
98 MeshAlignment2D3D::getPrimaryArea(const dof_id_type primary_elem_id) const
99 {
100  auto it = _primary_elem_id_to_area.find(primary_elem_id);
101  mooseAssert(it != _primary_elem_id_to_area.end(), "The element ID has no area stored.");
102  return it->second;
103 }
std::vector< Point > _secondary_elem_points
List of secondary element points.
void initialize(const std::vector< std::tuple< dof_id_type, unsigned short int >> &primary_boundary_info, const std::vector< std::tuple< dof_id_type, unsigned short int >> &secondary_boundary_info, const Point &axis_point, const RealVectorValue &axis_direction)
Extracts mesh information and builds the mapping.
virtual Elem * elemPtr(const dof_id_type i)
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.
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.
const MooseArray< Real > & coordTransformation() const
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::map< dof_id_type, std::vector< Real > > _primary_elem_id_to_area
Map of primary element ID to area for each quadrature point.
void buildCoupledElemQpIndexMapSecondary(Assembly &assembly)
Builds the map used for getting the coupled quadrature point index.
const MooseArray< Real > & JxWFace() const
std::vector< Point > _primary_node_points
List of primary node points.
void setCurrentSubdomainID(SubdomainID i)
const std::vector< Real > & getPrimaryArea(const dof_id_type primary_elem_id) const
Gets the area for each quadrature point on a primary element.
const MooseArray< Point > & qPointsFace() const
dof_id_type getCoupledPrimaryElemID(const dof_id_type &secondary_elem_id) const
Gets the coupled primary element ID for a given secondary element ID.
std::vector< unsigned short int > _primary_side_ids
List of primary side IDs (if any)
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.
std::vector< dof_id_type > _primary_elem_ids
List of primary element IDs.
processor_id_type processor_id() const
void checkAlignment(const Point &axis_point, const RealVectorValue &axis_direction)
Checks the alignment and sets _mesh_alignment accordingly.
auto index_range(const T &sizable)
uint8_t dof_id_type
std::vector< Point > _secondary_node_points
List of secondary node points.
MeshAlignment2D3D(const MooseMesh &mesh)
Constructor.