MFEM  v3.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 <iostream>
14 #include "error.hpp"
15 #include "stable3d.hpp"
16 
17 using namespace std;
18 
19 namespace mfem
20 {
21 
22 STable3D::STable3D (int nr)
23 {
24  int i;
25 
26  Size = nr;
27  Rows = new STable3DNode *[nr];
28  for (i = 0; i < nr; i++)
29  {
30  Rows[i] = NULL;
31  }
32  NElem = 0;
33 }
34 
35 inline void Sort3 (int &r, int &c, int &f)
36 {
37  int t;
38 
39  if (r > c)
40  if (c > f)
41  {
42  t = r; r = f; f = t; // (r,c,f) --> (f,c,r)
43  }
44  else if (r > f)
45  {
46  t = r; r = c; c = f; f = t; // (r,c,f) --> (c,f,r)
47  }
48  else
49  {
50  t = r; r = c; c = t; // (r,c,f) --> (c,r,f)
51  }
52  else if (c > f)
53  {
54  if (r > f)
55  {
56  t = f; f = c; c = r; r = t; // (r,c,f) --> (f,r,c)
57  }
58  else
59  {
60  t = c; c = f; f = t; // (r,c,f) --> (r,f,c)
61  }
62  }
63 }
64 
65 int STable3D::Push (int r, int c, int f)
66 {
67  STable3DNode *node;
68 
69  MFEM_ASSERT(r != c && c != f && f != r,
70  "STable3D::Push : r = " << r << ", c = " << c << ", f = " << f);
71 
72  Sort3 (r, c, f);
73 
74  for (node = Rows[r]; node != NULL; node = node->Prev)
75  {
76  if (node->Column == c)
77  if (node->Floor == f)
78  {
79  return node->Number;
80  }
81  }
82 
83 #ifdef MFEM_USE_MEMALLOC
84  node = NodesMem.Alloc ();
85 #else
86  node = new STable3DNode;
87 #endif
88  node->Column = c;
89  node->Floor = f;
90  node->Number = NElem;
91  node->Prev = Rows[r];
92  Rows[r] = node;
93 
94  NElem++;
95  return (NElem-1);
96 }
97 
98 int STable3D::operator() (int r, int c, int f) const
99 {
100  STable3DNode *node;
101 
102  Sort3 (r, c, f);
103 
104  for (node = Rows[r]; node != NULL; node = node->Prev)
105  {
106  if (node->Column == c)
107  if (node->Floor == f)
108  {
109  return node->Number;
110  }
111  }
112 
113  MFEM_ABORT("(r,c,f) = (" << r << "," << c << "," << f << ")");
114 
115  return 0;
116 }
117 
118 int STable3D::Index (int r, int c, int f) const
119 {
120  STable3DNode *node;
121 
122  Sort3 (r, c, f);
123 
124  for (node = Rows[r]; node != NULL; node = node->Prev)
125  {
126  if (node->Column == c)
127  if (node->Floor == f)
128  {
129  return node->Number;
130  }
131  }
132 
133  return -1;
134 }
135 
136 int STable3D::Push4 (int r, int c, int f, int t)
137 {
138  MFEM_ASSERT(r != c && r != f && r != t && c != f && c != t && f != t,
139  " r = " << r << ", c = " << c << ", f = " << f << ", t = " << t);
140 
141  int i = 0;
142  int max = r;
143 
144  if (max < c) { max = c, i = 1; }
145  if (max < f) { max = f, i = 2; }
146  if (max < t) { max = t, i = 3; }
147 
148  switch (i)
149  {
150  case 0:
151  return Push (c,f,t);
152  case 1:
153  return Push (r,f,t);
154  case 2:
155  return Push (r,c,t);
156  case 3:
157  return Push (r,c,f);
158  }
159 
160  return -1;
161 }
162 
163 int STable3D::operator() (int r, int c, int f, int t) const
164 {
165  int i = 0;
166  int max = r;
167 
168  if (max < c) { max = c, i = 1; }
169  if (max < f) { max = f, i = 2; }
170  if (max < t) { max = t, i = 3; }
171 
172  switch (i)
173  {
174  case 0:
175  return (*this)(c,f,t);
176  case 1:
177  return (*this)(r,f,t);
178  case 2:
179  return (*this)(r,c,t);
180  case 3:
181  return (*this)(r,c,f);
182  }
183 
184  return -1;
185 }
186 
187 STable3D::~STable3D ()
188 {
189 #ifdef MFEM_USE_MEMALLOC
190  // NodesMem.Clear(); // this is done implicitly
191 #else
192  for (int i = 0; i < Size; i++)
193  {
194  STable3DNode *aux, *node_p = Rows[i];
195  while (node_p != NULL)
196  {
197  aux = node_p;
198  node_p = node_p->Prev;
199  delete aux;
200  }
201  }
202 #endif
203  delete [] Rows;
204 }
205 
206 }
void Sort3(int &r, int &c, int &f)
Definition: stable3d.cpp:35
STable3DNode * Prev
Definition: stable3d.hpp:23