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 #include <tcl.h>
00034 #include <tk.h>
00035
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039
00040 #include <Domain.h>
00041
00042 #include <MeshRegion.h>
00043 #include <ID.h>
00044
00045 int
00046 TclAddMeshRegion(ClientData clientData, Tcl_Interp *interp, int argc,
00047 TCL_Char **argv, Domain &theDomain)
00048 {
00049 int loc = 1;
00050 int tag;
00051 double alphaM = 0.0;
00052 double betaK = 0.0;
00053 double betaK0 = 0.0;
00054 double betaKc = 0.0;
00055
00056 ID *theNodes = 0;
00057 ID *theElements = 0;
00058 int numNodes = 0;
00059 int numElements = 0;
00060
00061
00062 if (argc < 2) {
00063 opserr << "WARNING region tag? - no tag specified\n";
00064 return TCL_ERROR;
00065 }
00066
00067 if (Tcl_GetInt(interp, argv[loc], &tag) != TCL_OK) {
00068 opserr << "WARNING region tag? .. - invalid tag " << argv[loc] << endln;
00069 return TCL_ERROR;
00070 }
00071
00072 loc++;
00073
00074
00075 while (loc < argc) {
00076
00077 if (strcmp(argv[loc],"-ele") == 0) {
00078
00079
00080 if (argc < loc+2) {
00081 opserr << "WARNING region tag? .. -ele tag1? .. - no ele tags specified\n";
00082 return TCL_ERROR;
00083 }
00084
00085
00086
00087
00088 loc++;
00089
00090 if (theElements == 0)
00091 theElements = new ID(0, 64);
00092 int eleTag;
00093
00094 while (loc < argc && Tcl_GetInt(interp, argv[loc++], &eleTag) == TCL_OK) {
00095 (*theElements)[numElements++] = eleTag;
00096 }
00097 if (loc < argc) loc--;
00098
00099 } else if (strcmp(argv[loc],"-eleRange") == 0) {
00100
00101
00102 if (argc < loc+3) {
00103 opserr << "WARNING region tag? .. -eleRange start? end? .. - no ele tags specified\n";
00104 return TCL_ERROR;
00105 }
00106
00107
00108
00109
00110
00111 int start, end;
00112 if (Tcl_GetInt(interp, argv[loc+1], &start) != TCL_OK) {
00113 opserr << "WARNING region tag? -eleRange start? end? - invalid start " << argv[loc+1] << endln;
00114 return TCL_ERROR;
00115 }
00116 if (Tcl_GetInt(interp, argv[loc+2], &end) != TCL_OK) {
00117 opserr << "WARNING region tag? -eleRange start? end? - invalid end " << argv[loc+2] << endln;
00118 return TCL_ERROR;
00119 }
00120 if (start > end) {
00121 int swap = end;
00122 end = start;
00123 start = swap;
00124 }
00125 int numEle = end-start+1;
00126
00127 if (theElements == 0)
00128 theElements = new ID(0, numEle);
00129 for (int i=start; i<=end; i++)
00130 (*theElements)[numElements++] = i;
00131
00132 loc += 3;
00133
00134 } else if (strcmp(argv[loc],"-node") == 0) {
00135
00136
00137 if (argc < loc+2) {
00138 opserr << "WARNING region tag? .. -node tag1? .. - no node tags specified\n";
00139 return TCL_ERROR;
00140 }
00141
00142 loc++;
00143
00144
00145
00146 if (theNodes == 0)
00147 theNodes = new ID(0, 64);
00148 int nodTag;
00149 while (loc < argc && Tcl_GetInt(interp, argv[loc++], &nodTag) == TCL_OK) {
00150 (*theNodes)[numNodes++] = nodTag;
00151 }
00152
00153 if (loc < argc) loc--;
00154
00155 } else if (strcmp(argv[loc],"-nodeRange") == 0) {
00156
00157
00158 if (argc < loc+3) {
00159 opserr << "WARNING region tag? .. -nodeRange start? end? .. - no node tags specified\n";
00160 return TCL_ERROR;
00161 }
00162
00163
00164 int start, end;
00165 if (Tcl_GetInt(interp, argv[loc+1], &start) != TCL_OK) {
00166 opserr << "WARNING region tag? -eleRange start? end? - invalid start " << argv[loc+1] << endln;
00167 return TCL_ERROR;
00168 }
00169 if (Tcl_GetInt(interp, argv[loc+2], &end) != TCL_OK) {
00170 opserr << "WARNING region tag? -eleRange start? end? - invalid end " << argv[loc+1] << endln;
00171 return TCL_ERROR;
00172 }
00173 if (start > end) {
00174 int swap = end;
00175 end = start;
00176 start = swap;
00177 }
00178 int numNode = end-start+1;
00179
00180 if (theNodes == 0)
00181 theNodes = new ID(0, numNode);
00182 for (int i=start; i<=end; i++)
00183 (*theNodes)[numNodes++] = i;
00184
00185 loc += 3;
00186
00187 } else if (strcmp(argv[loc],"-rayleigh") == 0) {
00188
00189
00190 if (argc < loc+5) {
00191 opserr << "WARNING region tag? .. -rayleigh aM? bK? bK0? .. - not enough factors\n";
00192 return TCL_ERROR;
00193 }
00194
00195
00196 if (Tcl_GetDouble(interp, argv[loc+1], &alphaM) != TCL_OK) {
00197 opserr << "WARNING region tag? .. -rayleigh aM bK bK0 - invalid aM " << argv[loc+1] << endln;
00198 return TCL_ERROR;
00199 }
00200 if (Tcl_GetDouble(interp, argv[loc+2], &betaK) != TCL_OK) {
00201 opserr << "WARNING region tag? .. -rayleigh aM bK bK0 - invalid bK " << argv[loc+2] << endln;
00202 return TCL_ERROR;
00203 }
00204 if (Tcl_GetDouble(interp, argv[loc+3], &betaK0) != TCL_OK) {
00205 opserr << "WARNING region tag? .. -rayleigh aM bK bK0 - invalid bK0 " << argv[loc+3] << endln;
00206 return TCL_ERROR;
00207 }
00208 if (Tcl_GetDouble(interp, argv[loc+4], &betaKc) != TCL_OK) {
00209 opserr << "WARNING region tag? .. -rayleigh aM bK bK0 - invalid bKc " << argv[loc+4] << endln;
00210 return TCL_ERROR;
00211 }
00212 loc += 5;
00213
00214 } else
00215 loc++;
00216
00217 }
00218
00219 MeshRegion *theRegion = new MeshRegion(tag);
00220
00221 if ((theRegion == 0) || (theDomain.addRegion(*theRegion)) < 0) {
00222 opserr << "WARNING could not add to domain - region " << tag << endln;
00223 if (theRegion == 0)
00224 opserr << "could not create region\n";
00225 else
00226 delete theRegion;
00227 return TCL_ERROR;
00228 }
00229
00230
00231 if (theElements != 0)
00232 theRegion->setElements(*theElements);
00233
00234 if (theNodes != 0) {
00235 if (theElements == 0)
00236 theRegion->setNodes(*theNodes);
00237 else
00238 opserr << "WARNING region - both elements & nodes set, ONLY set using elements\n";
00239 }
00240
00241
00242 if (alphaM != 0.0 || betaK != 0.0 || betaK0 != 0.0 || betaKc != 0.0)
00243 theRegion->setRayleighDampingFactors(alphaM, betaK, betaK0, betaKc);
00244
00245 if (theElements != 0)
00246 delete theElements;
00247
00248 if (theNodes != 0)
00249 delete theNodes;
00250
00251 return TCL_OK;
00252 }
00253