SwapHeavierToLighterNeighbours.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.2 $
00022 // $Date: 2003/02/14 23:00:58 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/loadBalancer/SwapHeavierToLighterNeighbours.cpp,v $
00024                                                                         
00025                                                                         
00026  // File: ~/domain/loadBalancer/HeavierToSmallerNeighbours.C
00027 // 
00028 // Written: fmk 
00029 // Created: Fri Aug 29 17:43:25 1997
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for 
00033 // HeavierToSmallerNeighbours. A HeavierToSmallerNeighbours is an object 
00034 // is used to partition a PartitionedDomain.
00035 //
00036 // What: "@(#) HeavierToSmallerNeighbours.C, revA"
00037 
00038 #include <SwapHeavierToLighterNeighbours.h>
00039 #include <Graph.h>
00040 #include <VertexIter.h>
00041 #include <Vertex.h>
00042 #include <ID.h> 
00043 
00044 
00045 SwapHeavierToLighterNeighbours::SwapHeavierToLighterNeighbours()
00046  :numReleases(1), factorGreater(1.0)
00047 {
00048 
00049 }
00050 
00051 SwapHeavierToLighterNeighbours::
00052 SwapHeavierToLighterNeighbours(double factGreater, 
00053                                int releases)
00054  :numReleases(releases),factorGreater(factGreater)
00055 {
00056     if (releases < 1)
00057         numReleases = 1;
00058 }
00059 
00060 
00061 SwapHeavierToLighterNeighbours::~SwapHeavierToLighterNeighbours()
00062 {
00063     
00064 }
00065 
00066 int
00067 SwapHeavierToLighterNeighbours::balance(Graph &theWeightedGraph)
00068 {
00069     // check to see a domain partitioner has been set
00070     DomainPartitioner *thePartitioner = this->getDomainPartitioner();
00071     if (thePartitioner == 0) {
00072         opserr << "SwapHeavierToLighterNeighbours::balance";
00073         opserr << "- No DomainPartitioner has been set\n"; 
00074         return -1;
00075     }
00076 
00077     int res = 0;
00078 
00079     for (int ii=0; ii<numReleases; ii++) {
00080         VertexIter &theVertices = theWeightedGraph.getVertices();
00081         Vertex *vertexPtr;
00082         while ((vertexPtr = theVertices()) != 0) {
00083             int vertexTag = vertexPtr->getTag();
00084             double vertexLoad = vertexPtr->getWeight();
00085             const ID &adjacency = vertexPtr->getAdjacency();
00086             int size = adjacency.Size();
00087             for (int j=0; j<size; j++) {
00088                 int otherVertexTag = adjacency(j);
00089                 Vertex *otherVertexPtr 
00090                     = theWeightedGraph.getVertexPtr(otherVertexTag);
00091                 double otherVertexLoad = otherVertexPtr->getWeight();
00092                 
00093                 if (vertexLoad > otherVertexLoad && otherVertexLoad != 0) 
00094                     if (vertexLoad/otherVertexLoad > factorGreater) {
00095                         res = thePartitioner->
00096                             swapBoundary(vertexTag,otherVertexTag);
00097                         if (res < 0) {
00098                             opserr << "WARNING SwapHeavierToLighterNeighbours";
00099                             opserr << "::balance - DomainPartitioner returned ";
00100                             opserr << res << endln;
00101                             return res;
00102                         }
00103                     }
00104                 
00105                 if (vertexLoad != 0 && otherVertexLoad == 0)  {
00106                     res = thePartitioner->
00107                         swapBoundary(vertexTag,otherVertexTag); 
00108                     if (res < 0) {
00109                         opserr << "WARNING SwapHeavierToLighterNeighbours";
00110                         opserr << "::balance - DomainPartitioner returned ";
00111                         opserr << res << endln;
00112                         return res;
00113                     }
00114                 }
00115             }           
00116         }
00117     }
00118 
00119 
00120     return res;
00121 
00122 }

Generated on Mon Oct 23 15:05:01 2006 for OpenSees by doxygen 1.5.0