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 "MortarContactUtils.h"
11 :
12 : #include <tuple>
13 :
14 : namespace Moose
15 : {
16 : namespace Mortar
17 : {
18 : namespace Contact
19 : {
20 : void
21 198696 : communicateGaps(
22 : std::unordered_map<const DofObject *, std::pair<ADReal, Real>> & dof_to_weighted_gap,
23 : const MooseMesh & mesh,
24 : const bool nodal,
25 : const bool normalize_c,
26 : const Parallel::Communicator & communicator,
27 : const bool send_data_back)
28 : {
29 : libmesh_parallel_only(communicator);
30 : const auto our_proc_id = communicator.rank();
31 :
32 : // We may have weighted gap information that should go to other processes that own the dofs
33 : using Datum = std::tuple<dof_id_type, ADReal, Real>;
34 : std::unordered_map<processor_id_type, std::vector<Datum>> push_data;
35 :
36 1085485 : for (auto & pr : dof_to_weighted_gap)
37 : {
38 886789 : const auto * const dof_object = pr.first;
39 886789 : const auto proc_id = dof_object->processor_id();
40 886789 : if (proc_id == our_proc_id)
41 864998 : continue;
42 :
43 : push_data[proc_id].push_back(
44 43582 : std::make_tuple(dof_object->id(), std::move(pr.second.first), pr.second.second));
45 : }
46 :
47 198696 : const auto & lm_mesh = mesh.getMesh();
48 : std::unordered_map<processor_id_type, std::vector<const DofObject *>>
49 : pid_to_dof_object_for_sending_back;
50 :
51 : auto action_functor =
52 12319 : [nodal,
53 : our_proc_id,
54 : &lm_mesh,
55 : &dof_to_weighted_gap,
56 : &normalize_c,
57 : &pid_to_dof_object_for_sending_back,
58 27862 : send_data_back](const processor_id_type pid, const std::vector<Datum> & sent_data)
59 : {
60 : mooseAssert(pid != our_proc_id, "We do not send messages to ourself here");
61 : libmesh_ignore(our_proc_id);
62 :
63 34110 : for (auto & [dof_id, weighted_gap, normalization] : sent_data)
64 : {
65 : const auto * const dof_object =
66 21791 : nodal ? static_cast<const DofObject *>(lm_mesh.node_ptr(dof_id))
67 0 : : static_cast<const DofObject *>(lm_mesh.elem_ptr(dof_id));
68 : mooseAssert(dof_object, "This should be non-null");
69 21791 : if (send_data_back)
70 6071 : pid_to_dof_object_for_sending_back[pid].push_back(dof_object);
71 : auto & [our_weighted_gap, our_normalization] = dof_to_weighted_gap[dof_object];
72 21791 : our_weighted_gap += weighted_gap;
73 21791 : if (normalize_c)
74 19247 : our_normalization += normalization;
75 : }
76 211015 : };
77 :
78 198696 : TIMPI::push_parallel_vector_data(communicator, push_data, action_functor);
79 :
80 : // Now send data back if requested
81 198696 : if (!send_data_back)
82 : return;
83 :
84 : std::unordered_map<processor_id_type, std::vector<Datum>> push_back_data;
85 :
86 33232 : for (const auto & [pid, dof_objects] : pid_to_dof_object_for_sending_back)
87 : {
88 : auto & pid_send_data = push_back_data[pid];
89 3457 : pid_send_data.reserve(dof_objects.size());
90 9528 : for (const DofObject * const dof_object : dof_objects)
91 : {
92 : const auto & [our_weighted_gap, our_normalization] =
93 6071 : libmesh_map_find(dof_to_weighted_gap, dof_object);
94 : pid_send_data.push_back(
95 6071 : std::make_tuple(dof_object->id(), our_weighted_gap, our_normalization));
96 : }
97 : }
98 :
99 : auto sent_back_action_functor =
100 3457 : [nodal, our_proc_id, &lm_mesh, &dof_to_weighted_gap, &normalize_c](
101 24284 : const processor_id_type libmesh_dbg_var(pid), const std::vector<Datum> & sent_data)
102 : {
103 : mooseAssert(pid != our_proc_id, "We do not send messages to ourself here");
104 : libmesh_ignore(our_proc_id);
105 :
106 9528 : for (auto & [dof_id, weighted_gap, normalization] : sent_data)
107 : {
108 : const auto * const dof_object =
109 6071 : nodal ? static_cast<const DofObject *>(lm_mesh.node_ptr(dof_id))
110 6071 : : static_cast<const DofObject *>(lm_mesh.elem_ptr(dof_id));
111 : mooseAssert(dof_object, "This should be non-null");
112 : auto & [our_weighted_gap, our_normalization] = dof_to_weighted_gap[dof_object];
113 6071 : our_weighted_gap = weighted_gap;
114 6071 : if (normalize_c)
115 6071 : our_normalization = normalization;
116 : }
117 33232 : };
118 29775 : TIMPI::push_parallel_vector_data(communicator, push_back_data, sent_back_action_functor);
119 : }
120 : }
121 : }
122 : }
|