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

Site Contact