Go to the documentation of this file.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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "SundanceMaximalCofacetBatch.hpp"
00043 #include "PlayaExceptions.hpp"
00044
00045 using namespace Sundance;
00046 using namespace Teuchos;
00047 using namespace Sundance;
00048
00049 MaximalCofacetBatch::MaximalCofacetBatch()
00050 : cofacetLIDs_(2),
00051 facetIndices_(2),
00052 numCells_(-1),
00053 numCofacets_(-1)
00054 {
00055 for (int i=0; i<2; i++)
00056 {
00057 cofacetLIDs_[i] = rcp(new Array<int>());
00058 facetIndices_[i] = rcp(new Array<int>());
00059 }
00060 }
00061
00062 void MaximalCofacetBatch::reset(int numCells, int numCofacets)
00063 {
00064 TEUCHOS_TEST_FOR_EXCEPTION(numCofacets < 0 || numCofacets > 2, std::runtime_error,
00065 "invalid number of maximal cofacets = " << numCofacets);
00066 numCofacets_ = numCofacets;
00067 reset(numCells);
00068 }
00069
00070 void MaximalCofacetBatch::reset(int numCells)
00071 {
00072 numCells_ = numCells;
00073 TEUCHOS_TEST_FOR_EXCEPTION(numCells_ <= 0, std::runtime_error,
00074 "invalid number of cells = " << numCells_);
00075 for (int i=0; i<numCofacets_; i++)
00076 {
00077 cofacetLIDs_[i]->resize(numCells_);
00078 facetIndices_[i]->resize(numCells_);
00079 }
00080 }
00081
00082 void MaximalCofacetBatch::addSingleCofacet(int c,
00083 int cofacetLID, int facetIndex)
00084 {
00085 TEUCHOS_TEST_FOR_EXCEPTION(numCofacets_ != 1, std::runtime_error,
00086 "addSingleCofacet called for a batch configured with " << numCofacets_
00087 << " cofacets");
00088
00089 cofacetLIDs_[0]->operator[](c) = cofacetLID;
00090 facetIndices_[0]->operator[](c) = facetIndex;
00091 }
00092 void MaximalCofacetBatch::addTwoCofacets(int c,
00093 int cofacet1, int facetIndex1,
00094 int cofacet2, int facetIndex2
00095 )
00096 {
00097 TEUCHOS_TEST_FOR_EXCEPTION(numCofacets_ != 2, std::runtime_error,
00098 "addTwoCofacets called for a batch configured with " << numCofacets_
00099 << " cofacets");
00100
00101 cofacetLIDs_[0]->operator[](c) = cofacet1;
00102 facetIndices_[0]->operator[](c) = facetIndex1;
00103
00104 cofacetLIDs_[1]->operator[](c) = cofacet2;
00105 facetIndices_[1]->operator[](c) = facetIndex2;
00106 }
00107
00108 int MaximalCofacetBatch::cofacetLID(int c, int n, int& facetIndex) const
00109 {
00110 TEUCHOS_TEST_FOR_EXCEPTION(n >= numCofacets_, std::runtime_error,
00111 "invalid cofacet number n=" << n);
00112 TEUCHOS_TEST_FOR_EXCEPTION(c >= numCells_, std::runtime_error,
00113 "invalid cell number c=" << c);
00114
00115 facetIndex = facetIndices_[n]->operator[](c);
00116 return cofacetLIDs_[n]->operator[](c);
00117 }
00118
00119 void MaximalCofacetBatch::getSpecifiedCofacets(
00120 const Array<int>& cofacetNumbers,
00121 RCP<Array<int> >& cofacets,
00122 RCP<Array<int> >& facetIndices) const
00123 {
00124 TEUCHOS_TEST_FOR_EXCEPTION((int) cofacetNumbers.size() != numCells(),
00125 std::runtime_error,
00126 "mismatch between cofacet batch size (" << numCells() << ") and "
00127 "requested number of cofacets (" << cofacetNumbers.size() << ")");
00128
00129 cofacets->resize(numCells());
00130 facetIndices->resize(numCells());
00131
00132 for (int c=0; c<numCells(); c++)
00133 {
00134 (*cofacets)[c] = cofacetLID(c, cofacetNumbers[c], (*facetIndices)[c]);
00135 }
00136 }
00137
00138 void MaximalCofacetBatch::getSpecifiedCofacets(
00139 int cofacetNumber,
00140 RCP<Array<int> >& cofacets,
00141 RCP<Array<int> >& facetIndices) const
00142 {
00143 TEUCHOS_TEST_FOR_EXCEPTION(cofacetNumber < 0 || cofacetNumber>1,
00144 std::runtime_error,
00145 "invalid cofacet number=" << cofacetNumber);
00146
00147 cofacets = cofacetLIDs_[cofacetNumber];
00148 facetIndices = facetIndices_[cofacetNumber];
00149 }