MFEM v2.0
stable3d.cpp
Go to the documentation of this file.
00001 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
00002 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
00003 // reserved. See file COPYRIGHT for details.
00004 //
00005 // This file is part of the MFEM library. For more information and source code
00006 // availability see http://mfem.googlecode.com.
00007 //
00008 // MFEM is free software; you can redistribute it and/or modify it under the
00009 // terms of the GNU Lesser General Public License (as published by the Free
00010 // Software Foundation) version 2.1 dated February 1999.
00011 
00012 
00013 #include "error.hpp"
00014 #include "stable3d.hpp"
00015 
00016 using namespace std;
00017 
00018 STable3D::STable3D (int nr)
00019 {
00020    int i;
00021 
00022    Size = nr;
00023    Rows = new STable3DNode *[nr];
00024    for (i = 0; i < nr; i++)
00025       Rows[i] = NULL;
00026    NElem = 0;
00027 }
00028 
00029 inline void Sort3 (int &r, int &c, int &f)
00030 {
00031    int t;
00032 
00033    if (r > c)
00034       if (c > f)
00035       {
00036          t = r;  r = f;  f = t;  //  (r,c,f) --> (f,c,r)
00037       }
00038       else
00039          if (r > f)
00040          {
00041             t = r;  r = c;  c = f;  f = t;  //  (r,c,f) --> (c,f,r)
00042          }
00043          else
00044          {
00045             t = r;  r = c;  c = t;  //  (r,c,f) --> (c,r,f)
00046          }
00047    else
00048       if (c > f)
00049       {
00050          if (r > f)
00051          {
00052             t = f;  f = c;  c = r;  r = t;  //  (r,c,f) --> (f,r,c)
00053          }
00054          else
00055          {
00056             t = c;  c = f;  f = t;  //  (r,c,f) --> (r,f,c)
00057          }
00058       }
00059 }
00060 
00061 int STable3D::Push (int r, int c, int f)
00062 {
00063    STable3DNode *node;
00064 
00065 #ifdef MFEM_DEBUG
00066    if (r == c || c == f || f == r)
00067    {
00068       cerr << "STable3D::Push : r = " << r << ", c = " << c << ", f = "
00069            << f << endl;
00070       mfem_error();
00071    }
00072 #endif
00073 
00074    Sort3 (r, c, f);
00075 
00076    for (node = Rows[r]; node != NULL; node = node->Prev)
00077    {
00078       if (node->Column == c)
00079          if (node->Floor == f)
00080             return node->Number;
00081    }
00082 
00083 #ifdef MFEM_USE_MEMALLOC
00084    node = NodesMem.Alloc ();
00085 #else
00086    node = new STable3DNode;
00087 #endif
00088    node->Column = c;
00089    node->Floor  = f;
00090    node->Number = NElem;
00091    node->Prev   = Rows[r];
00092    Rows[r] = node;
00093 
00094    NElem++;
00095    return (NElem-1);
00096 }
00097 
00098 int STable3D::operator() (int r, int c, int f) const
00099 {
00100    STable3DNode *node;
00101 
00102    Sort3 (r, c, f);
00103 
00104    for (node = Rows[r]; node != NULL; node = node->Prev)
00105    {
00106       if (node->Column == c)
00107          if (node->Floor == f)
00108             return node->Number;
00109    }
00110 
00111    cerr << "STable3D::operator(): (r,c,f) = (" << r << "," << c << ","
00112         << f << ")" << endl;
00113    mfem_error();
00114 
00115    return 0;
00116 }
00117 
00118 int STable3D::Index (int r, int c, int f) const
00119 {
00120    STable3DNode *node;
00121 
00122    Sort3 (r, c, f);
00123 
00124    for (node = Rows[r]; node != NULL; node = node->Prev)
00125    {
00126       if (node->Column == c)
00127          if (node->Floor == f)
00128             return node->Number;
00129    }
00130 
00131    return -1;
00132 }
00133 
00134 int STable3D::Push4 (int r, int c, int f, int t)
00135 {
00136 #ifdef MFEM_DEBUG
00137    if (r == c || r == f || r == t || c == f || c == t || f == t)
00138    {
00139       cerr << "STable3D::Push4 : r = " << r << ", c = " << c << ", f = "
00140            << f << ", t = " << t << endl;
00141       mfem_error();
00142    }
00143 #endif
00144 
00145    int i = 0;
00146    int max = r;
00147 
00148    if (max < c) max = c, i = 1;
00149    if (max < f) max = f, i = 2;
00150    if (max < t) max = t, i = 3;
00151 
00152    switch(i) {
00153    case 0:
00154       return Push (c,f,t);
00155    case 1:
00156       return Push (r,f,t);
00157    case 2:
00158       return Push (r,c,t);
00159    case 3:
00160       return Push (r,c,f);
00161    }
00162 
00163    return -1;
00164 }
00165 
00166 int STable3D::operator() (int r, int c, int f, int t) const
00167 {
00168    int i = 0;
00169    int max = r;
00170 
00171    if (max < c) max = c, i = 1;
00172    if (max < f) max = f, i = 2;
00173    if (max < t) max = t, i = 3;
00174 
00175    switch(i) {
00176    case 0:
00177       return (*this)(c,f,t);
00178    case 1:
00179       return (*this)(r,f,t);
00180    case 2:
00181       return (*this)(r,c,t);
00182    case 3:
00183       return (*this)(r,c,f);
00184    }
00185 
00186    return -1;
00187 }
00188 
00189 STable3D::~STable3D ()
00190 {
00191 #ifdef MFEM_USE_MEMALLOC
00192    // NodesMem.Clear();  // this is done implicitly
00193 #else
00194    for (int i = 0; i < Size; i++)
00195    {
00196       STable3DNode *aux, *node_p = Rows[i];
00197       while (node_p != NULL)
00198       {
00199          aux = node_p;
00200          node_p = node_p->Prev;
00201          delete aux;
00202       }
00203    }
00204 #endif
00205    delete [] Rows;
00206 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines