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 "SundanceBinaryCellFilter.hpp"
00032 #include "PlayaExceptions.hpp"
00033 #include "SundanceOrderedTuple.hpp"
00034 #include "PlayaTabs.hpp"
00035 #include "SundanceOut.hpp"
00036
00037 using namespace Sundance;
00038 using namespace Sundance;
00039 using namespace Sundance;
00040 using namespace Teuchos;
00041
00042 BinaryCellFilter::BinaryCellFilter(const CellFilter& left,
00043 const CellFilter& right,
00044 const CellFilterOpType& op)
00045 : CellFilterBase(), op_(op), left_(left), right_(right)
00046 {
00047 std::string str;
00048 switch(op)
00049 {
00050 case Union:
00051 str = "Union(";
00052 break;
00053 case Intersection:
00054 str = "Intersection(";
00055 break;
00056 default:
00057 str = "SetDifference(";
00058 }
00059
00060 setName(str + left.toString() + ", " + right.toString() + ")");
00061 }
00062
00063 int BinaryCellFilter::dimension(const Mesh& mesh) const
00064 {
00065 int d1 = left_.dimension(mesh);
00066 int d2 = right_.dimension(mesh);
00067
00068 TEUCHOS_TEST_FOR_EXCEPTION(d1 != d2, std::runtime_error,
00069 "BinaryCellFilter::dimension() mismatched dimensions. "
00070 "Left filter has dimension d1=" << d1 << " but "
00071 "right filter has dimension d2=" << d2);
00072
00073 return d1;
00074 }
00075
00076 CellSet BinaryCellFilter::internalGetCells(const Mesh& mesh) const
00077 {
00078 Tabs tab;
00079
00080 SUNDANCE_OUT(this->verb() > 2,
00081 "cell filter " << toXML().toString() << " is getting its cells for mesh "
00082 << mesh.id());
00083
00084 CellSet L = left_.getCells(mesh);
00085 CellSet R = right_.getCells(mesh);
00086
00087
00088 SUNDANCE_OUT(this->verb() > 2,
00089 "cell filter " << toXML().toString() << " is performing its operation");
00090
00091 switch(op_)
00092 {
00093 case Union:
00094 return L.setUnion(R);
00095 case Intersection:
00096 return L.setIntersection(R);
00097 case Difference:
00098 return L.setDifference(R);
00099 }
00100 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "unknown cell filter op type" << op_
00101 << " in BinaryCellFilter::internalGetCells()");
00102 return L;
00103 }
00104
00105 string BinaryCellFilter::opName() const
00106 {
00107 switch(op_)
00108 {
00109 case Union:
00110 return "UnionCellFilter";
00111 case Intersection:
00112 return "IntersectionCellFilter";
00113 case Difference:
00114 return "DifferenceCellFilter";
00115 }
00116 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "unknown cell filter op type" << op_
00117 << " in BinaryCellFilter::opName()");
00118 return "UnionCellFilter";
00119 }
00120
00121 XMLObject BinaryCellFilter::toXML() const
00122 {
00123 XMLObject rtn(opName());
00124 rtn.addChild(left_.toXML());
00125 rtn.addChild(right_.toXML());
00126 return rtn;
00127 }
00128
00129
00130 #ifdef OLD_CELL_FILTER
00131
00132 bool BinaryCellFilter::lessThan(const CellFilterStub* other) const
00133 {
00134 const BinaryCellFilter* B
00135 = dynamic_cast<const BinaryCellFilter*>(other);
00136
00137 TEUCHOS_TEST_FOR_EXCEPTION(B==0,
00138 std::logic_error,
00139 "argument " << other->toXML()
00140 << " to BinaryCellFilter::lessThan() should be "
00141 "a BinaryCellFilter pointer.");
00142
00143 return OrderedTriple<CellFilterOpType, CellFilter, CellFilter>(op_, left_, right_)
00144 < OrderedTriple<CellFilterOpType, CellFilter, CellFilter>(B->op_, B->left_, B->right_) ;
00145 }
00146
00147 #endif