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 #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
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
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;
00210 return TCL_ERROR;
00211 }
00212 }
00213
00214 return TCL_OK;
00215 }
00216
00217
00218
00219