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