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 #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
00152
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