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 "SundanceSubsetCellFilter.hpp"
00032 #include "SundanceExplicitCellSet.hpp"
00033 #include "PlayaExceptions.hpp"
00034 #include "SundanceOrderedTuple.hpp"
00035 #include "SundanceOut.hpp"
00036
00037 using namespace Sundance;
00038 using namespace Sundance;
00039 using namespace Sundance;
00040 using namespace Teuchos;
00041
00042 SubsetCellFilter::SubsetCellFilter(const CellFilter& superset,
00043 const CellPredicate& predicate)
00044 : CellFilterBase(), superset_(superset), predicate_(predicate)
00045 {
00046 int verb=0;
00047 SUNDANCE_MSG3(verb, "creating subset cell filter: ["
00048 << predicate.description()
00049 << "]");
00050 setName("Subset[sup=" + superset.description() + ", pred="
00051 + predicate.description()+"]");
00052 }
00053
00054 SubsetCellFilter::~SubsetCellFilter()
00055 {
00056
00057 }
00058
00059 XMLObject SubsetCellFilter::toXML() const
00060 {
00061 XMLObject rtn("SubsetCellFilter");
00062 rtn.addAttribute("id", Teuchos::toString(id()));
00063 rtn.addChild(predicate_.toXML());
00064 return rtn;
00065 }
00066
00067 bool SubsetCellFilter::lessThan(const CellFilterStub* other) const
00068 {
00069 const SubsetCellFilter* S
00070 = dynamic_cast<const SubsetCellFilter*>(other);
00071
00072 TEUCHOS_TEST_FOR_EXCEPTION(S==0,
00073 std::logic_error,
00074 "argument " << other->toXML()
00075 << " to SubsetCellFilter::lessThan() should be "
00076 "a SubsetCellFilter pointer.");
00077
00078 return OrderedPair<CellFilter, CellPredicate>(superset_, predicate_)
00079 < OrderedPair<CellFilter, CellPredicate>(S->superset_, S->predicate_);
00080 }
00081
00082 CellSet SubsetCellFilter::internalGetCells(const Mesh& mesh) const
00083 {
00084 SUNDANCE_OUT(this->verb() > 1,
00085 "SubsetCellFilter::internalGetCells()");
00086 CellSet super = superset_.getCells(mesh);
00087
00088 int dim = superset_.dimension(mesh);
00089
00090 CellType cellType = mesh.cellType(dim);
00091
00092 predicate_.setMesh(mesh, dim);
00093
00094 ExplicitCellSet* rtn = new ExplicitCellSet(mesh, dim, cellType);
00095
00096 Set<int>& cells = rtn->cells();
00097
00098 const CellPredicateBase* pred = predicate_.ptr().get();
00099
00100
00101 Array<int> cellLID;
00102
00103 cellLID.reserve(mesh.numCells(dim));
00104
00105 for (CellIterator i=super.begin(); i != super.end(); i++)
00106 {
00107 cellLID.append(*i);
00108 }
00109
00110 Array<int> testResults(cellLID.size());
00111 pred->testBatch(cellLID, testResults);
00112
00113 for (int i=0; i<cellLID.size(); i++)
00114 {
00115 SUNDANCE_OUT(this->verb() > 2,
00116 "SubsetCellFilter is testing " << cellLID[i]);
00117 if (testResults[i])
00118 {
00119 SUNDANCE_OUT(this->verb() > 2,
00120 "accepted " << cellLID[i]);
00121 cells.insert(cellLID[i]);
00122 }
00123 else
00124 {
00125 SUNDANCE_OUT(this->verb() > 2,
00126 "rejected " << cellLID[i]);
00127 }
00128 }
00129
00130 return rtn;
00131 }