SundanceCFMeshPair.cpp
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 #include "SundanceCFMeshPair.hpp"
00043 #include "PlayaTabs.hpp"
00044 #include "SundanceExplicitCellSet.hpp"
00045 #include "SundanceBinaryCellFilter.hpp"
00046 #include "SundanceSubsetCellFilter.hpp"
00047 #include "SundanceLabelCellPredicate.hpp"
00048 #include "SundanceNullCellFilterStub.hpp"
00049 #include "SundanceNullCellFilter.hpp"
00050 
00051 #include "Teuchos_Time.hpp"
00052 #include "Teuchos_TimeMonitor.hpp"
00053 
00054 using namespace Sundance;
00055 using namespace Sundance;
00056 using namespace Sundance;
00057 using namespace Teuchos;
00058 
00059 
00060 static Time& csPartitionTimer() 
00061 {
00062   static RCP<Time> rtn 
00063     = TimeMonitor::getNewTimer("cell set partitioning"); 
00064   return *rtn;
00065 }
00066 
00067 
00068 CFMeshPair::CFMeshPair()
00069   : filter_(),
00070     mesh_(),
00071     cellSet_(),
00072     funcs_()
00073 {}
00074 
00075 CFMeshPair::CFMeshPair(const CellFilter& cf,
00076                        const Mesh& mesh,
00077                        const Set<int>& funcs)
00078   : filter_(cf),
00079     mesh_(mesh),
00080     cellSet_(),
00081     funcs_(funcs)
00082 {
00083   if (filter_.ptr().get() != 0) cellSet_ = filter_.getCells(mesh);
00084 }
00085 
00086 bool CFMeshPair::operator<(const CFMeshPair& other) const
00087 {
00088   if (isEmpty()) return true;
00089   if (other.isEmpty()) return false;
00090 
00091   TEUCHOS_TEST_FOR_EXCEPTION(mesh_.id() != other.mesh_.id(),
00092                      std::runtime_error,
00093                      "mismatched meshes!");
00094 
00095   return cellSet_ < other.cellSet_;
00096 }
00097 
00098 bool CFMeshPair::isEmpty() const
00099 {
00100   return filter_.ptr().get() == 0 
00101     || cellSet_.ptr().get() == 0
00102     || cellSet_.begin()==cellSet_.end();
00103 }
00104 
00105 CFMeshPair CFMeshPair::setMinus(const CFMeshPair& other) const
00106 {
00107 
00108   if (isEmpty()) return CFMeshPair();
00109   if (other.isEmpty()) return *this;
00110 
00111   TEUCHOS_TEST_FOR_EXCEPTION(mesh().id() != other.mesh().id(),
00112                      std::runtime_error,
00113                      "mismatched meshes!");
00114 
00115   CellFilter diff = filter() - other.filter();
00116   return CFMeshPair(diff, mesh(), funcs_);
00117 }
00118 
00119 CFMeshPair CFMeshPair::intersection(const CFMeshPair& other) const
00120 {
00121   if (isEmpty() || other.isEmpty()) return CFMeshPair();
00122 
00123   TEUCHOS_TEST_FOR_EXCEPTION(mesh().id() != other.mesh().id(),
00124                      std::runtime_error,
00125                      "mismatched meshes!");
00126 
00127   CellFilter inter = filter().intersection(other.filter());
00128 
00129   return CFMeshPair(inter, mesh(), funcs_.setUnion(other.funcs_));
00130 }
00131 
00132 
00133 namespace Sundance
00134 {
00135   Array<CFMeshPair> resolvePair(const CFMeshPair& a, 
00136                                 const CFMeshPair& b)
00137   {
00138     Tabs tab0;
00139 
00140     CFMeshPair inter = a.intersection(b);
00141     CFMeshPair aMinusB = a.setMinus(b);
00142     CFMeshPair bMinusA = b.setMinus(a);
00143 
00144     return tuple(bMinusA, inter, aMinusB);
00145   }
00146 
00147   
00148   Array<CFMeshPair> resolveSets(const Array<CFMeshPair>& s)
00149   {
00150 
00151     if (s.size() == 1) return s;
00152 
00153     Array<CFMeshPair> T = tuple(s[0]);
00154     
00155     for (int i=0; i<s.size(); i++)
00156       {
00157         CFMeshPair A = s[i];
00158         Array<CFMeshPair> TN;
00159         for (int j=0; j<T.size(); j++)
00160           {
00161             Array<CFMeshPair> p = resolvePair(A, T[j]);
00162             if (!p[0].isEmpty())
00163               {
00164                 TN.append(p[0]);
00165               }
00166             if (!p[1].isEmpty())
00167               {
00168                 TN.append(p[1]);
00169               }
00170             A = p[2];
00171           }
00172         if (!A.isEmpty())
00173           {
00174             TN.append(A);
00175           }
00176         T = TN;
00177       }
00178     return T;
00179   }
00180 
00181 
00182   Array<CFMeshPair>
00183   findDisjointFilters(const Array<CellFilter>& filters,
00184                       const Array<Set<int> >& funcs,
00185                       const Mesh& mesh)
00186   {
00187     TimeMonitor timer(csPartitionTimer() );
00188     Array<CFMeshPair> cf(filters.size());
00189 
00190     TEUCHOS_TEST_FOR_EXCEPT(filters.size() != funcs.size());
00191     for (int i=0; i<filters.size(); i++)
00192       {
00193         cf[i] = CFMeshPair(filters[i], mesh, funcs[i]);
00194       }
00195     return resolveSets(cf);
00196   }
00197 
00198 }

Site Contact