MFEM  v3.3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
stable3d.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 
13 #include "error.hpp"
14 #include "stable3d.hpp"
15 
16 using namespace std;
17 
18 namespace mfem
19 {
20 
21 STable3D::STable3D (int nr)
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 
34 inline 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 
64 int 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 
97 int 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 
117 int STable3D::Index (int r, int c, int f) const
118 {
119  STable3DNode *node;
120 
121  Sort3 (r, c, f);
122 
123  for (node = Rows[r]; node != NULL; node = node->Prev)
124  {
125  if (node->Column == c)
126  if (node->Floor == f)
127  {
128  return node->Number;
129  }
130  }
131 
132  return -1;
133 }
134 
135 int STable3D::Push4 (int r, int c, int f, int t)
136 {
137  MFEM_ASSERT(r != c && r != f && r != t && c != f && c != t && f != t,
138  " r = " << r << ", c = " << c << ", f = " << f << ", t = " << t);
139 
140  int i = 0;
141  int max = r;
142 
143  if (max < c) { max = c, i = 1; }
144  if (max < f) { max = f, i = 2; }
145  if (max < t) { max = t, i = 3; }
146 
147  switch (i)
148  {
149  case 0:
150  return Push (c,f,t);
151  case 1:
152  return Push (r,f,t);
153  case 2:
154  return Push (r,c,t);
155  case 3:
156  return Push (r,c,f);
157  }
158 
159  return -1;
160 }
161 
162 int STable3D::operator() (int r, int c, int f, int t) const
163 {
164  int i = 0;
165  int max = r;
166 
167  if (max < c) { max = c, i = 1; }
168  if (max < f) { max = f, i = 2; }
169  if (max < t) { max = t, i = 3; }
170 
171  switch (i)
172  {
173  case 0:
174  return (*this)(c,f,t);
175  case 1:
176  return (*this)(r,f,t);
177  case 2:
178  return (*this)(r,c,t);
179  case 3:
180  return (*this)(r,c,f);
181  }
182 
183  return -1;
184 }
185 
186 STable3D::~STable3D ()
187 {
188 #ifdef MFEM_USE_MEMALLOC
189  // NodesMem.Clear(); // this is done implicitly
190 #else
191  for (int i = 0; i < Size; i++)
192  {
193  STable3DNode *aux, *node_p = Rows[i];
194  while (node_p != NULL)
195  {
196  aux = node_p;
197  node_p = node_p->Prev;
198  delete aux;
199  }
200  }
201 #endif
202  delete [] Rows;
203 }
204 
205 }
void Sort3(int &r, int &c, int &f)
Definition: stable3d.cpp:34
STable3DNode * Prev
Definition: stable3d.hpp:23