SundanceCellSet.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 "SundanceCellSet.hpp"
00043 #include "SundanceExplicitCellSet.hpp"
00044 #include "SundanceImplicitCellSet.hpp"
00045 #include "SundanceOut.hpp"
00046 #include "PlayaTabs.hpp"
00047 #include "PlayaExceptions.hpp"
00048 #include <algorithm>
00049 #include <iterator>
00050 
00051 using namespace Sundance;
00052 using namespace Teuchos;
00053 using Playa::Handle;
00054 using Playa::Handleable;
00055 
00056 
00057 CellSet::CellSet(const Mesh& mesh, int cellDim,
00058   const CellType& cellType,
00059   const Set<int>& cellLIDs)
00060   : Handle<CellSetBase>(rcp(new ExplicitCellSet(mesh, cellDim, cellType, cellLIDs)))
00061 {}
00062 
00063 CellSet CellSet::setUnion(const CellSet& other) const
00064 {
00065   if (isNull()) return other;
00066   if (other.isNull()) return *this;
00067 
00068   ExplicitCellSet* rtn = new ExplicitCellSet(mesh(), dimension(), cellType());
00069 
00070   checkCompatibility("union", other);
00071   
00072   Set<int>& cells = rtn->cells();
00073 
00074   std::set_union(this->begin(), this->end(), other.begin(), other.end(), 
00075     std::insert_iterator<Set<int> >(cells, cells.begin()));
00076   
00077   return rtn;
00078 }
00079 
00080 CellSet CellSet::setIntersection(const CellSet& other) const
00081 {
00082   if (isNull()) return *this;
00083   if (other.isNull()) return other;
00084 
00085   ExplicitCellSet* rtn = new ExplicitCellSet(mesh(), dimension(), cellType());
00086 
00087   checkCompatibility("intersection", other);
00088   
00089   Set<int>& cells = rtn->cells();
00090 
00091   std::set_intersection(this->begin(), this->end(), other.begin(), other.end(), 
00092     std::insert_iterator<Set<int> >(cells, cells.begin()));
00093   
00094   return rtn;
00095 }
00096 
00097 CellSet CellSet::setDifference(const CellSet& other) const
00098 {
00099   if (isNull()) return *this;
00100   if (other.isNull()) return *this;
00101 
00102   ExplicitCellSet* rtn = new ExplicitCellSet(mesh(), dimension(), cellType());
00103 
00104   checkCompatibility("difference", other);
00105   
00106   Set<int>& cells = rtn->cells();
00107 
00108   std::set_difference(this->begin(), this->end(), other.begin(), other.end(), 
00109     std::insert_iterator<Set<int> >(cells, cells.begin()));
00110   
00111   return rtn;
00112 }
00113 
00114 
00115 void CellSet::checkCompatibility(const std::string& op, const CellSet& other) const 
00116 {
00117 
00118   TEUCHOS_TEST_FOR_EXCEPTION(meshID() != other.meshID(), std::runtime_error,
00119     "CellSet::checkCompatibility(): "
00120     "incompatible mesh ID numbers in " << op
00121     << ". LHS=" << meshID() << " RHS=" << other.meshID());
00122 
00123   TEUCHOS_TEST_FOR_EXCEPTION(dimension() != other.dimension(), std::runtime_error,
00124     "CellSet::checkCompatibility() incompatible dimensions in " << op
00125     << "LHS has "
00126     "dimension=" << dimension() << " but RHS has dimension="
00127     << other.dimension());
00128   
00129   TEUCHOS_TEST_FOR_EXCEPTION(cellType() != other.cellType(), std::runtime_error,
00130     "CellSet::checkCompatibility() incompatible cell types. "
00131     " in " << op << " LHS has "
00132     "cellType=" << cellType() << " but RHS has cellType="
00133     << other.cellType());
00134 
00135 
00136   SUNDANCE_OUT(this->verb() > 2,
00137     "Set operation: " << op << std::endl
00138     << "LHS cells: " << *this << std::endl
00139     << "RHS cells: " << other);
00140                
00141 }
00142 
00143 
00144 bool CellSet::areFacetsOf(const CellSet& other) const
00145 {
00146   Array<int> cofacetLIDs;
00147   int myDim = dimension();
00148   int cofacetDim = other.dimension();
00149   CellType cofacetType = other.cellType();
00150   if (myDim >= cofacetDim) return false;
00151 
00152   for (CellIterator i=begin(); i!=end(); i++)
00153   {
00154     int cellLID = *i;
00155     mesh().getCofacets(myDim, cellLID, cofacetDim, cofacetLIDs);
00156     Set<int> cofacetSet;
00157     for (int c=0; c<cofacetLIDs.size(); c++)
00158     {
00159       int cf = cofacetLIDs[c];
00160       cofacetSet.put(cf);
00161     }
00162     CellSet myCofacetSet(mesh(), cofacetDim, cofacetType, cofacetSet); 
00163     CellSet intersection = myCofacetSet.setIntersection(other);      
00164     /* if the intersection is empty, then we have found a cell
00165      * that is not a facet of one of the other cells */
00166     if (intersection.begin()==intersection.end()) return false;
00167   }
00168   return true;
00169 }
00170 
00171 bool CellSet::operator<(const CellSet& other) const
00172 {
00173   Tabs tab;
00174   bool rtn = ptr()->lessThan(other.ptr().get());
00175   return rtn;
00176 }
00177 
00178 
00179 int CellSet::numCells() const 
00180 {
00181   int count = 0;
00182   for (CellIterator i=begin(); i!=end(); i++)
00183   {
00184     count ++;
00185   }
00186   return count;
00187 }
00188 

Site Contact