MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
transferutils.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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
13
14#ifdef MFEM_USE_MOONOLITH
15
16#include "transferutils.hpp"
17#include <assert.h>
18
19#include <iostream>
20
21namespace mfem
22{
23
24namespace internal
25{
26
27void MaxCol(const DenseMatrix &mat, double *vec, bool include_vec_elements)
28{
29 int n = mat.Height();
30 int start = 0;
31 if (!include_vec_elements)
32 {
33 for (int i = 0; i < n; ++i)
34 {
35 vec[i] = mat.Elem(i, 0);
36 }
37
38 start = 1;
39 }
40
41 for (int i = 0; i < mat.Height(); ++i)
42 {
43 for (int j = start; j < mat.Width(); ++j)
44 {
45 const double e = mat.Elem(i, j);
46
47 if (vec[i] < e)
48 {
49 vec[i] = e;
50 }
51 }
52 }
53}
54
55void MinCol(const DenseMatrix &mat, double *vec, bool include_vec_elements)
56{
57 int n = mat.Height();
58 int start = 0;
59 if (!include_vec_elements)
60 {
61 for (int i = 0; i < n; ++i)
62 {
63 vec[i] = mat.Elem(i, 0);
64 }
65
66 start = 1;
67 }
68
69 for (int i = 0; i < mat.Height(); ++i)
70 {
71 for (int j = start; j < mat.Width(); ++j)
72 {
73 const double e = mat.Elem(i, j);
74
75 if (vec[i] > e)
76 {
77 vec[i] = e;
78 }
79 }
80 }
81}
82
83Element *NewElem(const int type, const int *cells_data, const int attr)
84{
85 switch (type)
86 {
88 return new Triangle(cells_data, attr);
90 return new Tetrahedron(cells_data, attr);
92 return new Quadrilateral(cells_data, attr);
93 case Geometry::CUBE:
94 return new Hexahedron(cells_data, attr);
95
96 default:
97 {
98 assert(false && "unknown type");
99 mfem::err << "NewElem: unknown type " << type << std::endl;
100 return nullptr;
101 }
102 }
103}
104
105int MaxVertsXFace(const int type)
106{
107 switch (type)
108 {
110 return 2;
112 return 3;
113 case Geometry::SQUARE:
114 return 2;
115 case Geometry::CUBE:
116 return 4;
117
118 default:
119 {
120 assert(false && "unknown type");
121 mfem::err << "NewElem: unknown type " << type << std::endl;
122 return -1;
123 }
124 }
125}
126
127void Finalize(Mesh &mesh, const bool generate_edges)
128{
129 // based on the first element
130 int type = mesh.GetElement(0)->GetGeometryType();
131
132 switch (type)
133 {
135 return mesh.FinalizeTriMesh(generate_edges);
136 case Geometry::SQUARE:
137 return mesh.FinalizeQuadMesh(generate_edges);
138 case Geometry::CUBE:
139 return mesh.FinalizeHexMesh(generate_edges);
141 return mesh.FinalizeTetMesh(generate_edges);
142
143 default:
144 {
145 assert(false && "unknown type");
146 mfem::err << "Finalize: unknown type " << type << std::endl;
147 return;
148 }
149 }
150}
151
152double Sum(const DenseMatrix &mat)
153{
154 Vector rs(mat.Width());
155 mat.GetRowSums(rs);
156 return rs.Sum();
157}
158} // namespace internal
159
160} // namespace mfem
161
162#endif // MFEM_USE_MOONOLITH
MFEM_HOST_DEVICE constexpr auto type(const tuple< T... > &values)
a function intended to be used for extracting the ith type from a tuple.
Definition tuple.hpp:347
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
Definition globals.hpp:71