TclGroundMotionCommand.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.4 $
00022 // $Date: 2005/04/01 20:34:49 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/groundMotion/TclGroundMotionCommand.cpp,v $
00024 
00025 // Written: fmk 
00026 // Created: 11/00
00027 // Revision: A
00028 //
00029 // Description: This file contains the function invoked when the user invokes
00030 // the GroundMotion command in the interpreter. It is invoked by the 
00031 // TclModelBuilder_addGroundMotion function in the TclModelBuilder.C file. Current 
00032 // valid GroundMotion types are:
00033 
00034 // What: "@(#) TclGroundMotionCommand.C, revA"
00035 
00036 #include <TclModelBuilder.h>
00037 
00038 #include <tcl.h>
00039 #include <GroundMotionRecord.h>
00040 
00041 #include <string.h>
00042 #include <MultiSupportPattern.h>
00043 #include <InterpolatedGroundMotion.h>
00044 #include <TimeSeriesIntegrator.h>
00045 
00046 
00047 extern TimeSeries *
00048 TclSeriesCommand(ClientData clientData, Tcl_Interp *interp, TCL_Char *arg);
00049 
00050 extern TimeSeriesIntegrator *
00051 TclSeriesIntegratorCommand(ClientData clientData, Tcl_Interp *interp, TCL_Char *arg);
00052 
00053 int
00054 TclGroundMotionCommand(ClientData clientData, Tcl_Interp *interp, 
00055                        int argc, TCL_Char **argv, MultiSupportPattern *thePattern)
00056 {
00057   GroundMotion *theMotion = 0;
00058   int gMotionTag;
00059     
00060   // make sure at least one other argument to contain integrator
00061   if (argc < 4) {
00062     opserr << "WARNING invalid command - want: groundMotion tag type <args>\n";
00063     opserr << "           valid types: AccelRecord and Interpolated \n";
00064     return TCL_ERROR;
00065   }    
00066 
00067 
00068   if (Tcl_GetInt(interp, argv[1], &gMotionTag) != TCL_OK) {
00069     opserr << "WARNING invalid tag: groundMotion tag  type <args>\n";
00070     return TCL_ERROR;           
00071   }
00072   int startArg = 2;
00073 
00074   if ((strcmp(argv[startArg],"Series") == 0) ||
00075       (strcmp(argv[startArg],"Plain") == 0)) {
00076 
00077     TimeSeries *accelSeries = 0;
00078     TimeSeries *velSeries = 0;
00079     TimeSeries *dispSeries = 0;
00080     TimeSeriesIntegrator *seriesIntegrator = 0;
00081     
00082     int currentArg = startArg+1;        
00083 
00084     while (currentArg < argc-1) {
00085       if ((strcmp(argv[currentArg],"-accel") == 0) ||
00086           (strcmp(argv[currentArg],"-acceleration") == 0)) {
00087           
00088         currentArg++;
00089         accelSeries = TclSeriesCommand(clientData, interp, argv[currentArg]);
00090         if (accelSeries == 0) {
00091           opserr << "WARNING invalid accel series: groundMotion tag Series -accel <args>\n";
00092           return TCL_ERROR;             
00093         }
00094 
00095         currentArg++;
00096 
00097       } else if ((strcmp(argv[currentArg],"-vel") == 0) ||
00098                  (strcmp(argv[currentArg],"-velocity") == 0)) {
00099           
00100         currentArg++;
00101         velSeries = TclSeriesCommand(clientData, interp, argv[currentArg]);
00102         
00103         if (velSeries == 0) {
00104           opserr << "WARNING invalid vel series: " << argv[currentArg];
00105           opserr << " groundMotion tag Series -vel {series}\n";
00106           return TCL_ERROR;             
00107         }
00108         
00109         currentArg++;
00110 
00111       } else if ((strcmp(argv[currentArg],"-disp") == 0) ||
00112                  (strcmp(argv[currentArg],"-displacement") == 0)) {
00113           
00114         currentArg++;
00115         dispSeries = TclSeriesCommand(clientData, interp, argv[currentArg]);
00116 
00117         if (dispSeries == 0) {
00118           opserr << "WARNING invalid vel series: " << argv[currentArg];
00119           opserr << " groundMotion tag Series -vel {series}\n";
00120           return TCL_ERROR;             
00121         }
00122           
00123         currentArg++;
00124       } else if ((strcmp(argv[currentArg],"-int") == 0) ||
00125                  (strcmp(argv[currentArg],"-integrator") == 0)) {
00126           
00127         currentArg++;
00128         seriesIntegrator = TclSeriesIntegratorCommand(clientData, interp, 
00129                                                       argv[currentArg]);
00130         if (seriesIntegrator == 0) {
00131           opserr << "WARNING invalid series integrator: " << argv[currentArg];
00132           opserr << " - groundMotion tag Series -int {Series Integrator}\n";
00133           return TCL_ERROR;             
00134         }         
00135         currentArg++;
00136       }
00137 
00138     }
00139 
00140     theMotion = new GroundMotion(dispSeries, velSeries, 
00141                                  accelSeries, seriesIntegrator);
00142 
00143     if (theMotion == 0) {
00144       opserr << "WARNING ran out of memory creating ground motion - pattern UniformExcitation ";
00145       opserr << gMotionTag << endln;
00146       
00147       return TCL_ERROR;       
00148     }      
00149   }      
00150 
00151   else if (strcmp(argv[startArg],"Interpolated") == 0) {
00152 
00153     int endMotionIDs = startArg+1;
00154     int motionID;
00155     while (Tcl_GetInt(interp, argv[endMotionIDs], &motionID) == TCL_OK) {
00156       endMotionIDs++;
00157     }
00158     int numMotions = endMotionIDs - startArg - 1;
00159     GroundMotion **theMotions;
00160     if (numMotions != 0) {
00161       theMotions = new GroundMotion *[numMotions];      
00162       ID motionIDs(numMotions); 
00163       for (int i=3; i<endMotionIDs; i++) {
00164         if (Tcl_GetInt(interp, argv[i], &motionID) != TCL_OK)   
00165           return TCL_ERROR;     
00166         motionIDs[i-3] = motionID;        
00167         GroundMotion *theMotion1 = 
00168           thePattern->getMotion(motionID);
00169         
00170         if (theMotion1 == 0) {
00171           opserr << "WARNING no groundMotion with tag " << motionID <<" :";
00172           opserr << " pattern MultiSupport gMotion1? gMotion? .. ";
00173           opserr << "-fact fact1? fact2? .. \n";
00174           return TCL_ERROR;                 
00175         } else
00176           theMotions[i-3] = theMotion1;
00177       }
00178     } else {
00179       opserr << "WARNING no gMotionTags want :";
00180       opserr << " pattern MultiSupport gMotion1? gMotion? .. ";
00181       opserr << "-fact fact1? fact2? .. \n";
00182       return TCL_ERROR;
00183     }
00184     Vector facts(numMotions);
00185     for (int i=0; i<numMotions; i++) {
00186       double fact;
00187       if (Tcl_GetDouble(interp, argv[i+startArg+1+numMotions+2], &fact) != TCL_OK)      
00188         return TCL_ERROR;                   
00189       facts[i] = fact;
00190     }
00191     
00192     theMotion = new InterpolatedGroundMotion(theMotions, facts, false);
00193         
00194   }
00195     
00196   else { 
00197     opserr << "WARNING unknown pattern type " << argv[1];
00198     opserr << " - want: pattern patternType " << gMotionTag ;
00199     opserr << " \t valid types: Plain, UniformExcitation \n";
00200     return TCL_ERROR;      
00201   }
00202 
00203 
00204   // now add the load pattern to the modelBuilder
00205   if (theMotion != 0) {
00206     if (thePattern->addMotion(*theMotion, gMotionTag) < 0) {
00207       opserr << "WARNING could not add ground motion with tag " << gMotionTag;
00208       opserr << " to pattern\n ";
00209       delete theMotion; // free up the memory, pattern destroys the time series
00210       return TCL_ERROR;
00211     }
00212   }
00213 
00214   return TCL_OK;
00215 }
00216 
00217 
00218 
00219 

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