myCommands.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.6 $
00022 // $Date: 2003/02/25 23:34:26 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/modelbuilder/tcl/myCommands.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/modelbuilder/tcl/myCommands.C
00027 // 
00028 // Written: fmk 
00029 // Created: 04/98
00030 // Revision: A
00031 //
00032 // Description: This file contains the function myCommands().
00033 // myCommands() is called in g3AppInit() - all new user commands
00034 // are to be placed in here.
00035 //
00036 // What: "@(#) myCommands.C, revA"
00037 
00038 #include <Domain.h>
00039 #include "TclModelBuilder.h"
00040 #include "TclUniaxialMaterialTester.h"
00041 
00042 #include <tcl.h>
00043 #include <tk.h>
00044 
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <string.h>
00048 
00049 extern ModelBuilder *theBuilder;
00050 extern Domain theDomain;
00051 
00052 int
00053 specifyModelBuilder(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00054 
00055 int myCommands(Tcl_Interp *interp) {
00056     Tcl_CreateCommand(interp, "model", specifyModelBuilder,
00057                       (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
00058     return 0;
00059 }
00060 
00061 int
00062 specifyModelBuilder(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
00063 {
00064     // make sure at least one other argument to contain model builder type given
00065     if (argc < 2) {
00066       opserr << "WARNING need to specify a model type, valid types:\n";
00067       opserr << "\tBasicBuilder\n";
00068       return TCL_ERROR;
00069     }    
00070 
00071     // invoke the descructor on the old builder
00072     if (theBuilder != 0) {
00073       delete theBuilder;
00074       theBuilder = 0;
00075     }
00076 
00077     // check argv[1] for type of ModelBuilder and create the object 
00078     if (strcmp(argv[1],"basic") == 0 || strcmp(argv[1],"BasicBuilder") == 0) {
00079       int ndm =0;
00080       int ndf = 0;
00081       
00082       if (argc < 4) {
00083         opserr << "WARNING incorrect number of command arguments\n";
00084         opserr << "model modelBuilderType -ndm ndm? <-ndf ndf?> \n";
00085         return TCL_ERROR;
00086       }
00087 
00088       int argPos = 2;
00089       while (argPos < argc) {
00090         if (strcmp(argv[argPos],"-ndm") == 0 ||
00091                         strcmp(argv[argPos],"-NDM") == 0) {     
00092           argPos++;
00093           if (argPos < argc)
00094             if (Tcl_GetInt(interp, argv[argPos], &ndm) != TCL_OK) {
00095               opserr << "WARNING error reading ndm: " << argv[argPos];
00096               opserr << "\nmodel modelBuilderType -ndm ndm? <-ndf ndf?>\n";
00097               return TCL_ERROR;
00098             }     
00099           argPos++;
00100         }
00101 
00102         else if (strcmp(argv[argPos],"-ndf") == 0 ||
00103                         strcmp(argv[argPos],"-NDF") == 0) {     
00104           argPos++;
00105           if (argPos < argc)
00106             if (Tcl_GetInt(interp, argv[argPos], &ndf) != TCL_OK) {
00107               opserr << "WARNING error reading ndf: " << argv[argPos];
00108               opserr << "\nmodel modelBuilderType -ndm ndm? <-ndf ndf?>\n";
00109               return TCL_ERROR;
00110             }     
00111           argPos++;
00112         }
00113 
00114         else // Advance to next input argument if there are no matches -- MHS
00115           argPos++;
00116       }
00117 
00118       // check that ndm was specified
00119       if (ndm == 0) {
00120         opserr << "WARNING need to specify ndm\n";
00121         opserr << "model modelBuilderType -ndm ndm? <-ndf ndf?>\n";
00122         return TCL_ERROR;
00123       }
00124 
00125       // check for ndf, if not assume one
00126       if (ndf == 0) {
00127         if (ndm == 1) 
00128           ndf = 1;
00129         else if (ndm == 2)
00130           ndf = 3;
00131         else if (ndm == 3)
00132           ndf = 6;
00133         else {
00134           opserr << "WARNING specified ndm, " << ndm << ", will not work\n";
00135           opserr << "with any elements in BasicBuilder\n";
00136           return TCL_ERROR;
00137         }
00138       }
00139 
00140       // create the model builder
00141       theBuilder = new TclModelBuilder(theDomain, interp, ndm, ndf);
00142       if (theBuilder == 0) {
00143         opserr << "WARNING ran out of memory in creating BasicBuilder model\n";
00144         return TCL_ERROR;
00145       }
00146     }
00147 
00148     else if (strcmp(argv[1],"test") == 0 || strcmp(argv[1],"TestUniaxial") == 0) {
00149       int count = 1;
00150       if (argc == 3) {
00151             if (Tcl_GetInt(interp, argv[2], &count) != TCL_OK) {
00152               return TCL_ERROR;
00153             }     
00154       }
00155       theBuilder = new TclUniaxialMaterialTester(theDomain, interp, count);
00156       if (theBuilder == 0) {
00157         opserr << "WARNING ran out of memory in creating TclUniaxialMAterialTester model\n";
00158         return TCL_ERROR;
00159       }
00160     }
00161 
00162     else
00163     {
00164       Tcl_SetResult(interp, "WARNING unknown model builder type", TCL_STATIC);
00165 
00166       opserr << "WARNING model builder type " << argv[1]
00167            << " not supported\n";
00168       return TCL_ERROR;
00169     }
00170     
00171     return TCL_OK;
00172 }
00173 
00174 
00175 
00176 
00177 

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