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
00068 #ifdef OLD_CELL_FILTER
00069 bool SubsetCellFilter::lessThan(const CellFilterStub* other) const
00070 {
00071 const SubsetCellFilter* S
00072 = dynamic_cast<const SubsetCellFilter*>(other);
00073
00074 TEUCHOS_TEST_FOR_EXCEPTION(S==0,
00075 std::logic_error,
00076 "argument " << other->toXML()
00077 << " to SubsetCellFilter::lessThan() should be "
00078 "a SubsetCellFilter pointer.");
00079
00080 return OrderedPair<CellFilter, CellPredicate>(superset_, predicate_)
00081 < OrderedPair<CellFilter, CellPredicate>(S->superset_, S->predicate_);
00082 }
00083 #endif
00084
00085 CellSet SubsetCellFilter::internalGetCells(const Mesh& mesh) const
00086 {
00087 SUNDANCE_OUT(this->verb() > 1,
00088 "SubsetCellFilter::internalGetCells()");
00089 CellSet super = superset_.getCells(mesh);
00090
00091 int dim = superset_.dimension(mesh);
00092
00093 CellType cellType = mesh.cellType(dim);
00094
00095 predicate_.setMesh(mesh, dim);
00096
00097 ExplicitCellSet* rtn = new ExplicitCellSet(mesh, dim, cellType);
00098
00099 Set<int>& cells = rtn->cells();
00100
00101 const CellPredicateBase* pred = predicate_.ptr().get();
00102
00103
00104 Array<int> cellLID;
00105
00106 cellLID.reserve(mesh.numCells(dim));
00107
00108 for (CellIterator i=super.begin(); i != super.end(); i++)
00109 {
00110 cellLID.append(*i);
00111 }
00112
00113 Array<int> testResults(cellLID.size());
00114 pred->testBatch(cellLID, testResults);
00115
00116 for (int i=0; i<cellLID.size(); i++)
00117 {
00118 SUNDANCE_OUT(this->verb() > 2,
00119 "SubsetCellFilter is testing " << cellLID[i]);
00120 if (testResults[i])
00121 {
00122 SUNDANCE_OUT(this->verb() > 2,
00123 "accepted " << cellLID[i]);
00124 cells.insert(cellLID[i]);
00125 }
00126 else
00127 {
00128 SUNDANCE_OUT(this->verb() > 2,
00129 "rejected " << cellLID[i]);
00130 }
00131 }
00132
00133 return rtn;
00134 }