SundanceCellFilter.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 #ifndef SUNDANCE_CELLFILTER_H
00032 #define SUNDANCE_CELLFILTER_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceSet.hpp"
00036 #include "SundanceCellSet.hpp"
00037 #include "SundanceCellPredicate.hpp"
00038 #include "SundanceCellFilterStub.hpp"
00039 #include "SundancePositionalCellPredicate.hpp"
00040 #include "SundanceOrderedHandle.hpp"
00041 #include "SundanceHandle.hpp"
00042 #include "Teuchos_RefCountPtr.hpp"
00043 
00044 namespace Sundance
00045 {
00046 using namespace Teuchos;
00047   
00048 
00049 class CellFilterBase;
00050 
00051   
00052 /** 
00053  * CellFilter is a user-level object representing a 
00054  * filter that selects from a mesh all cells that
00055  * satisfy some condition. CellFilters are used to identify subdomains
00056  * on which equations or boundary conditions apply. 
00057  * Examples of cell filters are to identify
00058  * all cells on the boundary of the mesh, or all cells whose node positions
00059  * satisfy some mathematical equation or inequality. 
00060  *
00061  * <h4> Use of CellFilter </h4>
00062  *
00063  * \code
00064  * // Define a filter that will pick out all maximal cells located 
00065  * // entirely in the left half-plane x < 0 
00066  * CellFilter elements = new MaximalCellFilter();
00067  * CellFilter leftHalf = elements.subset( x <= 0.0 );
00068  * 
00069  * // Apply the leftHalf filter to a mesh, thus enumerating
00070  * // all the cells of that mesh living in the left half-plane
00071  * CellSet leftCells = leftHalf.getCells(mesh);
00072  * \endcode
00073  *
00074  * <h4> Set operations with CellFilter objects </h4>
00075  *
00076  * Operations on cell filters can produce new filters. 
00077  *
00078  * The subset() and labeledSubset() operators
00079  * produce new CellFilters that pick out a subset of the cells
00080  * satisfying an additional condition given in the argument
00081  * to the subset methods. 
00082  *
00083  * Binary set operations can also produce new filters.
00084  * Suppose
00085  * <tt>a</tt> and <tt>b</tt> are CellFilters whose <tt>getCells()</tt>
00086  * methods produce
00087  * CellSets \f$\{A\}\f$ and \f$\{B\}\f$, respectively. There exist
00088  * operators for the following binary operations:
00089  * <ul>
00090  * <li> The <b>union</b> operator <tt>a+b.</tt> The result of a union
00091  * operation is a filter that will produce the union of the two operand's
00092  * cell sets, 
00093  * \f[{\tt a+b} \rightarrow \{A\} \cup \{B\}, \f]
00094  * i.e., all cells that are in either \f$\{A\}\f$ or \f$\{B\}\f$
00095  * <li> The <b>intersection </b> operator <tt>a.intersection(b)</tt> 
00096  * The result of an intersection
00097  * operation is a filter that will produce the intersection
00098  * of the two operand's
00099  * cell sets, 
00100  * \f[{\tt a.intersection(b)} \rightarrow \{A\} \cap \{B\}, \f]
00101  * i.e., all cells that are in both \f$\{A\}\f$ and \f$\{B\}\f$
00102  * <li> The <b>exclusion </b> operator <tt>a-b.</tt>  
00103  * The result of an exclusion
00104  * operation is a filter that will produce the exclusion
00105  * of the two operand's
00106  * cell sets, 
00107  * \f[{\tt a - b} \rightarrow \{A\} \setminus \{B\}, \f]
00108  * i.e., all cells that are in \f$\{A\}\f$ but not in \f$\{B\}\f$
00109  * </ul>
00110  * \code
00111  * CellFilter elements = new MaximalCellFilter();
00112  * CellFilter leftHalf = elements.subset( x <= 0.0 );
00113  * CellFilter topHalf = elements.subset( x >= 0.0 );
00114  * CellFilter topLeftQuarter = leftHalf.intersection(topHalf);
00115  * CellFilter 
00116  * \endcode
00117  *
00118 
00119 */
00120 class CellFilter : public OrderedHandle<CellFilterStub>
00121 {
00122 public:
00123   ORDERED_HANDLE_CTORS(CellFilter, CellFilterStub);
00124 
00125   /** Find the cells passing this filter on the given mesh */
00126   CellSet getCells(const Mesh& mesh) const ;
00127 
00128   /** Return the dimension of this cell set on the given mesh */
00129   int dimension(const Mesh& mesh) const ;
00130 
00131   /** Return a filter that returns the set union of the sets
00132    * produced by the two operand filters */
00133   CellFilter operator+(const CellFilter& other) const ;
00134     
00135   /** Return a filter that returns the set difference between the sets
00136    * produced by the two operand filters */
00137   CellFilter operator-(const CellFilter& other) const ;
00138 
00139   /** Return a filter that returns the set intersection of the sets
00140    * produced by the two operand filters */
00141   CellFilter intersection(const CellFilter& other) const ;
00142 
00143   // /** Return a filter that returns the
00144   //      *  subset of cells for which the logical expression 
00145   //      * is true */
00146   //     CellFilter subset(const LogicalExpr& expr) const ;
00147 
00148     
00149   /** Return a filter that will return the subset of cells having
00150    * the given label */
00151   CellFilter labeledSubset(int label) const ;
00152 
00153     
00154   /** Return a filter that will return the subset of cells for which
00155    * the given predicate is true */
00156   CellFilter subset(const CellPredicate& test) const ;
00157     
00158   /** Return a filter that will return the subset of cells for which
00159    * the given predicate is true */
00160   CellFilter subset(const RCP<CellPredicateFunctorBase>& test) const ;
00161 
00162   /** Return a compilation of all registered subsets of this filter */
00163   const Set<CellFilter>& knownSubsets() const ;
00164 
00165   /** Return a compilation of all filters registered as disjoint with
00166    * this filter */
00167   const Set<CellFilter>& knownDisjoints() const ;
00168 
00169   /** Indicate whether this filter is known to be a subset of
00170    * the specified filter. Note that a negative answer here does NOT
00171    * mean that it is not a subset, only that it can't be determined
00172    * to be one through structural properties alone. If this function
00173    * returns false, then to get a definitive answer one must do a test
00174    * using an actual realization on a mesh. */
00175   bool isKnownSubsetOf(const CellFilter& other) const ;
00176 
00177   /** Indicate whether this filter is known to be disjoint with
00178    * the specified filter. Note that a negative answer here does NOT
00179    * mean that it is not disjoint, only that it can't be determined
00180    * to be one through structural properties alone. If this function
00181    * returns false, then to get a definitive answer one must do a test
00182    * using an actual realization on a mesh. */
00183   bool isKnownDisjointWith(const CellFilter& other) const ;
00184 
00185   /** Do a brute-force check of whether this filter is a subset of
00186    * the specified filter. */
00187   bool isSubsetOf(const CellFilter& other, const Mesh& mesh) const ;
00188 
00189   /** Do a brute-force check of whether this filter is disjoint with
00190    * the specified filter. */
00191   bool isDisjointWith(const CellFilter& other, const Mesh& mesh) const ;
00192 
00193   /** Register a subset */
00194   void registerSubset(const CellFilter& sub) const ;
00195 
00196   /** Register a filter known to be disjoint */
00197   void registerDisjoint(const CellFilter& sub) const ;
00198 
00199   /** Register a labeled subset  */
00200   void registerLabeledSubset(int label, const CellFilter& sub) const ;
00201 
00202     
00203   /** Indicate whether this is a null cell filter */
00204   bool isNullCellFilter() const ;
00205 
00206 
00207   /** Determine whether all cells identified by this filter are
00208    * facets of cells identified by the other filter */
00209   bool areFacetsOf(const CellFilter& other, const Mesh& mesh) const ;
00210 
00211   /** Indicate whether this cell set is null */
00212   bool isNull() const ;
00213 
00214   /** */
00215   bool operator==(const CellFilter& other) const ;
00216 
00217   /** */
00218   bool operator!=(const CellFilter& other) const ;
00219     
00220 
00221   /** */
00222   XMLObject toXML() const ;
00223 
00224   /** */
00225   std::string toString() const ;
00226 
00227   /** */
00228   void setName(const std::string& name) ;
00229 
00230   /** */
00231   const CellFilterBase* cfbPtr() const ;
00232   /** */
00233   CellFilterBase* nonConstCfbPtr();
00234     
00235 private:
00236 
00237 };
00238 
00239 /** \relates CellFilter 
00240     \brief Create an array with one entry 
00241 */
00242 inline
00243 Array<CellFilter> List(const CellFilter& a)
00244 {
00245   Array<CellFilter> rtn(1, a);
00246   return rtn;
00247 }
00248 
00249 /** \relates CellFilter 
00250     \brief Create an array with two entries 
00251 */
00252 inline
00253 Array<CellFilter> List(const CellFilter& a, const CellFilter& b)
00254 {
00255   Array<CellFilter> rtn(2);
00256   rtn[0] = a;
00257   rtn[1] = b;
00258   return rtn;
00259 }
00260 
00261 /** \relates CellFilter 
00262     \brief Create an array with three entries 
00263 */
00264 inline
00265 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c)
00266 {
00267   Array<CellFilter> rtn(3);
00268   rtn[0] = a;
00269   rtn[1] = b;
00270   rtn[2] = c;
00271   return rtn;
00272 }
00273 
00274 /** \relates CellFilter 
00275     \brief Create an array with four entries 
00276 */
00277 inline
00278 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d)
00279 {
00280   Array<CellFilter> rtn(4);
00281   rtn[0] = a;
00282   rtn[1] = b;
00283   rtn[2] = c;
00284   rtn[3] = d;
00285   return rtn;
00286 }
00287 
00288 /** \relates CellFilter 
00289     \brief Create an array with five entries 
00290 */
00291 inline
00292 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e)
00293 {
00294   Array<CellFilter> rtn(5);
00295   rtn[0] = a;
00296   rtn[1] = b;
00297   rtn[2] = c;
00298   rtn[3] = d;
00299   rtn[4] = e;
00300   return rtn;
00301 }
00302 
00303 
00304 /** \relates CellFilter 
00305     \brief Create an array with six entries 
00306 */
00307 inline
00308 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00309   const CellFilter& f)
00310 {
00311   Array<CellFilter> rtn(6);
00312   rtn[0] = a;
00313   rtn[1] = b;
00314   rtn[2] = c;
00315   rtn[3] = d;
00316   rtn[4] = e;
00317   rtn[5] = f;
00318   return rtn;
00319 }
00320 
00321 /** \relates CellFilter 
00322     \brief Create an array with seven entries 
00323 */
00324 inline
00325 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00326   const CellFilter& f, const CellFilter& g)
00327 {
00328   Array<CellFilter> rtn(7);
00329   rtn[0] = a;
00330   rtn[1] = b;
00331   rtn[2] = c;
00332   rtn[3] = d;
00333   rtn[4] = e;
00334   rtn[5] = f;
00335   rtn[6] = g;
00336   return rtn;
00337 }
00338 
00339 /** \relates CellFilter 
00340     \brief Create an array with eight entries 
00341 */
00342 inline
00343 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00344   const CellFilter& f, const CellFilter& g, const CellFilter& h)
00345 {
00346   Array<CellFilter> rtn(8);
00347   rtn[0] = a;
00348   rtn[1] = b;
00349   rtn[2] = c;
00350   rtn[3] = d;
00351   rtn[4] = e;
00352   rtn[5] = f;
00353   rtn[6] = g;
00354   rtn[7] = h;
00355   return rtn;
00356 }
00357 
00358 /** \relates CellFilter 
00359     \brief Create an array with nine entries 
00360 */
00361 inline
00362 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00363   const CellFilter& f, const CellFilter& g, const CellFilter& h, const CellFilter& i)
00364 {
00365   Array<CellFilter> rtn(9);
00366   rtn[0] = a;
00367   rtn[1] = b;
00368   rtn[2] = c;
00369   rtn[3] = d;
00370   rtn[4] = e;
00371   rtn[5] = f;
00372   rtn[6] = g;
00373   rtn[7] = h;
00374   rtn[8] = i;
00375   return rtn;
00376 }
00377 
00378 
00379 /** \relates CellFilter 
00380     \brief Create an array with ten entries 
00381 */
00382 inline
00383 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00384   const CellFilter& f, const CellFilter& g, const CellFilter& h, const CellFilter& i, const CellFilter& j)
00385 {
00386   Array<CellFilter> rtn(10);
00387   rtn[0] = a;
00388   rtn[1] = b;
00389   rtn[2] = c;
00390   rtn[3] = d;
00391   rtn[4] = e;
00392   rtn[5] = f;
00393   rtn[6] = g;
00394   rtn[7] = h;
00395   rtn[8] = i;
00396   rtn[9] = j;
00397   return rtn;
00398 }
00399 
00400 /** \relates CellFilter */
00401 typedef Array<CellFilter> CellFilterArray;
00402 
00403 }
00404 
00405 namespace std
00406 {
00407 inline std::ostream& operator<<(std::ostream& os, const Sundance::CellFilter& f)
00408 {
00409   os << f.toString();
00410   return os;
00411 }
00412 }
00413 
00414 #endif

Site Contact