SundanceSubsetCellFilter.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
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 //  Out::os() << "~SubsetCellFilter()" << std::endl;
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 }

Site Contact