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

Site Contact