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 "MeshAlignment1D3D.h" 11 : #include "Assembly.h" 12 : #include "KDTree.h" 13 : 14 : #include "libmesh/elem.h" 15 : 16 51 : MeshAlignment1D3D::MeshAlignment1D3D(const MooseMesh & mesh) : MeshAlignmentOneToMany(mesh) {} 17 : 18 : void 19 47 : MeshAlignment1D3D::initialize( 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 47 : _primary_elem_ids = primary_elem_ids; 24 47 : extractFrom1DElements( 25 47 : _primary_elem_ids, _primary_elem_points, _primary_node_ids, _primary_node_points); 26 : 27 47 : extractFromBoundaryInfo(secondary_boundary_info, 28 47 : _secondary_elem_ids, 29 47 : _secondary_side_ids, 30 47 : _secondary_elem_points, 31 47 : _secondary_node_ids, 32 47 : _secondary_node_points); 33 : 34 47 : buildMapping(); 35 47 : } 36 : 37 : void 38 50 : MeshAlignment1D3D::buildCoupledElemQpIndexMap(Assembly & assembly) 39 : { 40 772 : for (const auto & primary_elem_id : _primary_elem_ids) 41 : { 42 722 : 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 722 : if (primary_elem && primary_elem->processor_id() == _mesh.processor_id()) 46 : { 47 : assembly.setCurrentSubdomainID(primary_elem->subdomain_id()); 48 478 : assembly.reinit(primary_elem); 49 478 : std::vector<Point> primary_qps = assembly.qPoints().stdVector(); 50 478 : _n_qp_primary = primary_qps.size(); 51 : 52 478 : const auto & secondary_elem_ids = getCoupledSecondaryElemIDs(primary_elem_id); 53 2190 : for (const auto & secondary_elem_id : secondary_elem_ids) 54 : { 55 : auto it = 56 1712 : 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 1712 : const unsigned short int secondary_side_id = _secondary_side_ids[i_secondary]; 60 : 61 1712 : const Elem * secondary_elem = _mesh.elemPtr(secondary_elem_id); 62 : assembly.setCurrentSubdomainID(secondary_elem->subdomain_id()); 63 1712 : assembly.reinit(secondary_elem, secondary_side_id); 64 1712 : const std::vector<Point> secondary_qps = assembly.qPointsFace().stdVector(); 65 1712 : _n_qp_secondary = secondary_qps.size(); 66 : 67 1712 : _secondary_elem_id_to_qp_indices[secondary_elem_id].resize(secondary_qps.size()); 68 1712 : KDTree kd_tree_qp(primary_qps, _mesh.getMaxLeafSize()); 69 8560 : for (std::size_t i = 0; i < secondary_qps.size(); i++) 70 : { 71 : unsigned int patch_size = 1; 72 6848 : std::vector<std::size_t> return_index(patch_size); 73 6848 : kd_tree_qp.neighborSearch(secondary_qps[i], patch_size, return_index); 74 6848 : _secondary_elem_id_to_qp_indices[secondary_elem_id][i] = return_index[0]; 75 : } 76 : } 77 : } 78 : } 79 50 : }