SundanceMaximalCofacetBatch.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
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 }

Site Contact