https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MortarContactUtils.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 "MortarContactUtils.h"
11
12#include <tuple>
13
14namespace Moose
15{
16namespace Mortar
17{
18namespace Contact
19{
20void
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 for (auto & pr : dof_to_weighted_gap)
37 {
38 const auto * const dof_object = pr.first;
39 const auto proc_id = dof_object->processor_id();
40 if (proc_id == our_proc_id)
41 continue;
42
43 push_data[proc_id].push_back(
44 std::make_tuple(dof_object->id(), std::move(pr.second.first), pr.second.second));
45 }
46
47 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 [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 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 for (auto & [dof_id, weighted_gap, normalization] : sent_data)
64 {
65 const auto * const dof_object = nodal ? cast_ptr<const DofObject *>(lm_mesh.node_ptr(dof_id))
66 : cast_ptr<const DofObject *>(lm_mesh.elem_ptr(dof_id));
67 mooseAssert(dof_object, "This should be non-null");
68 if (send_data_back)
69 pid_to_dof_object_for_sending_back[pid].push_back(dof_object);
70 auto & [our_weighted_gap, our_normalization] = dof_to_weighted_gap[dof_object];
71 our_weighted_gap += weighted_gap;
72 if (normalize_c)
73 our_normalization += normalization;
74 }
75 };
76
77 TIMPI::push_parallel_vector_data(communicator, push_data, action_functor);
78
79 // Now send data back if requested
80 if (!send_data_back)
81 return;
82
83 std::unordered_map<processor_id_type, std::vector<Datum>> push_back_data;
84
85 for (const auto & [pid, dof_objects] : pid_to_dof_object_for_sending_back)
86 {
87 auto & pid_send_data = push_back_data[pid];
88 pid_send_data.reserve(dof_objects.size());
89 for (const DofObject * const dof_object : dof_objects)
90 {
91 const auto & [our_weighted_gap, our_normalization] =
92 libmesh_map_find(dof_to_weighted_gap, dof_object);
93 pid_send_data.push_back(
94 std::make_tuple(dof_object->id(), our_weighted_gap, our_normalization));
95 }
96 }
97
98 auto sent_back_action_functor =
99 [nodal, our_proc_id, &lm_mesh, &dof_to_weighted_gap, &normalize_c](
100 const processor_id_type libmesh_dbg_var(pid), const std::vector<Datum> & sent_data)
101 {
102 mooseAssert(pid != our_proc_id, "We do not send messages to ourself here");
103 libmesh_ignore(our_proc_id);
104
105 for (auto & [dof_id, weighted_gap, normalization] : sent_data)
106 {
107 const auto * const dof_object = nodal ? cast_ptr<const DofObject *>(lm_mesh.node_ptr(dof_id))
108 : cast_ptr<const DofObject *>(lm_mesh.elem_ptr(dof_id));
109 mooseAssert(dof_object, "This should be non-null");
110 auto & [our_weighted_gap, our_normalization] = dof_to_weighted_gap[dof_object];
111 our_weighted_gap = weighted_gap;
112 if (normalize_c)
113 our_normalization = normalization;
114 }
115 };
116 TIMPI::push_parallel_vector_data(communicator, push_back_data, sent_back_action_functor);
117}
118}
119}
120}
MeshBase & mesh
void communicateGaps(std::unordered_map< const DofObject *, std::pair< ADReal, Real > > &dof_to_weighted_gap, const MooseMesh &mesh, bool nodal, bool normalize_c, const Parallel::Communicator &communicator, bool send_data_back)
This function is used to communicate gaps across processes.
void push_parallel_vector_data(const Communicator &comm, MapToVectors &&data, const ActionFunctor &act_on_data)