TclPetsc.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.1 $
00022 // $Date: 2005/08/04 00:18:03 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/system_of_eqn/linearSOE/petsc/TclPetsc.cpp,v $
00024                                                                         
00025 // Written: fmk
00026 
00027 // Description: This file contains the function invoked when the user invokes
00028 // the Petsc command in the interpreter. 
00029 //
00030 // What: "@(#) TclCommand_MySQL.C, revA"
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     // now must determine the type of solver to create from rest of args
00058     KSPType method = KSPCG;            // KSPCG KSPGMRES
00059     PCType preconditioner = PCJACOBI; // PCJACOBI PCILU PCBJACOBI
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 

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