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 "SundanceExceptions.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 bool SubsetCellFilter::lessThan(const CellFilterStub* other) const
00068 {
00069   const SubsetCellFilter* S 
00070     = dynamic_cast<const SubsetCellFilter*>(other);
00071 
00072   TEST_FOR_EXCEPTION(S==0,
00073                      InternalError,
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 }

Site Contact