00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
00084 if (n == 0)
00085 return 0;
00086
00087
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
00104 for (int i=0; i<n; i++)
00105 *(Xptr++) = *(Bptr++);
00106 Xptr = theSOE->X;
00107
00108
00109
00110 #ifdef _WIN32
00111 {if (theSOE->factored == false)
00112
00113 DGESV(&n,&nrhs,Aptr,&ldA,iPIV,Xptr,&ldB,&info);
00114 else {
00115
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
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
00173 return 0;
00174 }
00175
00176 int
00177 FullGenLinLapackSolver::recvSelf(int commitTag,
00178 Channel &theChannel,
00179 FEM_ObjectBroker &theBroker)
00180 {
00181
00182 return 0;
00183 }
00184
00185
00186