SundanceBinaryCellFilter.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #include "SundanceBinaryCellFilter.hpp"
00043 #include "PlayaExceptions.hpp"
00044 #include "SundanceOrderedTuple.hpp"
00045 #include "PlayaTabs.hpp"
00046 #include "SundanceOut.hpp"
00047 
00048 using namespace Sundance;
00049 using namespace Sundance;
00050 using namespace Sundance;
00051 using namespace Teuchos;
00052 
00053 BinaryCellFilter::BinaryCellFilter(const CellFilter& left,
00054                                    const CellFilter& right,
00055                                    const CellFilterOpType& op)
00056   : CellFilterBase(), op_(op), left_(left), right_(right)
00057 {
00058   std::string str;
00059   switch(op)
00060   {
00061     case Union:
00062       str = "Union(";
00063       break;
00064     case Intersection:
00065       str = "Intersection(";
00066       break;
00067     default:
00068       str = "SetDifference(";
00069     }
00070 
00071   setName(str + left.toString() + ", " + right.toString() + ")");
00072 }
00073 
00074 int BinaryCellFilter::dimension(const Mesh& mesh) const
00075 {
00076   int d1 = left_.dimension(mesh);
00077   int d2 = right_.dimension(mesh);
00078 
00079   TEUCHOS_TEST_FOR_EXCEPTION(d1 != d2, std::runtime_error,
00080                      "BinaryCellFilter::dimension() mismatched dimensions. "
00081                      "Left filter has dimension d1=" << d1 << " but "
00082                      "right filter has dimension d2=" << d2);
00083 
00084   return d1;
00085 }
00086 
00087 CellSet BinaryCellFilter::internalGetCells(const Mesh& mesh) const
00088 {
00089   Tabs tab;
00090 
00091   SUNDANCE_OUT(this->verb() > 2,
00092                "cell filter " << toXML().toString() << " is getting its cells for mesh " 
00093                << mesh.id());
00094 
00095   CellSet L = left_.getCells(mesh);
00096   CellSet R = right_.getCells(mesh);
00097 
00098 
00099   SUNDANCE_OUT(this->verb() > 2,
00100                "cell filter " << toXML().toString() << " is performing its operation");
00101   
00102   switch(op_)
00103     {
00104     case Union:
00105       return L.setUnion(R);
00106     case Intersection:
00107       return L.setIntersection(R);
00108     case Difference:
00109       return L.setDifference(R);
00110     }
00111   TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "unknown cell filter op type" << op_ 
00112                      << " in BinaryCellFilter::internalGetCells()");
00113   return L; // -Wall
00114 }
00115 
00116 string BinaryCellFilter::opName() const 
00117 {
00118   switch(op_)
00119     {
00120     case Union:
00121       return "UnionCellFilter";
00122     case Intersection:
00123       return "IntersectionCellFilter";
00124     case Difference:
00125       return "DifferenceCellFilter";
00126     }
00127   TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "unknown cell filter op type" << op_ 
00128                      << " in BinaryCellFilter::opName()");
00129   return "UnionCellFilter";//-Wall
00130 }
00131 
00132 XMLObject BinaryCellFilter::toXML() const 
00133 {
00134   XMLObject rtn(opName());
00135   rtn.addChild(left_.toXML());
00136   rtn.addChild(right_.toXML());
00137   return rtn;
00138 }
00139 
00140 
00141 #ifdef OLD_CELL_FILTER
00142 
00143 bool BinaryCellFilter::lessThan(const CellFilterStub* other) const
00144 {
00145   const BinaryCellFilter* B 
00146     = dynamic_cast<const BinaryCellFilter*>(other);
00147 
00148   TEUCHOS_TEST_FOR_EXCEPTION(B==0,
00149                      std::logic_error,
00150                      "argument " << other->toXML() 
00151                      << " to BinaryCellFilter::lessThan() should be "
00152                      "a BinaryCellFilter pointer.");
00153 
00154   return OrderedTriple<CellFilterOpType, CellFilter, CellFilter>(op_, left_, right_) 
00155     < OrderedTriple<CellFilterOpType, CellFilter, CellFilter>(B->op_, B->left_, B->right_) ;
00156 }
00157 
00158 #endif

Site Contact