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 "SundanceCFMeshPair.hpp"
00043 #include "PlayaTabs.hpp"
00044 #include "SundanceExplicitCellSet.hpp"
00045 #include "SundanceBinaryCellFilter.hpp"
00046 #include "SundanceSubsetCellFilter.hpp"
00047 #include "SundanceLabelCellPredicate.hpp"
00048 #include "SundanceNullCellFilterStub.hpp"
00049 #include "SundanceNullCellFilter.hpp"
00050
00051 #include "Teuchos_Time.hpp"
00052 #include "Teuchos_TimeMonitor.hpp"
00053
00054 using namespace Sundance;
00055 using namespace Sundance;
00056 using namespace Sundance;
00057 using namespace Teuchos;
00058
00059
00060 static Time& csPartitionTimer()
00061 {
00062 static RCP<Time> rtn
00063 = TimeMonitor::getNewTimer("cell set partitioning");
00064 return *rtn;
00065 }
00066
00067
00068 CFMeshPair::CFMeshPair()
00069 : filter_(),
00070 mesh_(),
00071 cellSet_(),
00072 funcs_()
00073 {}
00074
00075 CFMeshPair::CFMeshPair(const CellFilter& cf,
00076 const Mesh& mesh,
00077 const Set<int>& funcs)
00078 : filter_(cf),
00079 mesh_(mesh),
00080 cellSet_(),
00081 funcs_(funcs)
00082 {
00083 if (filter_.ptr().get() != 0) cellSet_ = filter_.getCells(mesh);
00084 }
00085
00086 bool CFMeshPair::operator<(const CFMeshPair& other) const
00087 {
00088 if (isEmpty()) return true;
00089 if (other.isEmpty()) return false;
00090
00091 TEUCHOS_TEST_FOR_EXCEPTION(mesh_.id() != other.mesh_.id(),
00092 std::runtime_error,
00093 "mismatched meshes!");
00094
00095 return cellSet_ < other.cellSet_;
00096 }
00097
00098 bool CFMeshPair::isEmpty() const
00099 {
00100 return filter_.ptr().get() == 0
00101 || cellSet_.ptr().get() == 0
00102 || cellSet_.begin()==cellSet_.end();
00103 }
00104
00105 CFMeshPair CFMeshPair::setMinus(const CFMeshPair& other) const
00106 {
00107
00108 if (isEmpty()) return CFMeshPair();
00109 if (other.isEmpty()) return *this;
00110
00111 TEUCHOS_TEST_FOR_EXCEPTION(mesh().id() != other.mesh().id(),
00112 std::runtime_error,
00113 "mismatched meshes!");
00114
00115 CellFilter diff = filter() - other.filter();
00116 return CFMeshPair(diff, mesh(), funcs_);
00117 }
00118
00119 CFMeshPair CFMeshPair::intersection(const CFMeshPair& other) const
00120 {
00121 if (isEmpty() || other.isEmpty()) return CFMeshPair();
00122
00123 TEUCHOS_TEST_FOR_EXCEPTION(mesh().id() != other.mesh().id(),
00124 std::runtime_error,
00125 "mismatched meshes!");
00126
00127 CellFilter inter = filter().intersection(other.filter());
00128
00129 return CFMeshPair(inter, mesh(), funcs_.setUnion(other.funcs_));
00130 }
00131
00132
00133 namespace Sundance
00134 {
00135 Array<CFMeshPair> resolvePair(const CFMeshPair& a,
00136 const CFMeshPair& b)
00137 {
00138 Tabs tab0;
00139
00140 CFMeshPair inter = a.intersection(b);
00141 CFMeshPair aMinusB = a.setMinus(b);
00142 CFMeshPair bMinusA = b.setMinus(a);
00143
00144 return tuple(bMinusA, inter, aMinusB);
00145 }
00146
00147
00148 Array<CFMeshPair> resolveSets(const Array<CFMeshPair>& s)
00149 {
00150
00151 if (s.size() == 1) return s;
00152
00153 Array<CFMeshPair> T = tuple(s[0]);
00154
00155 for (int i=0; i<s.size(); i++)
00156 {
00157 CFMeshPair A = s[i];
00158 Array<CFMeshPair> TN;
00159 for (int j=0; j<T.size(); j++)
00160 {
00161 Array<CFMeshPair> p = resolvePair(A, T[j]);
00162 if (!p[0].isEmpty())
00163 {
00164 TN.append(p[0]);
00165 }
00166 if (!p[1].isEmpty())
00167 {
00168 TN.append(p[1]);
00169 }
00170 A = p[2];
00171 }
00172 if (!A.isEmpty())
00173 {
00174 TN.append(A);
00175 }
00176 T = TN;
00177 }
00178 return T;
00179 }
00180
00181
00182 Array<CFMeshPair>
00183 findDisjointFilters(const Array<CellFilter>& filters,
00184 const Array<Set<int> >& funcs,
00185 const Mesh& mesh)
00186 {
00187 TimeMonitor timer(csPartitionTimer() );
00188 Array<CFMeshPair> cf(filters.size());
00189
00190 TEUCHOS_TEST_FOR_EXCEPT(filters.size() != funcs.size());
00191 for (int i=0; i<filters.size(); i++)
00192 {
00193 cf[i] = CFMeshPair(filters[i], mesh, funcs[i]);
00194 }
00195 return resolveSets(cf);
00196 }
00197
00198 }