https://mooseframework.inl.gov
Loading...
Searching...
No Matches
THMUtils.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 "THMUtils.h"
11#include "MooseUtils.h"
12#include "MooseTypes.h"
13#include "libmesh/vector_value.h"
14#include "metaphysicl/parallel_dualnumber.h"
15#include "metaphysicl/parallel_numberarray.h"
16#include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
17
18namespace THM
19{
20
21void
22computeOrthogonalDirections(const RealVectorValue & n_unnormalized,
23 RealVectorValue & t1,
24 RealVectorValue & t2)
25{
26 const RealVectorValue n = n_unnormalized.unit();
27
28 if (MooseUtils::absoluteFuzzyEqual(std::abs(n(0)), 1.0))
29 {
30 t1 = RealVectorValue(0, 1, 0);
31 t2 = RealVectorValue(0, 0, 1);
32 }
33 else
34 {
35 // Gram-Schmidt process to get first
36 RealVectorValue ex(1, 0, 0);
37 t1 = ex - (ex * n) * n;
38 t1 = t1.unit();
39
40 // use cross-product to get second
41 t2 = n.cross(t1);
42 t2 = t2.unit();
43 }
44}
45
46void
47allGatherADVectorMap(const Parallel::Communicator & comm,
48 std::map<dof_id_type, std::vector<ADReal>> & this_map)
49{
50 std::vector<std::map<dof_id_type, std::vector<ADReal>>> all_maps;
51 comm.allgather(this_map, all_maps);
52 for (auto & one_map : all_maps)
53 for (auto & it : one_map)
54 this_map[it.first] = it.second;
55}
56
57void
58allGatherADVectorMapSum(const Parallel::Communicator & comm,
59 std::map<dof_id_type, std::vector<ADReal>> & this_map)
60{
61 std::vector<std::map<dof_id_type, std::vector<ADReal>>> all_maps;
62 comm.allgather(this_map, all_maps);
63 this_map.clear();
64 for (auto & one_map : all_maps)
65 for (auto & it : one_map)
66 if (this_map.find(it.first) == this_map.end())
67 this_map[it.first] = it.second;
68 else
69 {
70 auto & existing = this_map[it.first];
71 for (const auto i : index_range(existing))
72 existing[i] += it.second[i];
73 }
74}
75}
TypeVector< T > unit() const
void allGatherADVectorMap(const Parallel::Communicator &comm, std::map< dof_id_type, std::vector< ADReal > > &this_map)
Parallel gather of a map of DoF ID to AD vector.
Definition THMUtils.C:47
void computeOrthogonalDirections(const RealVectorValue &n_unnormalized, RealVectorValue &t1, RealVectorValue &t2)
Computes two unit vectors orthogonal to the given vector.
Definition THMUtils.C:22
void allGatherADVectorMapSum(const Parallel::Communicator &comm, std::map< dof_id_type, std::vector< ADReal > > &this_map)
Parallel gather of a map of DoF ID to AD vector.
Definition THMUtils.C:58