example.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.1 $
00022 // $Date: 2006/04/13 20:58:45 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/system_of_eqn/linearSOE/mumps/example.cpp,v $
00024 
00025 #include <Matrix.h>
00026 #include <Vector.h>
00027 #include <ID.h>
00028 #include <MumpsParallelSOE.h>
00029 #include <MumpsParallelSolver.h>
00030 #include <MPI_Channel.h>
00031 #include <FEM_ObjectBroker.h>
00032 #include <Graph.h>
00033 #include <Vertex.h>
00034 
00035 // init the global variabled defined in OPS_Globals.h
00036 #include <OPS_Globals.h>
00037 #include <StandardStream.h>
00038 #include <mpi.h>
00039 
00040 StandardStream sserr;
00041 OPS_Stream *opserrPtr = &sserr;
00042  
00043 double        ops_Dt = 0;
00044 Domain       *ops_TheActiveDomain = 0;
00045 Element      *ops_TheActiveElement = 0;
00046 
00047 int main(int argc, char ** argv)
00048 {
00049   int ierr, rank, np;
00050   int soeType =2;  // 0 - unsymmetric, 1 - symmetric positive definite, 2 - symmetric
00051   ierr = MPI_Init(&argc, &argv);
00052   ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00053   ierr = MPI_Comm_size(MPI_COMM_WORLD, &np);
00054 
00055   ID *myID = 0;
00056   FEM_ObjectBroker theBroker;
00057   MumpsParallelSolver *theSolver = new MumpsParallelSolver();
00058   MumpsParallelSOE *theSOE = new MumpsParallelSOE(*theSolver, soeType);
00059 
00060   if (rank == 0) {
00061     for (int i=1; i<np; i++) {
00062       MPI_Channel *theChannel = new MPI_Channel(i);
00063       theSOE->sendSelf(0, *theChannel);
00064     }
00065     myID = new ID(6);
00066     Graph graph;
00067     for (int i=0; i<6; i++) {
00068       Vertex *vertex = new Vertex(i, i);
00069       graph.addVertex(vertex);
00070       (*myID)(i) = i;
00071     }
00072 
00073     Matrix a(6,6);
00074     a.Zero();
00075     a(0,0) = 4169.95/np;
00076     a(1,0) = 0.0;
00077     a(2,0) = 10075/np;
00078     a(3,0) = -4030.0;
00079     a(4,0) = 0.0;
00080     a(5,0) = 0.0;
00081     a(1,1) = 10084/np;
00082     a(2,1) = -1612/np;
00083     a(3,1) = 0.0;
00084     a(4,1) = -8.9556;
00085     a(5,1) = -1612;
00086     a(2,2) = 1354080.0/np;
00087     a(3,2) = 0.0;
00088     a(4,2) = 1612;
00089     a(5,2) = 193440.0;
00090     a(3,3) = 4169.93;
00091     a(4,3) = 0.0;
00092     a(5,3) = 10075;
00093     a(4,4) = 10084;
00094     a(5,4) = 1612;
00095     a(5,5) = 1354000.0;
00096 
00097     Vector b(6);
00098     b += 2.0;
00099 
00100     for (int i=0; i<6; i++)
00101       for (int j=i+1; j<6; j++) {
00102         graph.addEdge(i,j);
00103         a(i,j) = a(j,i);
00104       }
00105 
00106     theSOE->setSize(graph);
00107     theSOE->zeroA();
00108     theSOE->zeroB();
00109     theSOE->addA(a, *myID);
00110     theSOE->addB(b, *myID);
00111 
00112   } else {
00113 
00114     MPI_Channel *theChannel = new MPI_Channel(0);
00115     theSOE->recvSelf(0, *theChannel, theBroker);
00116 
00117     myID = new ID(3);
00118     Graph graph;
00119     for (int i=0; i<3; i++) {
00120       Vertex *vertex = new Vertex(i, i);
00121       graph.addVertex(vertex);
00122       (*myID)(i) = i;
00123     }
00124 
00125     Matrix a(3,3);
00126     Vector b(3);
00127     a(0,0) = 4169.95/np;
00128     a(1,0) = 0.0;
00129     a(2,0) = 10075.0/np;
00130     a(1,1) = 10084.0/np;
00131     a(2,1) = -1612.0/np;
00132     a(2,2) = 1354080.0/np;
00133 
00134 
00135     for (int i=0; i<3; i++)
00136       for (int j=i+1; j<3; j++) {
00137         graph.addEdge(i,j);
00138         a(i,j) = a(j,i);
00139       }
00140 
00141     theSOE->setSize(graph);
00142     theSOE->zeroA();
00143     theSOE->zeroB();
00144     theSOE->addA(a, *myID);
00145     theSOE->addB(b, *myID);
00146   }
00147 
00148   Matrix a(6,6);
00149   a.Zero();
00150   a(0,0) = 4169.95;
00151   a(1,0) = 0.0;
00152   a(2,0) = 10075;
00153   a(3,0) = -4030.0;
00154   a(4,0) = 0.0;
00155   a(5,0) = 0.0;
00156   a(1,1) = 10084;
00157   a(2,1) = -1612;
00158   a(3,1) = 0.0;
00159   a(4,1) = -8.9556;
00160   a(5,1) = -1612;
00161   a(2,2) = 1354080.0;
00162   a(3,2) = 0.0;
00163   a(4,2) = 1612;
00164   a(5,2) = 193440.0;
00165   a(3,3) = 4169.93;
00166   a(4,3) = 0.0;
00167   a(5,3) = 10075;
00168   a(4,4) = 10084;
00169   a(5,4) = 1612;
00170   a(5,5) = 1354000.0;
00171   for (int i=0; i<6; i++)
00172     for (int j=i+1; j<6; j++) 
00173       a(i,j) = a(j,i);
00174   
00175   
00176 
00177   Vector b(6),x(6);
00178 
00179   b= theSOE->getB();  
00180   theSOE->solve();
00181   x = theSOE->getX();
00182   
00183   if (rank == np-1) {
00184     opserr << "A:\n";
00185     opserr << "B:\n" << b;
00186     opserr << "X:\n " << x;
00187     opserr << "A*X:\n" << a*x;
00188   }
00189   
00190   theSOE->zeroB();
00191   if (rank == 0) {
00192     Vector b(6);
00193     b += 2.0/np;
00194     theSOE->addB(b, *myID);
00195   } else {
00196     Vector b(3);
00197     b += 2.0/np;
00198     theSOE->addB(b, *myID);
00199   }
00200 
00201   b= theSOE->getB();  
00202   theSOE->solve();
00203   x = theSOE->getX();  
00204 
00205   if (rank == np-1) {
00206     opserr << "A:\n";
00207     opserr << "B:\n" << b;
00208     opserr << "X:\n " << x;
00209     opserr << "A*X:\n" << a*x;
00210   }
00211 
00212   delete theSOE;
00213 
00214   MPI_Finalize();
00215   return 0;
00216 }

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