UmfpackGenLinSolver.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:53 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/system_of_eqn/linearSOE/umfGEN/UmfpackGenLinSolver.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/system_of_eqn/linearSOE/umfGEN/UmfpackGenLinSolver.C
00027 //
00028 // Written: fmk 
00029 // Created: 11/98
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for 
00033 // UmfpackGenLinSolver. It solves the UmfpackGenLinSOEobject by calling
00034 // UMFPACK2.2.1 routines.
00035 //
00036 // What: "@(#) UmfpackGenLinSolver.C, revA"
00037 
00038 #include <UmfpackGenLinSOE.h>
00039 #include <UmfpackGenLinSolver.h>
00040 #include <f2c.h>
00041 #include <math.h>
00042 #include <Channel.h>
00043 #include <FEM_ObjectBroker.h>
00044 
00045 #ifdef _WIN32
00046 extern "C" int UMD21I(int *keep, double *cntl, int *icntl);
00047 #else
00048 extern "C" int umd21i_(int *keep, double *cntl, int *icntl);
00049 #endif
00050 
00051 
00052 UmfpackGenLinSolver::
00053 UmfpackGenLinSolver()
00054 :LinearSOESolver(SOLVER_TAGS_UmfpackGenLinSolver),
00055  copyIndex(0), lIndex(0), work(0), theSOE(0)
00056 {
00057   // perform the initialisation needed in UMFpack
00058 #ifdef _WIN32
00059   UMD21I(keep, cntl, icntl);    
00060 #else
00061   umd21i_(keep, cntl, icntl);
00062 #endif
00063 }
00064 
00065 
00066 UmfpackGenLinSolver::~UmfpackGenLinSolver()
00067 {
00068   if (copyIndex != 0)
00069     delete [] copyIndex;
00070 
00071   if (work != 0)
00072     delete [] work;
00073 }
00074 
00075 #ifdef _WIN32
00076 extern "C" int UMD2FA(int *n, int *ne, int *job, logical *transa,
00077                        int *lvalue, int *lindex, double *value,
00078                        int *index, int *keep, double *cntl, int *icntl,
00079                        int *info, double *rinfo);
00080 
00081 /*
00082 extern "C" int umd2rf_(int *n, int *ne, int *job, logical *transa,
00083                        int *lvalue, int *lindex, double *value,
00084                        int *index, int *keep, double *cntl, int *icntl,
00085                        int *info, double *rinfo);
00086 */
00087 extern "C" int  UMD2SO(int *n, int *job, logical *transa,
00088                        int *lvalue, int *lindex, double *value,
00089                        int *index, int *keep, double *b, double *x, 
00090                        double *w, double *cntl, int *icntl,
00091                        int *info, double *rinfo);
00092 #else
00093 extern "C" int umd2fa_(int *n, int *ne, int *job, logical *transa,
00094                        int *lvalue, int *lindex, double *value,
00095                        int *index, int *keep, double *cntl, int *icntl,
00096                        int *info, double *rinfo);
00097 
00098 extern "C" int umd2so_(int *n, int *job, logical *transa,
00099                        int *lvalue, int *lindex, double *value,
00100                        int *index, int *keep, double *b, double *x, 
00101                        double *w, double *cntl, int *icntl,
00102                        int *info, double *rinfo);
00103 #endif
00104 
00105 int
00106 UmfpackGenLinSolver::solve(void)
00107 {
00108     if (theSOE == 0) {
00109         opserr << "WARNING UmfpackGenLinSolver::solve(void)- ";
00110         opserr << " No LinearSOE object has been set\n";
00111         return -1;
00112     }
00113     
00114     int n = theSOE->size;
00115     int ne = theSOE->nnz;
00116     int lValue = theSOE->lValue;
00117 
00118     // check for quick return
00119     if (n == 0)
00120         return 0;
00121 
00122     // first copy B into X
00123     double *Xptr = theSOE->X;
00124     double *Bptr = theSOE->B;
00125     double *Aptr = theSOE->A;
00126 
00127     int job =0; // set to 1 if wish to do iterative refinment
00128     logical trans = FALSE_;
00129 
00130     if (theSOE->factored == false) {
00131 
00132       // make a copy of index
00133       for (int i=0; i<2*ne; i++) {
00134         copyIndex[i] = theSOE->index[i];
00135       }
00136 
00137       // factor the matrix
00138 #ifdef _WIN32
00139       UMD2FA(&n, &ne, &job, &trans, &lValue, &lIndex, Aptr,
00140               copyIndex, keep, cntl, icntl, info, rinfo);
00141 #else
00142       umd2fa_(&n, &ne, &job, &trans, &lValue, &lIndex, Aptr,
00143               copyIndex, keep, cntl, icntl, info, rinfo);
00144 #endif      
00145       
00146       if (info[0] != 0) {       
00147         opserr << "WARNING UmfpackGenLinSolver::solve(void)- ";
00148         opserr << info[0] << " returned in factorization UMD2FA()\n";
00149         return -info[0];
00150       }
00151       theSOE->factored = true;
00152     }   
00153 
00154     // do forward and backward substitution
00155 #ifdef _WIN32
00156     UMD2SO(&n, &job, &trans, &lValue, &lIndex, Aptr, copyIndex, 
00157            keep, Bptr, Xptr, work, cntl, icntl, info, rinfo);    
00158 #else
00159     umd2so_(&n, &job, &trans, &lValue, &lIndex, Aptr, copyIndex, 
00160             keep, Bptr, Xptr, work, cntl, icntl, info, rinfo);
00161 #endif
00162 
00163     if (info[0] != 0) { 
00164        opserr << "WARNING UmfpackGenLinSolver::solve(void)- ";
00165        opserr << info[0] << " returned in substitution dgstrs()\n";
00166        return -info[0];
00167     }
00168 
00169     return 0;
00170 }
00171 
00172 
00173 int
00174 UmfpackGenLinSolver::setSize()
00175 {
00176     int n = theSOE->size;
00177     int ne = theSOE->nnz;
00178     if (n > 0) {
00179       if (work != 0)
00180         delete [] work;
00181 
00182       work = new double[4*n];
00183 
00184       lIndex = 37*n + 4*ne + 10;
00185       if (copyIndex != 0)
00186         delete [] copyIndex;
00187 
00188       copyIndex = new int[lIndex];
00189     }   
00190     return 0;
00191 }
00192 
00193 int
00194 UmfpackGenLinSolver::setLinearSOE(UmfpackGenLinSOE &theLinearSOE)
00195 {
00196   theSOE = &theLinearSOE;
00197   return 0;
00198 }
00199 
00200 int
00201 UmfpackGenLinSolver::sendSelf(int cTag, Channel &theChannel)
00202 {
00203     // nothing to do
00204     return 0;
00205 }
00206 
00207 int
00208 UmfpackGenLinSolver::recvSelf(int ctag,
00209                               Channel &theChannel, 
00210                               FEM_ObjectBroker &theBroker)
00211 {
00212     // nothing to do
00213     return 0;
00214 }
00215 

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