SundanceBinaryCellFilter.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 "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; // -Wall
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";//-Wall
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

Site Contact