MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
stable3d.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
13#include "error.hpp"
14#include "stable3d.hpp"
15
16using namespace std;
17
18namespace mfem
19{
20
22{
23 int i;
24
25 Size = nr;
26 Rows = new STable3DNode *[nr];
27 for (i = 0; i < nr; i++)
28 {
29 Rows[i] = NULL;
30 }
31 NElem = 0;
32}
33
34inline void Sort3 (int &r, int &c, int &f)
35{
36 int t;
37
38 if (r > c)
39 if (c > f)
40 {
41 t = r; r = f; f = t; // (r,c,f) --> (f,c,r)
42 }
43 else if (r > f)
44 {
45 t = r; r = c; c = f; f = t; // (r,c,f) --> (c,f,r)
46 }
47 else
48 {
49 t = r; r = c; c = t; // (r,c,f) --> (c,r,f)
50 }
51 else if (c > f)
52 {
53 if (r > f)
54 {
55 t = f; f = c; c = r; r = t; // (r,c,f) --> (f,r,c)
56 }
57 else
58 {
59 t = c; c = f; f = t; // (r,c,f) --> (r,f,c)
60 }
61 }
62}
63
64int STable3D::Push (int r, int c, int f)
65{
66 STable3DNode *node;
67
68 MFEM_ASSERT(r != c && c != f && f != r,
69 "STable3D::Push : r = " << r << ", c = " << c << ", f = " << f);
70
71 Sort3 (r, c, f);
72
73 for (node = Rows[r]; node != NULL; node = node->Prev)
74 {
75 if (node->Column == c)
76 if (node->Floor == f)
77 {
78 return node->Number;
79 }
80 }
81
82#ifdef MFEM_USE_MEMALLOC
83 node = NodesMem.Alloc ();
84#else
85 node = new STable3DNode;
86#endif
87 node->Column = c;
88 node->Floor = f;
89 node->Number = NElem;
90 node->Prev = Rows[r];
91 Rows[r] = node;
92
93 NElem++;
94 return (NElem-1);
95}
96
97int STable3D::operator() (int r, int c, int f) const
98{
99 STable3DNode *node;
100
101 Sort3 (r, c, f);
102
103 for (node = Rows[r]; node != NULL; node = node->Prev)
104 {
105 if (node->Column == c)
106 if (node->Floor == f)
107 {
108 return node->Number;
109 }
110 }
111
112 MFEM_ABORT("(r,c,f) = (" << r << "," << c << "," << f << ")");
113
114 return 0;
115}
116
117int STable3D::Index (int r, int c, int f) const
118{
119 STable3DNode *node;
120
121 if (r >= Size)
122 {
123 return -1;
124 }
125
126 Sort3 (r, c, f);
127
128 for (node = Rows[r]; node != NULL; node = node->Prev)
129 {
130 if (node->Column == c)
131 if (node->Floor == f)
132 {
133 return node->Number;
134 }
135 }
136
137 return -1;
138}
139
140int STable3D::Push4 (int r, int c, int f, int t)
141{
142 MFEM_ASSERT(r != c && r != f && r != t && c != f && c != t && f != t,
143 " r = " << r << ", c = " << c << ", f = " << f << ", t = " << t);
144
145 int i = 0;
146 int max = r;
147
148 if (max < c) { max = c, i = 1; }
149 if (max < f) { max = f, i = 2; }
150 if (max < t) { i = 3; }
151
152 switch (i)
153 {
154 case 0:
155 return Push (c,f,t);
156 case 1:
157 return Push (r,f,t);
158 case 2:
159 return Push (r,c,t);
160 case 3:
161 return Push (r,c,f);
162 }
163
164 return -1;
165}
166
167int STable3D::operator() (int r, int c, int f, int t) const
168{
169 int i = 0;
170 int max = r;
171
172 if (max < c) { max = c, i = 1; }
173 if (max < f) { max = f, i = 2; }
174 if (max < t) { i = 3; }
175
176 switch (i)
177 {
178 case 0:
179 return (*this)(c,f,t);
180 case 1:
181 return (*this)(r,f,t);
182 case 2:
183 return (*this)(r,c,t);
184 case 3:
185 return (*this)(r,c,f);
186 }
187
188 return -1;
189}
190
192{
193#ifdef MFEM_USE_MEMALLOC
194 // NodesMem.Clear(); // this is done implicitly
195#else
196 for (int i = 0; i < Size; i++)
197 {
198 STable3DNode *aux, *node_p = Rows[i];
199 while (node_p != NULL)
200 {
201 aux = node_p;
202 node_p = node_p->Prev;
203 delete aux;
204 }
205 }
206#endif
207 delete [] Rows;
208}
209
210void STable3D::Print(std::ostream & os) const
211{
212 os << NElem << endl;
213 for (int row = 0; row < Size; row++)
214 {
215 STable3DNode *node_p = Rows[row];
216 while (node_p != NULL)
217 {
218 os << row
219 << ' ' << node_p->Column
220 << ' ' << node_p->Floor
221 << ' ' << node_p->Number
222 << endl;
223 node_p = node_p->Prev;
224 }
225 }
226}
227
228}
STable3DNode * Prev
Definition stable3d.hpp:24
int operator()(int r, int c, int f) const
Return the number assigned to the table entry. Abort if it's not there.
Definition stable3d.cpp:97
int Index(int r, int c, int f) const
Definition stable3d.cpp:117
int Push(int r, int c, int f)
Check to see if this entry is in the table and add it to the table if it is not there....
Definition stable3d.cpp:64
int Push4(int r, int c, int f, int t)
Check to see if this entry is in the table and add it to the table if it is not there....
Definition stable3d.cpp:140
STable3D(int nr)
Construct the table with a total of 'nr' rows.
Definition stable3d.cpp:21
void Print(std::ostream &out=mfem::out) const
Print out all of the table elements.
Definition stable3d.cpp:210
void Sort3(int &r, int &c, int &f)
Definition stable3d.cpp:34
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
RefCoord t[3]