SundanceRivaraEdge.cpp
Go to the documentation of this file.
00001 #include "SundanceRivaraEdge.hpp"
00002 #include "SundanceRivaraElement.hpp"
00003 #include "SundanceRivaraNode.hpp"
00004 #include "SundanceRivaraMesh.hpp"
00005 
00006 using namespace Sundance::Rivara;
00007 using namespace Teuchos;
00008 
00009 
00010 
00011 Edge::Edge(const RCP<Node>& a,
00012            const RCP<Node>& b)
00013   : label_(-1),nodes_(tuple(a,b)), elements_(), midpoint_(),
00014     ownerProc_()
00015 {
00016   if (a->ownerProc() > b->ownerProc())
00017     {
00018       ownerProc_ = a->ownerProc();
00019     }
00020   else
00021     {
00022       ownerProc_ = b->ownerProc();
00023     }
00024 }
00025 
00026 void Edge::addConnectingElement(Element* tri)
00027 {
00028   elements_.append(tri);
00029 }
00030 
00031 double Edge::length() const 
00032 {
00033   const Point& x1 = nodes_[0]->pt();
00034   const Point& x2 = nodes_[1]->pt();
00035 
00036   return sqrt((x1-x2)*(x1-x2));
00037 }
00038 
00039 void Edge::getUnrefinedCofacets(Array<Element*>& c) const 
00040 {
00041   for (int i=0; i<elements_.length(); i++)
00042     {
00043       if (!elements_[i]->hasChildren()) c.append(elements_[i]);
00044     }
00045 }
00046 
00047 RCP<Node> Edge::bisect(RivaraMesh* mesh)
00048 {
00049   /* if we've already been bisected, return the existing midpoint node */
00050   if (!(midpoint_.get() == 0))
00051     {
00052       return midpoint_;
00053     }
00054 
00055   const Point& x1 = nodes_[0]->pt();
00056   const Point& x2 = nodes_[1]->pt();
00057 
00058   int nextGID = mesh->nextGID();
00059   midpoint_ = rcp(new Node(nextGID, 0.5*(x1 + x2), ownerProc_));
00060   mesh->addNode(midpoint_);
00061 
00062   int s;
00063   RCP<Edge> sub1 = mesh->tryEdge(nodes_[0], midpoint_, s);
00064   RCP<Edge> sub2 = mesh->tryEdge(midpoint_, nodes_[1], s);
00065   sub1->setParent(this);
00066   sub2->setParent(this);
00067 
00068   sub1->setLabel(label_);
00069   sub2->setLabel(label_);
00070 
00071   setChildren(sub1.get(), sub2.get());
00072 
00073   return midpoint_;
00074 }
00075 

Site Contact