mainTriangle.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:01:58 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/renderer/mainTriangle.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/model/main.C
00027 //
00028 // Written: fmk 12/95
00029 // Revised:
00030 //
00031 // Purpose: This file is a driver to create a 2d plane-frame
00032 // model and to perform a linear static analysis on that model.
00033 // 
00034 //
00035 
00036 #include <X11Renderer.h>
00037 #include <DofColorMap.h>
00038 
00039 #define numP 8
00040 
00041 #define BLAS_EXISTS 1
00042 // #define PETSC_EXISTS 1
00043 
00044 #include <stdlib.h>
00045 #include <iOPS_Stream.h>
00046 
00047 #include <Timer.h>
00048 #include <TrianglePlaneStress.h>
00049 
00050 #include <Node.h>
00051 #include <Domain.h>
00052 
00053 #include <AnalysisModel.h>
00054 
00055 #include <Linear.h>
00056 #include <NewtonRaphson.h>
00057 
00058 #include <PlainHandler.h>
00059 #include <PenaltyConstraintHandler.h>
00060 
00061 #include <PlainNumberer.h>
00062 #include <DOF_Numberer.h>
00063 
00064 #include <StaticIntegrator.h>
00065 #include <LoadControl.h>
00066 
00067 #include <CTestNormUnbalance.h>
00068 #include <CTestNormDispIncr.h>
00069 #include <CTestEnergyIncr.h>
00070 
00071 #include <StaticAnalysis.h>
00072 
00073 #include <SlowLinearSOE.h>
00074 #include <SlowLinearSOESolver.h>
00075 #include <ProfileSPDLinSOE.h>
00076 #include <ProfileSPDLinDirectSolver.h>
00077 #include <ProfileSPDLinDirectBlockSolver.h>
00078 
00079 #ifdef BLAS_EXISTS
00080 #include <BandSPDLinSOE.h>
00081 #include <BandSPDLinLapackSolver.h>
00082 #include <BandGenLinSOE.h>
00083 #include <BandGenLinLapackSolver.h>
00084 #include <FullGenLinSOE.h>
00085 #include <FullGenLinLapackSolver.h>
00086 #include <ProfileSPDLinDirectThreadSolver.h>
00087 #include <ProfileSPDLinDirectSkypackSolver.h>
00088 #include <SparseGenLinSOE.h>
00089 #include <SparseGenSuperLuSolver.h>
00090 #include <SparseGenSuperLuThreadSolver.h>
00091 #endif
00092 
00093 #ifdef PETSC_EXISTS
00094 #include <PetscSOE.h>
00095 #include <PetscSolver.h>
00096 #include <mpi.h>
00097 #endif
00098 
00099 #include <Graph.h>
00100 #include <RCM.h>
00101 #include <Metis.h>
00102 
00103 int main(int argc, char **argv)
00104 {
00105     //
00106     // read in the number of analysis iterations
00107     //    - the first iteartion will be expensive due to
00108     //      construction of FE_Element, DOF_Groups, node
00109     //      and dof graphs
00110     // 
00111 
00112     int numReps;
00113     opserr << "Enter Number of Iterations: ";
00114     cin >> numReps;
00115     
00116 #ifdef PETSC_EXISTS
00117     int numP; // number of processes started
00118     int me;  // the integer id of the process .. 0 through numP-1
00119     MPI_Init(&argc, &argv);
00120     MPI_Comm_rank(MPI_COMM_WORLD, &me);
00121     MPI_Comm_size(MPI_COMM_WORLD, &numP);
00122     static char help[] = "My daft little program\n";
00123     PetscInitialize(&argc, &argv, (char *)0, help);
00124 #endif  
00125     
00126     //
00127     //  now create a domain and a modelbuilder
00128     //  and build the model
00129     //
00130 
00131     Domain *theDomain = new Domain();
00132     TrianglePlaneStress  *theModelBuilder 
00133       = new TrianglePlaneStress(*theDomain);
00134     theModelBuilder->buildFE_Model();
00135 
00136 
00137     theModelBuilder->fixNodeXdirnXloc(100.0,0.0);
00138     theModelBuilder->fixNodeYdirnYloc(100.0,0.0);
00139 
00140     theModelBuilder->addPointLoad(0.0,100.0, -50.0, 0.0);
00141 
00142     //
00143     // create an Analysis object to perform a static analysis of the model
00144     //  - constructs:
00145     //    AnalysisModel of type AnalysisModel,
00146     //    EquiSolnAlgo of type Linear
00147     //    StaticIntegrator of type StaticIntegrator
00148     //    ConstraintHandler of type PlainHandler (only homo SP constraints)
00149     //    DOF_Numberer which does either RCM or takes order provided
00150     //    LinearSOE of types full and band general, band and profile SPD
00151 
00152     AnalysisModel       *theModel = new AnalysisModel();
00153     EquiSolnAlgo        *theSolnAlgo = new Linear();
00154     ConvergenceTest *theTest = new CTestNormUnbalance(1.0e-8);
00155     // EquiSolnAlgo     *theSolnAlgo = new NewtonRaphson(10,*theTest); 
00156     StaticIntegrator    *theIntegrator = new LoadControl(1);
00157 
00158     ConstraintHandler   *theHandler;
00159     cout << "Enter ConstraintHandler type: [1]-Plain, [2]-Penalty: ";
00160     int handlerType;
00161     cin >> handlerType;
00162     if (handlerType == 1)
00163         theHandler = new PlainHandler();
00164     else
00165         theHandler = new PenaltyConstraintHandler(1.0e16,1.0e16);
00166     
00167     // construct the DOF_Numberer
00168     cout << "[1]-RCM, [2]-Metis : ";
00169     int numType;
00170     cin >> numType;    
00171     
00172     DOF_Numberer *theNumberer;
00173     GraphNumberer *theGN;
00174     if (numType == 1) {
00175       theGN = new RCM;
00176       theNumberer = new DOF_Numberer(*theGN);       
00177     } else {
00178       theGN = new Metis(numP);
00179       theNumberer = new DOF_Numberer(*theGN);       
00180     }
00181 
00182     // construct the LinearSOE
00183     LinearSOE *theSOE;
00184 
00185 #ifdef PETSC_EXISTS        
00186     cout << "Enter SystemOfEquation type: [1]-FullGen, [2]-BandGen, ";
00187     cout << "[3]-BandSPD, [4]-ProfileSPD, [5]-SparseGEN, [6]-Petsc : ";
00188     int soeType;
00189     cin >> soeType;    
00190     if (soeType == 1) {
00191       FullGenLinSolver    *theSolver = new FullGenLinLapackSolver();
00192       theSOE = new FullGenLinSOE(*theSolver);            
00193     } else if (soeType == 2) {
00194       BandGenLinSolver    *theSolver = new BandGenLinLapackSolver();
00195       theSOE = new BandGenLinSOE(*theSolver);      
00196     } else if (soeType == 3) {
00197       BandSPDLinSolver    *theSolver = new BandSPDLinLapackSolver();   
00198       theSOE = new BandSPDLinSOE(*theSolver);        
00199     } else if (soeType == 4) { // a ProfileSPD
00200       // can choose from a variety of solver for a profile SPD
00201       ProfileSPDLinSolver *theSolver;
00202       cout << "Enter Solver Type: [1]-Normal, [2]-Block, [3]-Skypack: ";
00203       int solverType;
00204       cin >> solverType;
00205       if (solverType == 1) 
00206         theSolver = new ProfileSPDLinDirectSolver(); 
00207       else if (solverType == 2) {
00208         cout << "Enter blockSize: ";
00209         int blockSize;
00210         cin >> blockSize;
00211         theSolver = new ProfileSPDLinDirectBlockSolver(1.0e-12,blockSize); 
00212       } else {
00213         cout << "Enter mRows, mCols [e.g. 64 128] ";
00214         int mRows, mCols;
00215         cin >> mRows >> mCols;
00216         theSolver = new ProfileSPDLinDirectSkypackSolver(mCols, mRows); 
00217       }
00218       theSOE = new ProfileSPDLinSOE(*theSolver);      
00219     }
00220     else if (soeType == 5) {
00221       // cout << "Enter Num Threads: ";
00222       //      int NP;
00223       //      cin >> NP;
00224       cout << "Enter Ordering [0]: natural, [1]-min Degree A^tA ";
00225       cout << "[2]-min Degree A^t+A: ";
00226       int perm;
00227       cin >> perm;
00228       SparseGenLinSolver  *
00229         theSolver = new SparseGenSuperLuSolver(perm,3,3,0.0);   
00230       //      SparseGenLinSolver  
00231       //        *theSolver = new SparseGenSuperLuThreadSolver(NP,perm,3,3,0.0);   
00232       theSOE = new SparseGenLinSOE(*theSolver);        
00233     } 
00234     else {
00235       PetscSolver *theSolver = new PetscSolver(KSPCG, PCJACOBI);
00236       theSOE = new PetscSOE(*theSolver);
00237 
00238   }
00239 #endif
00240     
00241 #ifdef BLAS_EXISTS        
00242     cout << "Enter SystemOfEquation type: [1]-FullGen, [2]-BandGen, ";
00243     cout << "[3]-BandSPD, [4]-ProfileSPD, [5]-SparseGEN : ";
00244     int soeType;
00245     cin >> soeType;    
00246     if (soeType == 1) {
00247       FullGenLinSolver    *theSolver = new FullGenLinLapackSolver();
00248       theSOE = new FullGenLinSOE(*theSolver);            
00249     } else if (soeType == 2) {
00250       BandGenLinSolver    *theSolver = new BandGenLinLapackSolver();
00251       theSOE = new BandGenLinSOE(*theSolver);      
00252     } else if (soeType == 3) {
00253       BandSPDLinSolver    *theSolver = new BandSPDLinLapackSolver();   
00254       theSOE = new BandSPDLinSOE(*theSolver);        
00255     } else if (soeType == 4) { // a ProfileSPD
00256       // can choose from a variety of solver for a profile SPD
00257       ProfileSPDLinSolver *theSolver;
00258       cout << "Enter Solver Type: [1]-Normal, [2]-Block, [3]-Skypack: ";
00259       int solverType;
00260       cin >> solverType;
00261       if (solverType == 1) 
00262         theSolver = new ProfileSPDLinDirectSolver(); 
00263       else if (solverType == 2) {
00264         cout << "Enter blockSize: ";
00265         int blockSize;
00266         cin >> blockSize;
00267         theSolver = new ProfileSPDLinDirectBlockSolver(1.0e-12,blockSize); 
00268       } else {
00269         cout << "Enter mRows, mCols [e.g. 64 128] ";
00270         int mRows, mCols;
00271         cin >> mRows >> mCols;
00272         theSolver = new ProfileSPDLinDirectSkypackSolver(mCols, mRows); 
00273       }
00274       theSOE = new ProfileSPDLinSOE(*theSolver);      
00275     }
00276     else {
00277       // cout << "Enter Num Threads: ";
00278       //      int NP;
00279       //      cin >> NP;
00280       cout << "Enter Ordering [0]: natural, [1]-min Degree A^tA ";
00281       cout << "[2]-min Degree A^t+A: ";
00282       int perm;
00283       cin >> perm;
00284       SparseGenLinSolver  *
00285         theSolver = new SparseGenSuperLuSolver(perm,3,3,0.0);   
00286       //      SparseGenLinSolver  
00287       //        *theSolver = new SparseGenSuperLuThreadSolver(NP,perm,3,3,0.0);   
00288       theSOE = new SparseGenLinSOE(*theSolver);        
00289   }
00290 #endif    
00291     
00292 
00293 
00294     StaticAnalysis      theAnalysis(*theDomain,
00295                                     *theHandler,
00296                                     *theNumberer,
00297                                     *theModel,
00298                                     *theSolnAlgo,
00299                                     *theSOE,
00300                                     *theIntegrator);
00301     
00302     //
00303     // start the timing
00304     // 
00305 
00306     Timer timer;
00307     Timer timer1;
00308 
00309     timer.start();
00310     timer1.start();
00311 
00312 
00313     for (int j=0; j<numReps; j++) {
00314         timer.start();
00315         theAnalysis.analyze();    
00316         timer.pause();
00317         theSolnAlgo->Print(opserr);
00318         timer1.pause();
00319         cout << "Main::Time To Analyse Rep: " << 
00320           j+1 << "  real:  " << timer.getReal();
00321         cout << "  cpu: " << timer.getCPU() << 
00322           "  page: " << timer.getNumPageFaults() << endln; 
00323         cout << "Main::Time Since Start: " 
00324              << j+1 << "  real:  " << timer1.getReal();
00325         cout << "  cpu: " << timer1.getCPU() 
00326           << "  page: " << timer1.getNumPageFaults() << endln; 
00327 
00328     }
00329 
00330     // done
00331     //    opserr << *theDomain;
00332     
00333     Node *theNode = theDomain->getNode(2);
00334     if (theNode != 0) {
00335         opserr << *theNode;
00336     }
00337 
00338     //const Vector &theResult = theSOE->getX();
00339     //opserr << "x(0): " << theResult(0) << endln;
00340 
00341     DofColorMap theMap(theSOE->getNumEqn(),numP);
00342     WindowRenderer *theViewer = new X11Renderer(600,600,*theDomain, theMap);
00343     theViewer->setPRP(50, 50, 100);
00344     theViewer->setVRP(50, 50, 0);
00345     theViewer->setVUP(0,1,0);
00346     theViewer->setVPN(0,0,1);
00347     theViewer->setViewWindow(-5,105,-5, 105);
00348     theViewer->setPlaneDist(0,150);
00349     theViewer->setPortWindow(-1,1,-1, 1);
00350     theViewer->setProjectionMode(0); // 0 parallel mode, 1 perspective
00351     theViewer->setFillMode(1); // 0 fill, 1 wire
00352     
00353     theViewer->displayModel(0,0);
00354 
00355     int data;
00356     cin >> data;
00357 
00358 #ifdef PETSC_EXISTS    
00359     MPI_Finalize();    
00360     PetscFinalize();
00361 #endif
00362     exit(0);
00363 }       
00364         

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