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 "PlayaHandle.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   /** Return a filter that will return the subset of cells having
00154    * any one of the given labels */
00155   CellFilter labeledSubset(const Array<int>& labels) const ;
00156 
00157   /** Return a filter that will return the subset of cells for which
00158    * the dir-th coordinate takes on value coordVal */
00159   CellFilter coordSubset(int dir, const double& coordVal) const ;
00160 
00161     
00162   /** Return a filter that will return the subset of cells for which
00163    * the given predicate is true */
00164   CellFilter subset(const CellPredicate& test) const ;
00165     
00166   /** Return a filter that will return the subset of cells for which
00167    * the given predicate is true */
00168   CellFilter subset(const RCP<CellPredicateFunctorBase>& test) const ;
00169 
00170   /** Return a compilation of all registered subsets of this filter */
00171   const Set<CellFilter>& knownSubsets() const ;
00172 
00173   /** Return a compilation of all filters registered as disjoint with
00174    * this filter */
00175   const Set<CellFilter>& knownDisjoints() const ;
00176 
00177   /** Indicate whether this filter is known to be a subset of
00178    * the specified filter. Note that a negative answer here does NOT
00179    * mean that it is not a subset, 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 isKnownSubsetOf(const CellFilter& other) const ;
00184 
00185   /** Indicate whether this filter is known to be disjoint with
00186    * the specified filter. Note that a negative answer here does NOT
00187    * mean that it is not disjoint, only that it can't be determined
00188    * to be one through structural properties alone. If this function
00189    * returns false, then to get a definitive answer one must do a test
00190    * using an actual realization on a mesh. */
00191   bool isKnownDisjointWith(const CellFilter& other) const ;
00192 
00193   /** Do a brute-force check of whether this filter is a subset of
00194    * the specified filter. */
00195   bool isSubsetOf(const CellFilter& other, const Mesh& mesh) const ;
00196 
00197   /** Do a brute-force check of whether this filter is disjoint with
00198    * the specified filter. */
00199   bool isDisjointWith(const CellFilter& other, const Mesh& mesh) const ;
00200 
00201   /** Register a subset */
00202   void registerSubset(const CellFilter& sub) const ;
00203 
00204   /** Register a filter known to be disjoint */
00205   void registerDisjoint(const CellFilter& sub) const ;
00206 
00207   /** Register a labeled subset  */
00208   void registerLabeledSubset(const Set<int>& label, const CellFilter& sub) const ;
00209 
00210     
00211   /** Indicate whether this is a null cell filter */
00212   bool isNullCellFilter() const ;
00213 
00214 
00215   /** Determine whether all cells identified by this filter are
00216    * facets of cells identified by the other filter */
00217   bool areFacetsOf(const CellFilter& other, const Mesh& mesh) const ;
00218 
00219   /** Indicate whether this cell set is null */
00220   bool isNull() const ;
00221 
00222   /** */
00223   bool operator==(const CellFilter& other) const ;
00224 
00225   /** */
00226   bool operator!=(const CellFilter& other) const ;
00227     
00228 
00229   /** */
00230   XMLObject toXML() const ;
00231 
00232   /** */
00233   std::string toString() const ;
00234 
00235   /** */
00236   void setName(const std::string& name) ;
00237 
00238   /** */
00239   const CellFilterBase* cfbPtr() const ;
00240   /** */
00241   CellFilterBase* nonConstCfbPtr();
00242     
00243 private:
00244 
00245 };
00246 
00247 /** \relates CellFilter 
00248     \brief Create an array with one entry 
00249 */
00250 inline
00251 Array<CellFilter> List(const CellFilter& a)
00252 {
00253   Array<CellFilter> rtn(1, a);
00254   return rtn;
00255 }
00256 
00257 /** \relates CellFilter 
00258     \brief Create an array with two entries 
00259 */
00260 inline
00261 Array<CellFilter> List(const CellFilter& a, const CellFilter& b)
00262 {
00263   Array<CellFilter> rtn(2);
00264   rtn[0] = a;
00265   rtn[1] = b;
00266   return rtn;
00267 }
00268 
00269 /** \relates CellFilter 
00270     \brief Create an array with three entries 
00271 */
00272 inline
00273 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c)
00274 {
00275   Array<CellFilter> rtn(3);
00276   rtn[0] = a;
00277   rtn[1] = b;
00278   rtn[2] = c;
00279   return rtn;
00280 }
00281 
00282 /** \relates CellFilter 
00283     \brief Create an array with four entries 
00284 */
00285 inline
00286 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d)
00287 {
00288   Array<CellFilter> rtn(4);
00289   rtn[0] = a;
00290   rtn[1] = b;
00291   rtn[2] = c;
00292   rtn[3] = d;
00293   return rtn;
00294 }
00295 
00296 /** \relates CellFilter 
00297     \brief Create an array with five entries 
00298 */
00299 inline
00300 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e)
00301 {
00302   Array<CellFilter> rtn(5);
00303   rtn[0] = a;
00304   rtn[1] = b;
00305   rtn[2] = c;
00306   rtn[3] = d;
00307   rtn[4] = e;
00308   return rtn;
00309 }
00310 
00311 
00312 /** \relates CellFilter 
00313     \brief Create an array with six entries 
00314 */
00315 inline
00316 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00317   const CellFilter& f)
00318 {
00319   Array<CellFilter> rtn(6);
00320   rtn[0] = a;
00321   rtn[1] = b;
00322   rtn[2] = c;
00323   rtn[3] = d;
00324   rtn[4] = e;
00325   rtn[5] = f;
00326   return rtn;
00327 }
00328 
00329 /** \relates CellFilter 
00330     \brief Create an array with seven entries 
00331 */
00332 inline
00333 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00334   const CellFilter& f, const CellFilter& g)
00335 {
00336   Array<CellFilter> rtn(7);
00337   rtn[0] = a;
00338   rtn[1] = b;
00339   rtn[2] = c;
00340   rtn[3] = d;
00341   rtn[4] = e;
00342   rtn[5] = f;
00343   rtn[6] = g;
00344   return rtn;
00345 }
00346 
00347 /** \relates CellFilter 
00348     \brief Create an array with eight entries 
00349 */
00350 inline
00351 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00352   const CellFilter& f, const CellFilter& g, const CellFilter& h)
00353 {
00354   Array<CellFilter> rtn(8);
00355   rtn[0] = a;
00356   rtn[1] = b;
00357   rtn[2] = c;
00358   rtn[3] = d;
00359   rtn[4] = e;
00360   rtn[5] = f;
00361   rtn[6] = g;
00362   rtn[7] = h;
00363   return rtn;
00364 }
00365 
00366 /** \relates CellFilter 
00367     \brief Create an array with nine entries 
00368 */
00369 inline
00370 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00371   const CellFilter& f, const CellFilter& g, const CellFilter& h, const CellFilter& i)
00372 {
00373   Array<CellFilter> rtn(9);
00374   rtn[0] = a;
00375   rtn[1] = b;
00376   rtn[2] = c;
00377   rtn[3] = d;
00378   rtn[4] = e;
00379   rtn[5] = f;
00380   rtn[6] = g;
00381   rtn[7] = h;
00382   rtn[8] = i;
00383   return rtn;
00384 }
00385 
00386 
00387 /** \relates CellFilter 
00388     \brief Create an array with ten entries 
00389 */
00390 inline
00391 Array<CellFilter> List(const CellFilter& a, const CellFilter& b, const CellFilter& c, const CellFilter& d, const CellFilter& e,
00392   const CellFilter& f, const CellFilter& g, const CellFilter& h, const CellFilter& i, const CellFilter& j)
00393 {
00394   Array<CellFilter> rtn(10);
00395   rtn[0] = a;
00396   rtn[1] = b;
00397   rtn[2] = c;
00398   rtn[3] = d;
00399   rtn[4] = e;
00400   rtn[5] = f;
00401   rtn[6] = g;
00402   rtn[7] = h;
00403   rtn[8] = i;
00404   rtn[9] = j;
00405   return rtn;
00406 }
00407 
00408 /** \relates CellFilter */
00409 typedef Array<CellFilter> CellFilterArray;
00410 
00411 }
00412 
00413 namespace std
00414 {
00415 inline std::ostream& operator<<(std::ostream& os, const Sundance::CellFilter& f)
00416 {
00417   os << f.toString();
00418   return os;
00419 }
00420 }
00421 
00422 #endif

Site Contact