https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CacheInfoThread.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 "CacheInfoThread.h"
11
12#include "libmesh/elem.h"
13#include "libmesh/threads.h"
14
15CacheInfoThread::CacheInfoThread(MooseMesh & mesh, const bool cache_node_blocks)
16 : _mesh(mesh), _cache_node_blocks(cache_node_blocks)
17{
18}
19
21 : _mesh(x._mesh), _cache_node_blocks(x._cache_node_blocks)
22{
23}
24
25void
26CacheInfoThread::cacheNodeBlock(const dof_id_type node_id, const SubdomainID block_id)
27{
28 // Most calls revisit a node away from any interface, which this single lookup settles
29 if (const auto it = _node_block.find(node_id); it != _node_block.end())
30 {
31 if (it->second == block_id)
32 return;
33
34 // The elements incident on this node disagree, so it needs the full set from here on
35 _interface_node_blocks.emplace(node_id, std::set<SubdomainID>{it->second, block_id});
36 _node_block.erase(it);
37 return;
38 }
39
40 if (const auto it = _interface_node_blocks.find(node_id); it != _interface_node_blocks.end())
41 it->second.insert(block_id);
42 else
43 _node_block.emplace(node_id, block_id);
44}
45
46void
47CacheInfoThread::operator()(const ConstElemRange & range)
48{
49 const auto & mesh = _mesh.getMesh();
50
51 for (const auto & elem : range)
52 {
53 const Elem * ip_elem = elem->interior_parent();
54
55 if (ip_elem)
56 {
57 unsigned int ip_side = ip_elem->which_side_am_i(elem);
58
59 // For some grid sequencing tests: ip_side == libMesh::invalid_uint
60 if (ip_side != libMesh::invalid_uint)
61 {
62 auto pair = std::make_pair(ip_elem, static_cast<unsigned short int>(ip_side));
63 _higher_d_elem_side_to_lower_d_elem.emplace(pair, elem);
64 _lower_d_elem_to_higher_d_elem_side.emplace(elem, pair.second);
65
66 auto id = elem->subdomain_id();
67 if (ip_elem->neighbor_ptr(ip_side))
68 {
69 if (mesh.subdomain_name(id).find("INTERNAL_SIDE_LOWERD_SUBDOMAIN_") != std::string::npos)
70 _lower_d_interior_blocks.insert(id);
71 }
72 else
73 {
74 if (mesh.subdomain_name(id).find("BOUNDARY_SIDE_LOWERD_SUBDOMAIN_") != std::string::npos)
75 _lower_d_boundary_blocks.insert(id);
76 }
77 }
78 }
79
81 {
82 const auto block_id = elem->subdomain_id();
83 for (const auto nd : make_range(elem->n_nodes()))
84 {
85 const Node & node = *elem->node_ptr(nd);
86 cacheNodeBlock(node.id(), block_id);
87 }
88 }
89 }
90}
91
92void
94{
95 // Adding y's entries through cacheNodeBlock() keeps each node in only one of _node_block and
96 // _interface_node_blocks: a node that each thread saw with a single, but different, subdomain
97 // becomes an interface node here
98 for (const auto & [node_id, block_id] : y._node_block)
99 cacheNodeBlock(node_id, block_id);
100 for (const auto & [node_id, block_ids] : y._interface_node_blocks)
101 for (const auto block_id : block_ids)
102 cacheNodeBlock(node_id, block_id);
103
112}
subdomain_id_type SubdomainID
Fills lower-d side maps and node-to-block ownership for MooseMesh::cacheInfo().
std::unordered_map< std::pair< const Elem *, unsigned short int >, const Elem * > _higher_d_elem_side_to_lower_d_elem
const bool _cache_node_blocks
Whether node-to-block ownership has to be recorded at all.
std::unordered_map< dof_id_type, SubdomainID > _node_block
The subdomain of the elements incident on a node, for the nodes whose incident elements all agree,...
std::unordered_map< const Elem *, unsigned short int > _lower_d_elem_to_higher_d_elem_side
MooseMesh & _mesh
CacheInfoThread(MooseMesh &mesh, bool cache_node_blocks)
std::unordered_map< dof_id_type, std::set< SubdomainID > > _interface_node_blocks
The full subdomain set of the nodes whose incident elements disagree, that is the nodes on a subdomai...
void cacheNodeBlock(dof_id_type node_id, SubdomainID block_id)
Record that an element of subdomain block_id is incident on the node node_id.
std::set< SubdomainID > _lower_d_interior_blocks
std::set< SubdomainID > _lower_d_boundary_blocks
void operator()(const ConstElemRange &range)
void join(const CacheInfoThread &y)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3535
MeshBase & mesh
const unsigned int invalid_uint