SundancePositionalCellPredicate.hpp
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 
00043 #ifndef SUNDANCE_POSITIONALCELLPREDICATE_H
00044 #define SUNDANCE_POSITIONALCELLPREDICATE_H
00045 
00046 
00047 #include "SundanceDefs.hpp"
00048 #include "SundanceCellPredicateBase.hpp"
00049 
00050 namespace Sundance
00051 {
00052 using namespace Teuchos;
00053 
00054 #define NEW_CELL_PREDICATE(name)  \
00055   class name : public CellPredicateFunctorBase,  \
00056                public Playa::Handleable<CellPredicateFunctorBase>  \
00057   {  \
00058   public:  \
00059     name() : CellPredicateFunctorBase(#name) {} \
00060     virtual ~name() {}  \
00061     virtual bool operator()(const Point& x) const; \
00062     GET_RCP(CellPredicateFunctorBase);  \
00063   }; \
00064   \
00065   bool name::operator()(const Point& x) const
00066 
00067 
00068 #define CELL_PREDICATE_(name, code) \
00069   class name : public CellPredicateFunctorBase, \
00070                public Playa::Handleable<CellPredicateFunctorBase> \
00071   { \
00072   public:\
00073     name() : CellPredicateFunctorBase(#name){;}            \
00074     virtual ~name(){;}\
00075     virtual bool operator()(const Point& x) const code \
00076     GET_RCP(CellPredicateFunctorBase);\
00077   }
00078 
00079 
00080 #define CELL_PREDICATE(name, code) CELL_PREDICATE_(name, code);
00081 
00082 
00083 
00084 
00085 /** */
00086 class CellPredicateFunctorBase
00087 {
00088 public:
00089   /** */
00090   CellPredicateFunctorBase(const std::string& name="Functor(" + Teuchos::toString(topID()) + ")")
00091     : name_(name) {;}
00092 
00093   /** */
00094   virtual ~CellPredicateFunctorBase(){;}
00095 
00096   /** */
00097   virtual bool operator()(const Point& x) const = 0 ;
00098 
00099   /** */
00100   virtual std::string description() const {return name_;}
00101 private:
00102   static int& topID() {static int rtn=0; rtn++; return rtn;}
00103   std::string name_;
00104 };
00105 
00106   
00107 /** 
00108  * PositionalCellPredicate tests whether the cell's nodes satisfy
00109  * a condition on their positions.
00110  */
00111 class PositionalCellPredicate : public CellPredicateBase 
00112 {
00113 public:
00114       
00115   /** Construct with a function of positions */
00116   PositionalCellPredicate(const RCP<CellPredicateFunctorBase>& func) 
00117     : CellPredicateBase(), func_(func) 
00118     {;}
00119 
00120   /** virtual dtor */
00121   virtual ~PositionalCellPredicate(){;}
00122       
00123   /** Test the predicate on a batch of cells */
00124   virtual void testBatch(const Array<int>& cellLID,
00125     Array<int>& results) const ;
00126 
00127   /** Write to XML */
00128   virtual XMLObject toXML() const ;
00129 
00130   /** comparison */
00131   virtual bool lessThan(const CellPredicateBase* other) const ;
00132 
00133   /** */
00134   virtual std::string description() const {return func_->description();}
00135 
00136   /* */
00137   GET_RCP(CellPredicateBase);
00138 
00139 private:
00140   RCP<CellPredicateFunctorBase> func_;
00141 };
00142 
00143 
00144 
00145 
00146 
00147 /** */
00148 class PointCellPredicateFunctor 
00149   : public CellPredicateFunctorBase
00150 {
00151 public:
00152   /** */
00153   PointCellPredicateFunctor(const Point& x, const double& tol=1.0e-12)
00154     : x_(x), tol_(tol){}
00155 
00156   /** */
00157   bool operator()(const Point& x) const ;
00158 
00159 private:
00160   Point x_;
00161   double tol_;
00162 };
00163 
00164 
00165 
00166 /** */
00167 class CoordinateValueCellPredicateFunctor 
00168   : public CellPredicateFunctorBase
00169 {
00170 public:
00171   /** */
00172   CoordinateValueCellPredicateFunctor(
00173     int direction, const double& value, const double& tol=1.0e-12)
00174     : direction_(direction), value_(value), tol_(tol) {}
00175 
00176   /** */
00177   bool operator()(const Point& x) const ;
00178 
00179 private:
00180   int direction_;
00181   double value_;
00182   double tol_;
00183 };
00184 
00185 /** */
00186 class PointCellPredicate : public PositionalCellPredicate
00187 {
00188 public:
00189   /** */
00190   PointCellPredicate(const Point& x, const double& tol=1.0e-12)
00191     : PositionalCellPredicate(rcp(new PointCellPredicateFunctor(x,tol)))
00192     {}
00193 
00194   /* */
00195   GET_RCP(CellPredicateBase);
00196 };
00197 
00198 /** */
00199 class CoordinateValueCellPredicate : public PositionalCellPredicate
00200 {
00201 public:
00202   /** */
00203   CoordinateValueCellPredicate(int direction,
00204     const double& value, const double& tol=1.0e-12)
00205     : PositionalCellPredicate(
00206       rcp(new CoordinateValueCellPredicateFunctor(direction,value,tol)))
00207     {}
00208 
00209   /* */
00210   GET_RCP(CellPredicateBase);
00211 };
00212 
00213 
00214 }
00215 
00216 
00217 #endif

Site Contact