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 #include <OPS_Globals.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <tcl.h>
00036
00037 #include <PetscSOE.h>
00038 #include <PetscSolver.h>
00039 #include <PetscSparseSeqSolver.h>
00040 #include <SparseGenRowLinSOE.h>
00041
00042 #ifdef _USRDLL
00043 #define DllExport _declspec(dllexport)
00044 #else
00045 #define DllExport
00046 #endif
00047
00048 extern "C" DllExport int
00049 TclCommand_Petsc(ClientData clientData,
00050 Tcl_Interp *interp,
00051 int argc,
00052 TCL_Char **argv,
00053 FEM_ObjectBroker *theBroker,
00054 LinearSOE **theSOE)
00055 {
00056
00057
00058 KSPType method = KSPCG;
00059 PCType preconditioner = PCJACOBI;
00060 int matType = 0;
00061
00062 double rTol = 1.0e-5;
00063 double aTol = 1.0e-50;
00064 double dTol = 1.0e5;
00065 int maxIts = 100000;
00066 int count = 2;
00067 while (count < argc-1) {
00068 if (strcmp(argv[count],"-matrixType") == 0 || strcmp(argv[count],"-matrix")){
00069 if (strcmp(argv[count+1],"sparse") == 0)
00070 matType = 1;
00071 }
00072 else if (strcmp(argv[count],"-rTol") == 0 || strcmp(argv[count],"-relTol") ||
00073 strcmp(argv[count],"-relativeTolerance")) {
00074 if (Tcl_GetDouble(interp, argv[count+1], &rTol) != TCL_OK)
00075 return TCL_ERROR;
00076 } else if (strcmp(argv[count],"-aTol") == 0 || strcmp(argv[count],"-absTol") ||
00077 strcmp(argv[count],"-absoluteTolerance")) {
00078 if (Tcl_GetDouble(interp, argv[count+1], &aTol) != TCL_OK)
00079 return TCL_ERROR;
00080 } else if (strcmp(argv[count],"-dTol") == 0 || strcmp(argv[count],"-divTol") ||
00081 strcmp(argv[count],"-divergenceTolerance")) {
00082 if (Tcl_GetDouble(interp, argv[count+1], &dTol) != TCL_OK)
00083 return TCL_ERROR;
00084 } else if (strcmp(argv[count],"-mIts") == 0 || strcmp(argv[count],"-maxIts") ||
00085 strcmp(argv[count],"-maxIterations")) {
00086 if (Tcl_GetInt(interp, argv[count+1], &maxIts) != TCL_OK)
00087 return TCL_ERROR;
00088 } else if (strcmp(argv[count],"-KSP") == 0 || strcmp(argv[count],"-KSPType")){
00089 if (strcmp(argv[count+1],"KSPCG") == 0)
00090 method = KSPCG;
00091 else if (strcmp(argv[count+1],"KSPBICG") == 0)
00092 method = KSPBICG;
00093 else if (strcmp(argv[count+1],"KSPRICHARDSON") == 0)
00094 method = KSPRICHARDSON;
00095 else if (strcmp(argv[count+1],"KSPCHEBYCHEV") == 0)
00096 method = KSPCHEBYCHEV;
00097 else if (strcmp(argv[count+1],"KSPGMRES") == 0)
00098 method = KSPGMRES;
00099 } else if (strcmp(argv[count],"-PC") == 0 || strcmp(argv[count],"-PCType")){
00100 if ((strcmp(argv[count+1],"PCJACOBI") == 0) || (strcmp(argv[count+1],"JACOBI") == 0))
00101 preconditioner = PCJACOBI;
00102 else if ((strcmp(argv[count+1],"PCILU") == 0) || (strcmp(argv[count+1],"ILU") == 0))
00103 preconditioner = PCILU;
00104 else if ((strcmp(argv[count+1],"PCICC") == 0) || (strcmp(argv[count+1],"ICC") == 0))
00105 preconditioner = PCICC;
00106 else if ((strcmp(argv[count+1],"PCBJACOBI") == 0) || (strcmp(argv[count+1],"BIJACOBI") == 0))
00107 preconditioner = PCBJACOBI;
00108 else if ((strcmp(argv[count+1],"PCNONE") == 0) || (strcmp(argv[count+1],"NONE") == 0))
00109 preconditioner = PCNONE;
00110 }
00111 count+=2;
00112 }
00113
00114 if (matType == 0) {
00115 PetscSolver *theSolver = new PetscSolver(method, preconditioner, rTol, aTol, dTol, maxIts);
00116 (*theSOE) = new PetscSOE(*theSolver);
00117 } else {
00118 PetscSparseSeqSolver *theSolver = new PetscSparseSeqSolver(method, preconditioner, rTol, aTol, dTol, maxIts);
00119 (*theSOE) = new SparseGenRowLinSOE(*theSolver);
00120 }
00121
00122
00123 if (*theSOE == 0) {
00124 opserr << "WARNING system Petsc - out of memory\n";
00125 return TCL_ERROR;
00126 }
00127
00128 return TCL_OK;
00129 }
00130