main.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.3 $
00022 // $Date: 2006/01/12 23:59:07 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/system_of_eqn/linearSOE/petsc/main.cpp,v $
00024                                                                         
00025                                                                         
00026 
00027 #include <Matrix.h>
00028 #include <Vector.h>
00029 #include <ID.h>
00030 //#include <PetscSOE.h>
00031 //#include <PetscSolver.h>
00032 #include <PetscSOE.h>
00033 #include <PetscSolver.h>
00034 #include <Graph.h>
00035 #include <Vertex.h>
00036 #include <SuperLU.h>
00037 #include <SparseGenColLinSOE.h>
00038 #include <PetscSparseSeqSolver.h>
00039 #include <SparseGenRowLinSOE.h>
00040 
00041 // init the global variabled defined in OPS_Globals.h
00042 #include <OPS_Globals.h>
00043 #include <StandardStream.h>
00044 
00045 StandardStream sserr;
00046 OPS_Stream *opserrPtr = &sserr;
00047  
00048 double        ops_Dt = 0;
00049 Domain       *ops_TheActiveDomain = 0;
00050 Element      *ops_TheActiveElement = 0;
00051 
00052 main() 
00053 {
00054     Matrix a(2,2);
00055     a(0,0) = 2.0;
00056     a(0,1) = 1.0;
00057     a(1,0) = 1.0;
00058     a(1,1) = 2.0;
00059     
00060     Matrix b(1,1);
00061     b(0,0) = 10;
00062     
00063     Matrix c(3,3);
00064     c(0,0) = 9.0;
00065     c(0,1) = 2.0;
00066     c(0,2) = 2.0;
00067     c(2,0) = 2.0;
00068     c(2,1) = 2.0;
00069     c(2,2) = 9.0;
00070     c(1,0) = 2.0;
00071     c(1,1) = 9.0;
00072     c(1,2) = 2.0;                     
00073     
00074     ID d(1);    d(0) =  1;
00075     ID e(1);    e(0) =  2;
00076     ID f(2);    f(0) =  1; f(1) = 0;
00077     ID g(2);    g(0) = -1; g(1) = 2;
00078     ID h(3);    h(0) =  2; h(1) = 1; h(2) = 3;
00079     ID m(3);    m(0) =  5; m(1) = 4; m(2) = 3;    
00080 
00081     Graph theGraph(6);  
00082     Vertex v0(0,0);  theGraph.addVertex(&v0);
00083     Vertex v1(1,1);  theGraph.addVertex(&v1);
00084     Vertex v2(2,2);  theGraph.addVertex(&v2);
00085     Vertex v3(3,3);  theGraph.addVertex(&v3);
00086     Vertex v4(4,4);  theGraph.addVertex(&v4);
00087     Vertex v5(5,5);  theGraph.addVertex(&v5);
00088     theGraph.addEdge(0,1);
00089     theGraph.addEdge(2,1);
00090     theGraph.addEdge(1,3);
00091     theGraph.addEdge(5,4);
00092     theGraph.addEdge(4,3);
00093 
00094     Vector x(3); x(0) = 2; x(1) = 3; x(2) = 4.5;
00095 
00096     SuperLU *theSolver1 = new SuperLU;
00097     SparseGenColLinSOE *theSOE1 = new SparseGenColLinSOE(*theSolver1);
00098 
00099     opserr << "Test One with SuperLU\n";
00100 
00101     theSOE1->setSize(theGraph);
00102     theSOE1->addA(a,f);
00103     theSOE1->addA(a,g);
00104     theSOE1->addA(c,h);
00105     theSOE1->addA(c,m,2.0);    
00106 
00107     theSOE1->addB(x,h);
00108     theSOE1->addB(x,m,-1);
00109 
00110     theSOE1->solve();
00111     opserr << "B: " << theSOE1->getB();
00112     opserr << "X: " << theSOE1->getX();
00113 
00114     delete theSOE1;
00115     
00116     KSPType method = KSPCG;            // KSPCG KSPGMRES
00117     PCType preconditioner = PCJACOBI; // PCJACOBI PCILU PCBJACOBI
00118     
00119     PetscSparseSeqSolver *theSolver2 = new     PetscSparseSeqSolver(method, preconditioner);
00120     SparseGenRowLinSOE *theSOE2 = new SparseGenRowLinSOE(*theSolver2);
00121 
00122     opserr << "Test Two with Petsc\n";
00123 
00124     theSOE2->setSize(theGraph);
00125 
00126     theSOE2->addA(a,f);
00127     theSOE2->addA(a,g);
00128     theSOE2->addA(c,h);
00129     theSOE2->addA(c,m,2.0);    
00130 
00131     theSOE2->addB(x,h);
00132     theSOE2->addB(x,m,-1);
00133 
00134     theSOE2->solve();
00135     opserr << "B: " << theSOE2->getB();
00136     opserr << "X: " << theSOE2->getX();
00137 
00138     // solve again
00139     theSOE2->solve();
00140     opserr << "  results on a second solve with same B\n";
00141     opserr << "B: " << theSOE2->getB();
00142     opserr << "X: " << theSOE2->getX();
00143 
00144     delete theSOE2;
00145 
00146     PetscSparseSeqSolver *theSolver3 = new PetscSparseSeqSolver(method, preconditioner);
00147     SparseGenRowLinSOE *theSOE3 = new SparseGenRowLinSOE(*theSolver3);
00148 
00149     opserr << "Test Three with Petsc\n";
00150 
00151     theSOE3->setSize(theGraph);
00152 
00153     theSOE3->addA(a,f);
00154     theSOE3->addA(a,g);
00155     theSOE3->addA(c,h);
00156     theSOE3->addA(c,m,2.0);    
00157 
00158     theSOE3->addB(x,h);
00159     theSOE3->addB(x,m,-1);
00160 
00161     theSOE2->solve();
00162     opserr << "B: " << theSOE2->getB();
00163     opserr << "X: " << theSOE2->getX();
00164     
00165     // perturb A a bit
00166     theSOE3->addA(c,m,0.001);    
00167     theSOE3->solve();
00168     opserr << "  results on a second solve with A perturbed\n";
00169     opserr << "B: " << theSOE2->getB();
00170     opserr << "X: " << theSOE2->getX();
00171 
00172     // perturb B a bit
00173     theSOE3->addB(x,m,0.001);
00174     theSOE3->solve();
00175     opserr << "  results on a second solve with B perturbed\n";
00176     opserr << "B: " << theSOE2->getB();
00177     opserr << "X: " << theSOE2->getX();
00178 
00179     delete theSOE3;
00180     exit(0);
00181 }

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