Zoltan2 Version of the Day
Zoltan2_MeshInput.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 //
00003 // ***********************************************************************
00004 //
00005 //   Zoltan2: A package of combinatorial algorithms for scientific computing
00006 //                  Copyright 2012 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Vitus Leung (vjleung@sandia.gov)
00039 //
00040 // ***********************************************************************
00041 //
00042 // @HEADER
00043 
00049 #ifndef _ZOLTAN2_MESHADAPTER_HPP_
00050 #define _ZOLTAN2_MESHADAPTER_HPP_
00051 
00052 #include <Zoltan2_Adapter.hpp>
00053 
00054 #include <string>
00055 
00056 namespace Zoltan2 {
00057 
00058 enum MeshEntityType {
00059   MESH_REGION,
00060   MESH_FACE,
00061   MESH_EDGE,
00062   MESH_VERTEX
00063 };
00100 template <typename User>
00101   class MeshAdapter : public BaseAdapter {
00102 private:
00103   enum MeshEntityType primaryEntityType; // Entity to be partitioned, ordered,
00104                                          // colored, matched, etc.
00105   enum MeshEntityType adjacencyEntityType; // Entity describing adjacencies
00106   //KDD Do we need a 2nd-adjacency Entity Type to use as "through"?
00107 
00108 public:
00109 
00110 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00111   typedef typename InputTraits<User>::scalar_t    scalar_t;
00112   typedef typename InputTraits<User>::lno_t    lno_t;
00113   typedef typename InputTraits<User>::gno_t    gno_t;
00114   typedef typename InputTraits<User>::gid_t    gid_t;
00115   typedef typename InputTraits<User>::node_t   node_t;
00116   typedef User user_t;
00117   typedef User userCoord_t;
00118 #endif
00119 
00120   enum BaseAdapterType adapterType() const {return MeshAdapterType;}
00121 
00122   // Default MeshEntityType is MESH_REGION with MESH_FACE-based adjacencies
00123   MeshAdapter() : primaryEntityType(MESH_REGION),
00124                   adjacencyEntityType(MESH_FACE) {};
00125 
00128   virtual ~MeshAdapter() {};
00129 
00132   virtual size_t getLocalNumOf(MeshEntityType etype) const = 0;
00133 
00134 
00139   virtual void getIDsViewOf(MeshEntityType etype,
00140                             gid_t const *&Ids) const = 0;
00141 
00142 
00148   virtual int getNumWeightsPerOf(MeshEntityType etype) const { return 0; }
00149 
00165   virtual void getWeightsViewOf(MeshEntityType etype,
00166      const scalar_t *&weights, int &stride, int idx = 0) const
00167   {
00168     weights = NULL;
00169     stride = 0;
00170     Z2_THROW_NOT_IMPLEMENTED_ERROR
00171   }
00172 
00173 
00182 //KDD Assumed uniform dimension of all entity types in other adapters.
00183 //KDD Should we do the same here?
00184   virtual int getDimensionOf(MeshEntityType etype) const { return 0; }
00185 
00196   virtual void getCoordinatesViewOf(MeshEntityType etype,
00197     const scalar_t *&coords, int &stride, int coordDim) const 
00198   {
00199     coords = NULL;
00200     stride = 0;
00201     Z2_THROW_NOT_IMPLEMENTED_ERROR
00202   }
00203 
00204 
00207   virtual bool availAdjs(MeshEntityType source, MeshEntityType target);
00208 
00209 
00212   virtual size_t getLocalNumAdjs(MeshEntityType source,
00213                                  MeshEntityType target) const { return 0;}
00214 
00215 
00226 //KDD Since the source objects are assumed to be gotten from getIDsViewOf(),
00227 //KDD is the source MeshEntityType understood here?
00228 //KDD What about the target?
00229   virtual void getAdjsView(MeshEntityType source, MeshEntityType target,
00230      const lno_t *&offsets, const gid_t *& adjacencyIds) const 
00231   {
00232     offsets = NULL;
00233     adjacencyIds = NULL;
00234     Z2_THROW_NOT_IMPLEMENTED_ERROR
00235   }
00236 
00237 
00240   virtual bool avail2ndAdjs(MeshEntityType sourcetarget, MeshEntityType through);
00241 
00242 
00250   virtual size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget,
00251                                     MeshEntityType through) const { return 0; }
00252 
00263 // TODO:  Later may allow user to not implement second adjacencies and, if we want them,
00264 // TODO:  we compute A^T A, where A is matrix of first adjacencies.
00265 //KDD Since the source objects are assumed to be gotten from getIDsViewOf(),
00266 //KDD is the sourcetarget MeshEntityType understood here?
00267 //KDD What about the through MeshEntityType?
00268   virtual void get2ndAdjsView(MeshEntityType sourcetarget,
00269      MeshEntityType through, const lno_t *&offsets,
00270      const gid_t *& adjacencyIds) const
00271   {
00272     offsets = NULL;
00273     adjacencyIds = NULL;
00274     Z2_THROW_NOT_IMPLEMENTED_ERROR
00275   }
00276 
00277 
00280   virtual int getNumWeightsPer2ndAdj(MeshEntityType sourcetarget,
00281                                      MeshEntityType through) const { return 0;}
00282 
00283 
00292 //KDD Since the source objects are assumed to be gotten from getIDsViewOf(),
00293 //KDD is the sourcetarget MeshEntityType understood here?
00294 //KDD What about the through MeshEntityType?
00295   virtual void get2ndAdjWeightsView(MeshEntityType sourcetarget,
00296      MeshEntityType through, const scalar_t *&weights, int &stride,
00297      int idx) const
00298   {
00299     weights = NULL;
00300     stride = 0;
00301     Z2_THROW_NOT_IMPLEMENTED_ERROR
00302   }
00303 
00304 //KDD What if we wanted to provide weights with respect to first adjacencies?
00305 //KDD Should we add functions for that?
00306 
00307 
00309   // Implementations of base-class methods
00310 
00313   inline enum MeshEntityType getPrimaryEntityType() const {
00314     return this->primaryEntityType;
00315   }
00316 
00322   void setPrimaryEntityType(string typestr) {
00323     if (typestr == "region")
00324       this->primaryEntityType = MESH_REGION;
00325     else if (typestr == "face")
00326       this->primaryEntityType = MESH_FACE;
00327     else if (typestr == "edge")
00328       this->primaryEntityType = MESH_EDGE;
00329     else if (typestr == "vertex")
00330       this->primaryEntityType = MESH_VERTEX;
00331     else {
00332       std::ostringstream emsg;
00333       emsg << __FILE__ << "," << __LINE__
00334            << " error:  Invalid MeshEntityType " << typestr << std::endl;
00335       emsg << "Valid values: region  face  edge  vertex" << std::endl;
00336       throw std::runtime_error(emsg.str());
00337     }
00338   }
00339 
00346   inline enum MeshEntityType getAdjacencyEntityType() const {
00347     return this->adjacencyEntityType;
00348   }
00349 
00356   void setAdjacencyEntityType(string typestr) {
00357     if (typestr == "region")
00358       this->adjacencyEntityType = MESH_REGION;
00359     else if (typestr == "face")
00360       this->adjacencyEntityType = MESH_FACE;
00361     else if (typestr == "edge")
00362       this->adjacencyEntityType = MESH_EDGE;
00363     else if (typestr == "vertex")
00364       this->adjacencyEntityType = MESH_VERTEX;
00365     else {
00366       std::ostringstream emsg;
00367       emsg << __FILE__ << "," << __LINE__
00368            << " error:  Invalid MeshEntityType " << typestr << std::endl;
00369       emsg << "Valid values: region  face  edge  vertex" << std::endl;
00370       throw std::runtime_error(emsg.str());
00371     }
00372   }
00373 
00374   // Functions from the BaseAdapter interface
00375   size_t getLocalNumIDs() const {
00376     return getLocalNumOf(getPrimaryEntityType());
00377   }
00378 
00379   void getIDsView(const gid_t *&Ids) const {
00380     getIDsViewOf(getPrimaryEntityType(), Ids);
00381   }
00382 
00383   int getNumWeightsPerID() const {
00384     return getNumWeightsPerOf(getPrimaryEntityType());
00385   }
00386 
00387   void getWeightsView(const scalar_t *&wgt, int &stride, int idx = 0) const {
00388     getWeightsViewOf(getPrimaryEntityType(), wgt, stride, idx);
00389   }
00390 
00391 };
00392 
00393 }  //namespace Zoltan2
00394 
00395 #endif