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

Site Contact