SundanceMaximalCofacetBatch.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
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 }

Site Contact