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