FullGenLinLapackSolver.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: 2003/04/02 22:02:52 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/system_of_eqn/linearSOE/fullGEN/FullGenLinLapackSolver.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/system_of_eqn/linearSOE/FullGEN/FullGenLinLapackSolver.h
00027 //
00028 // Written: fmk 
00029 // Created: Tue Sep 26 16:27:47: 1996
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for 
00033 // FullGenLinLapackSolver. It solves the FullGenLinSOE object by calling
00034 // Lapack routines.
00035 //
00036 // What: "@(#) FullGenLinLapackSolver.h, revA"
00037 
00038 #include <FullGenLinLapackSolver.h>
00039 #include <FullGenLinSOE.h>
00040 #include <f2c.h>
00041 #include <math.h>
00042 #include <Channel.h>
00043 #include <FEM_ObjectBroker.h>
00044 
00045 FullGenLinLapackSolver::FullGenLinLapackSolver()
00046 :FullGenLinSolver(SOLVER_TAGS_FullGenLinLapackSolver),iPiv(0),sizeIpiv(0)
00047 {
00048     
00049 }
00050 
00051 FullGenLinLapackSolver::~FullGenLinLapackSolver()
00052 {
00053     if (iPiv != 0)
00054         delete [] iPiv;
00055 }
00056 
00057 
00058 #ifdef _WIN32
00059 extern "C" int  DGESV(int *N, int *NRHS, double *A, int *LDA, 
00060                               int *iPiv, double *B, int *LDB, int *INFO);
00061                              
00062 extern "C" int  DGETRS(char *TRANS,
00063                                int *N, int *NRHS, double *A, int *LDA, 
00064                                int *iPiv, double *B, int *LDB, int *INFO);
00065 #else
00066 extern "C" int dgesv_(int *N, int *NRHS, double *A, int *LDA, int *iPiv, 
00067                       double *B, int *LDB, int *INFO);
00068 
00069 extern "C" int dgetrs_(char *TRANS, int *N, int *NRHS, double *A, int *LDA, 
00070                        int *iPiv, double *B, int *LDB, int *INFO);                     
00071 #endif
00072 int
00073 FullGenLinLapackSolver::solve(void)
00074 {
00075     if (theSOE == 0) {
00076         opserr << "WARNING FullGenLinLapackSolver::solve(void)- ";
00077         opserr << " No LinearSOE object has been set\n";
00078         return -1;
00079     }
00080     
00081     int n = theSOE->size;
00082     
00083     // check for quick return
00084     if (n == 0)
00085         return 0;
00086     
00087     // check iPiv is large enough
00088     if (sizeIpiv < n) {
00089         opserr << "WARNING FullGenLinLapackSolver::solve(void)- ";
00090         opserr << " iPiv not large enough - has setSize() been called?\n";
00091         return -1;
00092     }   
00093         
00094     int ldA = n;
00095     int nrhs = 1;
00096     int ldB = n;
00097     int info;
00098     double *Aptr = theSOE->A;
00099     double *Xptr = theSOE->X;
00100     double *Bptr = theSOE->B;
00101     int *iPIV = iPiv;
00102     
00103     // first copy B into X
00104     for (int i=0; i<n; i++)
00105         *(Xptr++) = *(Bptr++);
00106     Xptr = theSOE->X;
00107 
00108     // now solve AX = Y
00109 
00110 #ifdef _WIN32
00111     {if (theSOE->factored == false)  
00112         // factor and solve 
00113         DGESV(&n,&nrhs,Aptr,&ldA,iPIV,Xptr,&ldB,&info);
00114      else {
00115         // solve only using factored matrix      
00116          unsigned int sizeC = 1;
00117          DGETRS("N", &n,&nrhs,Aptr,&ldA,iPIV,Xptr,&ldB,&info);   
00118      }}
00119 #else
00120     {if (theSOE->factored == false)      
00121         dgesv_(&n,&nrhs,Aptr,&ldA,iPIV,Xptr,&ldB,&info);
00122      else
00123         dgetrs_("N", &n,&nrhs,Aptr,&ldA,iPIV,Xptr,&ldB,&info);
00124     }
00125 #endif
00126     
00127     // check if successfull
00128     if (info != 0) {
00129         opserr << "WARNING FullGenLinLapackSolver::solve()";
00130         opserr << " - lapack solver failed - " << info << " returned\n";
00131         return -info;
00132     }
00133 
00134     
00135     theSOE->factored = true;
00136     return 0;
00137 }
00138 
00139 
00140 int
00141 FullGenLinLapackSolver::setSize()
00142 {
00143     int n = theSOE->size;
00144     if (n > 0) {
00145         if (sizeIpiv < n) {
00146             if (iPiv != 0)
00147                 delete [] iPiv;
00148             iPiv = new int[n];          
00149             if (iPiv == 0) {
00150                 opserr << "WARNING FullGenLinLapackSolver::setSize()";
00151                 opserr << " - ran out of memory\n";
00152                 return -1;
00153             }           
00154             sizeIpiv = n;
00155         }
00156     } else if (n == 0)
00157         return 0;
00158     else {
00159         opserr << "WARNING FullGenLinLapackSolver::setSize()";
00160         opserr << " - ran out of memory\n";
00161         return -1;      
00162     }
00163         
00164     return 0;
00165 }
00166 
00167 int
00168 FullGenLinLapackSolver::sendSelf(int commitTag,
00169                                  Channel &theChannel)
00170 
00171 {
00172     // nothing to do
00173     return 0;
00174 }
00175 
00176 int
00177 FullGenLinLapackSolver::recvSelf(int commitTag,
00178                                  Channel &theChannel, 
00179                                  FEM_ObjectBroker &theBroker)
00180 {
00181     // nothing to do
00182     return 0;
00183 }
00184 
00185 
00186 

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