SundanceRivaraMesh.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 
00043 #include "SundanceRivaraMesh.hpp"
00044 #include "SundanceRivaraEdge.hpp"
00045 #include "SundanceRivaraElement.hpp"
00046 #include "SundanceRivaraNode.hpp"
00047 #include "Teuchos_StrUtils.hpp"
00048 #include <fstream>
00049 #include "Teuchos_TimeMonitor.hpp"
00050 #include "SundanceOut.hpp"
00051 
00052 using namespace Sundance::Rivara;
00053 using namespace Sundance;
00054 using Sundance::Map;
00055 
00056 using namespace Teuchos;
00057 using std::endl;
00058 
00059 
00060 
00061 
00062 static Time& refKernelTimer() 
00063 {
00064   static RCP<Time> rtn 
00065     = TimeMonitor::getNewTimer("mesh refinement kernel"); 
00066   return *rtn;
00067 }
00068 
00069 RivaraMesh::RivaraMesh(int dim, const MPIComm& comm)
00070   : spatialDim_(dim), nextGID_(0),
00071     nodes_(), edges_(), elements_(), nodeToEdgeMap_()
00072 {;}
00073 
00074 void RivaraMesh::refine()
00075 {
00076   TimeMonitor timer(refKernelTimer());
00077   while (refinementSet().size() > 0)
00078     {
00079       Element* next = refinementSet().top();
00080       refinementSet().pop();
00081       double maxArea = refinementAreas().top();
00082       refinementAreas().pop();
00083       next->refine(this, maxArea);
00084     }
00085 }
00086 
00087 int RivaraMesh::addNode(const RCP<Node>& node)
00088 {
00089   int lid = nodes_.length();
00090   node->setLocalIndex(lid);
00091   nodes_.append(node);
00092   nodeToEdgeMap_.append(Map<int, int>());
00093   nextGID()++;
00094   return lid;
00095 }
00096 
00097 
00098 int RivaraMesh::addVertex(
00099   int globalIndex, const Point& x, 
00100   int ownerProcID, int label)
00101 {
00102   RCP<Node> node = rcp(new Node(globalIndex, x, ownerProcID, label));
00103   return addNode(node);
00104 }
00105 
00106 void RivaraMesh::addElement(const RCP<Element>& tri)
00107 {
00108   elements_.append(tri);
00109 }
00110 
00111 
00112 int RivaraMesh::addElement(
00113   int globalIndex, 
00114   const Array<int>& vertexGIDs, 
00115   int ownerProc,
00116   int label)
00117 {
00118   int lid = elements_.size();
00119   RCP<Element> elem;
00120 
00121   switch(vertexGIDs.size())
00122   {
00123     case 3:
00124       elem = rcp(new Element(this, 
00125           nodes_[vertexGIDs[0]],
00126           nodes_[vertexGIDs[1]],
00127           nodes_[vertexGIDs[2]],
00128           ownerProc,label));
00129       break;
00130     case 4:
00131       elem = rcp(new Element(this, 
00132           nodes_[vertexGIDs[0]],
00133           nodes_[vertexGIDs[1]],
00134           nodes_[vertexGIDs[2]],
00135           nodes_[vertexGIDs[3]],
00136           ownerProc,label));
00137       break;
00138     default:
00139       TEUCHOS_TEST_FOR_EXCEPT(1);
00140   }
00141   elements_.append(elem);
00142   return lid;
00143   
00144 }
00145 
00146 RCP<Edge> RivaraMesh::tryEdge(const RCP<Node>& a,
00147                                           const RCP<Node>& b,
00148                                           int& edgeSign)
00149 {
00150   int i = a->localIndex();
00151   int j = b->localIndex();
00152 
00153   if (nodeToEdgeMap_[i].containsKey(j))
00154     {
00155       int k = nodeToEdgeMap_[i].get(j);
00156       edgeSign = 1;
00157       return edges_[k];
00158     }
00159   else if (nodeToEdgeMap_[j].containsKey(i))
00160     {
00161       int k = nodeToEdgeMap_[j].get(i);
00162       edgeSign = -1;
00163       return edges_[k];
00164     }
00165   else
00166     {
00167       RCP<Edge> rtn = rcp(new Edge(a,b));
00168       edgeSign = 1;
00169       int k = edges_.length();
00170       edges_.append(rtn);
00171       nodeToEdgeMap_[i].put(j, k);
00172       return rtn;
00173     }
00174 }
00175 
00176 
00177 RCP<Face> RivaraMesh::tryFace(
00178   const RCP<Node>& a,
00179   const RCP<Node>& b,
00180   const RCP<Node>& c)
00181 {
00182   FaceNodes f(a,b,c);
00183 
00184   int faceLID;
00185   if (faceToLIDMap_.containsKey(f))
00186   {
00187     faceLID = faceToLIDMap_[f];
00188   }
00189   else
00190   {
00191     faceLID = faces_.size();
00192     RCP<Face> newFace = rcp(new Face(a,b,c));
00193     faceToLIDMap_.put(newFace->nodes(), faceLID);
00194     faces_.append(newFace);
00195   }
00196   
00197   return faces_[faceLID];
00198 }
00199 
00200 
00201 
00202 const RCP<Face>& RivaraMesh::getFace(
00203   const RCP<Node>& a,
00204   const RCP<Node>& b,
00205   const RCP<Node>& c) const 
00206 {
00207   FaceNodes f(a,b,c);
00208   return faces_[faceToLIDMap_.get(f)];
00209 }
00210 
00211 
00212 
00213 int RivaraMesh::numElements() const 
00214 {
00215   int numLeaves = 0;
00216   for (int i=0; i<elements_.length(); i++)
00217     {
00218       numLeaves += elements_[i]->numLeaves();
00219     }
00220   return numLeaves;
00221 }
00222 
00223 int RivaraMesh::spatialDim() const
00224 {
00225   return spatialDim_;
00226 }
00227 
00228 

Site Contact