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 "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
00165
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