00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 #include "SundanceMaximalCofacetBatch.hpp"
00032 #include "PlayaExceptions.hpp"
00033 
00034 using namespace Sundance;
00035 using namespace Teuchos;
00036 using namespace Sundance;
00037 
00038 MaximalCofacetBatch::MaximalCofacetBatch()
00039   : cofacetLIDs_(2),
00040     facetIndices_(2),
00041     numCells_(-1),
00042     numCofacets_(-1)
00043 {
00044   for (int i=0; i<2; i++)
00045   {
00046     cofacetLIDs_[i] = rcp(new Array<int>());
00047     facetIndices_[i] = rcp(new Array<int>());
00048   }
00049 }
00050 
00051 void MaximalCofacetBatch::reset(int numCells, int numCofacets)
00052 {
00053   TEUCHOS_TEST_FOR_EXCEPTION(numCofacets < 0 || numCofacets > 2, std::runtime_error,
00054     "invalid number of maximal cofacets = " << numCofacets);
00055   numCofacets_ = numCofacets;
00056   reset(numCells);
00057 }
00058 
00059 void MaximalCofacetBatch::reset(int numCells)
00060 {
00061   numCells_ = numCells;
00062   TEUCHOS_TEST_FOR_EXCEPTION(numCells_ <= 0, std::runtime_error,
00063     "invalid number of cells = " << numCells_);
00064   for (int i=0; i<numCofacets_; i++)
00065   {
00066     cofacetLIDs_[i]->resize(numCells_);
00067     facetIndices_[i]->resize(numCells_);
00068   }
00069 }
00070 
00071 void MaximalCofacetBatch::addSingleCofacet(int c, 
00072   int cofacetLID, int facetIndex)
00073 {
00074   TEUCHOS_TEST_FOR_EXCEPTION(numCofacets_ != 1, std::runtime_error,
00075     "addSingleCofacet called for a batch configured with " << numCofacets_ 
00076     << " cofacets");
00077 
00078   cofacetLIDs_[0]->operator[](c) = cofacetLID;
00079   facetIndices_[0]->operator[](c) = facetIndex;
00080 }
00081 void MaximalCofacetBatch::addTwoCofacets(int c, 
00082   int cofacet1, int facetIndex1,
00083   int cofacet2, int facetIndex2
00084 )
00085 {
00086   TEUCHOS_TEST_FOR_EXCEPTION(numCofacets_ != 2, std::runtime_error,
00087     "addTwoCofacets called for a batch configured with " << numCofacets_ 
00088     << " cofacets");
00089 
00090   cofacetLIDs_[0]->operator[](c) = cofacet1;
00091   facetIndices_[0]->operator[](c) = facetIndex1;
00092 
00093   cofacetLIDs_[1]->operator[](c) = cofacet2;
00094   facetIndices_[1]->operator[](c) = facetIndex2;
00095 }
00096 
00097 int MaximalCofacetBatch::cofacetLID(int c, int n, int& facetIndex) const
00098 {
00099   TEUCHOS_TEST_FOR_EXCEPTION(n >= numCofacets_, std::runtime_error,
00100     "invalid cofacet number n=" << n);
00101   TEUCHOS_TEST_FOR_EXCEPTION(c >= numCells_, std::runtime_error,
00102     "invalid cell number c=" << c);
00103 
00104   facetIndex = facetIndices_[n]->operator[](c);
00105   return cofacetLIDs_[n]->operator[](c);
00106 }
00107 
00108 void MaximalCofacetBatch::getSpecifiedCofacets(
00109   const Array<int>& cofacetNumbers,
00110   RCP<Array<int> >& cofacets,
00111   RCP<Array<int> >& facetIndices) const
00112 {
00113   TEUCHOS_TEST_FOR_EXCEPTION((int) cofacetNumbers.size() != numCells(),
00114     std::runtime_error,
00115     "mismatch between cofacet batch size (" << numCells() << ") and "
00116     "requested number of cofacets (" << cofacetNumbers.size() << ")");
00117 
00118   cofacets->resize(numCells());
00119   facetIndices->resize(numCells());
00120 
00121   for (int c=0; c<numCells(); c++)
00122   {
00123     (*cofacets)[c] = cofacetLID(c, cofacetNumbers[c], (*facetIndices)[c]);
00124   }
00125 }
00126 
00127 void MaximalCofacetBatch::getSpecifiedCofacets(
00128   int cofacetNumber,
00129   RCP<Array<int> >& cofacets,
00130   RCP<Array<int> >& facetIndices) const
00131 {
00132   TEUCHOS_TEST_FOR_EXCEPTION(cofacetNumber < 0 || cofacetNumber>1,    
00133     std::runtime_error,
00134     "invalid cofacet number=" << cofacetNumber);
00135 
00136   cofacets = cofacetLIDs_[cofacetNumber];
00137   facetIndices = facetIndices_[cofacetNumber];
00138 }