MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
face_map_utils.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12// Finite Element Base classes
13
14#include "face_map_utils.hpp"
15#include <cmath> // std::pow
16
17namespace mfem
18{
19
20namespace internal
21{
22
23std::pair<int,int> GetFaceNormal3D(const int face_id)
24{
25 switch (face_id)
26 {
27 case 0: return std::make_pair(2, 0); // z = 0
28 case 1: return std::make_pair(1, 0); // y = 0
29 case 2: return std::make_pair(0, 1); // x = 1
30 case 3: return std::make_pair(1, 1); // y = 1
31 case 4: return std::make_pair(0, 0); // x = 0
32 case 5: return std::make_pair(2, 1); // z = 1
33 default: MFEM_ABORT("Invalid face ID.")
34 }
35 return std::make_pair(-1, -1); // invalid
36}
37
38void FillFaceMap(const int n_face_dofs_per_component,
39 const std::vector<int> &offsets,
40 const std::vector<int> &strides,
41 const std::vector<int> &n_dofs_per_dim,
42 Array<int> &face_map)
43{
44 const int n_components = offsets.size();
45 const int face_dim = strides.size() / n_components;
46 for (int comp = 0; comp < n_components; ++comp)
47 {
48 const int offset = offsets[comp];
49 for (int i = 0; i < n_face_dofs_per_component; ++i)
50 {
51 int idx = offset;
52 int j = i;
53 for (int d = 0; d < face_dim; ++d)
54 {
55 const int dof1d = n_dofs_per_dim[comp*(face_dim) + d];
56 idx += strides[comp*(face_dim) + d]*(j % dof1d);
57 j /= dof1d;
58 }
59 face_map[comp*n_face_dofs_per_component + i] = idx;
60 }
61 }
62}
63
64void GetTensorFaceMap(const int dim, const int order, const int face_id,
65 Array<int> &face_map)
66{
67 const int dof1d = order + 1;
68 int n_face_dofs = int(std::pow(dof1d, dim - 1));
69 std::vector<int> offsets, strides;
70 switch (dim)
71 {
72 case 1:
73 offsets = {(face_id == 0) ? 0 : dof1d - 1};
74 break;
75 case 2:
76 strides = {(face_id == 0 || face_id == 2) ? 1 : dof1d};
77 switch (face_id)
78 {
79 case 0: offsets = {0}; break; // y = 0
80 case 1: offsets = {dof1d - 1}; break; // x = 1
81 case 2: offsets = {(dof1d-1)*dof1d}; break; // y = 1
82 case 3: offsets = {0}; break; // x = 0
83 }
84 break;
85 case 3:
86 {
87 const auto f = GetFaceNormal3D(face_id);
88 const int face_normal = f.first, level = f.second;
89 if (face_normal == 0) // x-normal
90 {
91 offsets = {level ? dof1d-1 : 0};
92 strides = {dof1d, dof1d*dof1d};
93 }
94 else if (face_normal == 1) // y-normal
95 {
96 offsets = {level ? (dof1d-1)*dof1d : 0};
97 strides = {1, dof1d*dof1d};
98 }
99 else if (face_normal == 2) // z-normal
100 {
101 offsets = {level ? (dof1d-1)*dof1d*dof1d : 0};
102 strides = {1, dof1d};
103 }
104 break;
105 }
106 }
107
108 // same number of DOFs in each dimension, repeat dof1d (dim - 1) times
109 std::vector<int> n_dofs(dim - 1, dof1d);
110 FillFaceMap(n_face_dofs, offsets, strides, n_dofs, face_map);
111}
112
113} // namespace internal
114
115} // namespace mfem
int dim
Definition ex24.cpp:53
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30