TclModelBuilder.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.33 $
00022 // $Date: 2006/10/02 20:09:08 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/modelbuilder/tcl/TclModelBuilder.cpp,v $
00024                                                                         
00025                                                                         
00026 // Written: fmk 
00027 // Created: 07/99
00028 //
00029 // Description: This file contains the class definition for TclModelBuilder.
00030 // A TclModelBuilder adds the commands to create the model for the standard
00031 // models that can be generated using the elements released with the g3 
00032 // framework. currently these elements include:
00033 //      1) linear-elastic 2 and 3d beam-column elements
00034 //      2) non-linear material truss
00035 //      3) non-linear 2 and 3d fiber-beam-column elements
00036 
00037 //
00038 // What: "@(#) TclModelBuilder.cpp, revA"
00039 
00040 #include <stdlib.h>
00041 #include <string.h>
00042 
00043 #include <Matrix.h>
00044 #include <Vector.h>
00045 #include <ID.h>
00046 #include <ArrayOfTaggedObjects.h>
00047 
00048 #include <Domain.h>
00049 #include <Node.h>
00050 #include <NodeIter.h>
00051 #include <SP_Constraint.h>
00052 #include <SP_ConstraintIter.h>
00053 #include <MP_Constraint.h>
00054 #include <NodalLoad.h>
00055 #include <Beam2dPointLoad.h>
00056 #include <Beam2dUniformLoad.h>
00057 #include <Beam2dTempLoad.h>
00058 #include <Beam3dPointLoad.h>
00059 #include <Beam3dUniformLoad.h>
00060 #include <BrickSelfWeight.h>
00061 #include <LoadPattern.h>
00062 
00063 #include <SectionForceDeformation.h>
00064 #include <SectionRepres.h>
00065 
00066 #include <CrdTransf2d.h>
00067 #include <CrdTransf3d.h>
00068 
00069 #include <UniaxialMaterial.h>
00070 #include <NDMaterial.h>
00071 #include <TclModelBuilder.h>
00072 #include <ImposedMotionSP.h>
00073 #include <ImposedMotionSP1.h>
00074 #include <MultiSupportPattern.h>
00075 
00076 #include <Block2D.h>
00077 #include <Block3D.h>
00078 // Added by Scott J. Brandenberg (sjbrandenberg@ucdavis.edu)
00079 #include <PySimple1Gen.h>
00080 #include <TzSimple1Gen.h>
00081 // End added by SJB
00082 
00083 #include <YieldSurface_BC.h>
00084 #include <YS_Evolution.h>
00085 #include <PlasticHardeningMaterial.h>
00086 #include <CyclicModel.h> 
00087 #include <DamageModel.h> 
00088 
00089 #ifdef OO_HYSTERETIC
00090 #include <StiffnessDegradation.h>
00091 #include <UnloadingRule.h>
00092 #include <StrengthDegradation.h>
00093 #include <HystereticBackbone.h>
00094 #endif
00095 
00096 #include <packages.h>
00097 
00098 //
00099 // SOME STATIC POINTERS USED IN THE FUNCTIONS INVOKED BY THE INTERPRETER
00100 //
00101 
00102 static Domain *theTclDomain =0;
00103 static TclModelBuilder *theTclBuilder =0;
00104 
00105 extern LoadPattern *theTclLoadPattern;
00106 extern MultiSupportPattern *theTclMultiSupportPattern;
00107 static int eleArgStart = 0;
00108 static int nodeLoadTag = 0;
00109 static int eleLoadTag = 0;
00110 
00111 static int currentSpTag = 0;
00112 
00113 // 
00114 // THE PROTOTYPES OF THE FUNCTIONS INVOKED BY THE INTERPRETER
00115 //
00116 
00117 int
00118 TclModelBuilder_addParameter(ClientData clientData, Tcl_Interp *interp, int argc, 
00119                              TCL_Char **argv);
00120 
00121 int
00122 TclModelBuilder_addNode(ClientData clientData, Tcl_Interp *interp, int argc, 
00123                         TCL_Char **argv);
00124 
00125 int
00126 TclModelBuilder_addElement(ClientData clientData, Tcl_Interp *interp,  int argc, 
00127                            TCL_Char **argv);
00128 
00129 int
00130 TclModelBuilder_addUniaxialMaterial(ClientData clientData, Tcl_Interp *interp, int argc,   
00131                                     TCL_Char **argv);
00132 
00133 int
00134 TclModelBuilder_addNDMaterial(ClientData clientData, Tcl_Interp *interp, int argc,   
00135                             TCL_Char **argv);
00136 
00137 int
00138 TclModelBuilder_addSection(ClientData clientData, Tcl_Interp *interp, int argc,   
00139                            TCL_Char **argv);
00140 
00141 int
00142 TclModelBuilder_addYieldSurface_BC(ClientData clientData, Tcl_Interp *interp,
00143                                     int argc, TCL_Char **argv);
00144 
00145 int
00146 TclModelBuilder_addYS_EvolutionModel(ClientData clientData, Tcl_Interp *interp,
00147                                     int argc, TCL_Char **argv);
00148 
00149 int
00150 TclModelBuilder_addYS_PlasticMaterial(ClientData clientData, Tcl_Interp *interp,
00151                                     int argc, TCL_Char **argv);
00152 
00153 int 
00154 TclModelBuilder_addCyclicModel(ClientData clientData, Tcl_Interp *interp,
00155                                     int argc, TCL_Char **argv);                     
00156 int 
00157 TclModelBuilder_addDamageModel(ClientData clientData, Tcl_Interp *interp,
00158                                int argc, TCL_Char **argv);      
00159 
00160 int
00161 TclModelBuilder_addPattern(ClientData clientData, Tcl_Interp *interp, int argc,
00162                            TCL_Char **argv);
00163 
00164 int
00165 TclModelBuilder_addPattern(ClientData clientData, Tcl_Interp *interp, int argc,   
00166                            TCL_Char **argv);
00167 
00168 int
00169 TclModelBuilder_addSeries(ClientData clientData, Tcl_Interp *interp, int argc,   
00170                           TCL_Char **argv);
00171 
00172 int
00173 TclModelBuilder_addHomogeneousBC(ClientData clientData, Tcl_Interp *interp, int argc,
00174                                  TCL_Char **argv);
00175 int
00176 TclModelBuilder_addHomogeneousBC_X(ClientData clientData, Tcl_Interp *interp, int argc,
00177                                    TCL_Char **argv);
00178 int
00179 TclModelBuilder_addHomogeneousBC_Y(ClientData clientData, Tcl_Interp *interp, int argc,
00180                                    TCL_Char **argv);
00181 int
00182 TclModelBuilder_addHomogeneousBC_Z(ClientData clientData, Tcl_Interp *interp, int argc,
00183                                    TCL_Char **argv);
00184 int
00185 TclModelBuilder_addEqualDOF_MP (ClientData clientData, Tcl_Interp *interp,
00186                                 int argc, TCL_Char **argv);
00187 
00188 int
00189 TclModelBuilder_addMP(ClientData clientData, Tcl_Interp *interp, int argc,   
00190                       TCL_Char **argv);
00191 
00192 int
00193 TclModelBuilder_addNodalLoad(ClientData clientData, Tcl_Interp *interp, int argc,   
00194                              TCL_Char **argv);
00195 
00196 int
00197 TclModelBuilder_addElementalLoad(ClientData clientData, Tcl_Interp *interp, int argc,   
00198                                  TCL_Char **argv);
00199 
00200 int
00201 TclModelBuilder_addNodalMass(ClientData clientData, Tcl_Interp *interp, int argc,   
00202                              TCL_Char **argv);
00203 int
00204 TclModelBuilder_addSP(ClientData clientData, Tcl_Interp *interp, int argc,   
00205                       TCL_Char **argv);
00206 
00207 int
00208 TclModelBuilder_addImposedMotionSP(ClientData clientData, 
00209                                    Tcl_Interp *interp, 
00210                                    int argc,    
00211                                    TCL_Char **argv);    
00212 // Added by Scott J. Brandenberg
00213 int
00214 TclModelBuilder_doPySimple1Gen(ClientData clientData, Tcl_Interp *interp, int argc,
00215                           TCL_Char **argv);
00216 
00217 int
00218 TclModelBuilder_doTzSimple1Gen(ClientData clientData, Tcl_Interp *interp, int argc,
00219                           TCL_Char **argv);
00220 // End added by SJB
00221 
00222 int
00223 TclModelBuilder_doBlock2D(ClientData clientData, Tcl_Interp *interp, int argc, 
00224                           TCL_Char **argv);
00225 
00226 int
00227 TclModelBuilder_doBlock3D(ClientData clientData, Tcl_Interp *interp, int argc, 
00228                           TCL_Char **argv);
00229 
00230 int
00231 TclModelBuilder_addRemoPatch(ClientData clientData, 
00232                              Tcl_Interp *interp, 
00233                              int argc,   
00234                              TCL_Char **argv);  
00235 
00236 int
00237 TclModelBuilder_addRemoLayer(ClientData clientData, 
00238                              Tcl_Interp *interp, 
00239                              int argc,   
00240                              TCL_Char **argv);   
00241                                
00242 int
00243 TclModelBuilder_addRemoFiber(ClientData clientData, 
00244                              Tcl_Interp *interp, 
00245                              int argc,    
00246                              TCL_Char **argv);   
00247 
00248 int
00249 TclModelBuilder_addRemoGeomTransf(ClientData clientData, 
00250                                   Tcl_Interp *interp, 
00251                                   int argc,   
00252                                   TCL_Char **argv); 
00253 
00254 #ifdef OO_HYSTERETIC
00255 int
00256 TclModelBuilder_addStiffnessDegradation(ClientData clientData,
00257                                         Tcl_Interp *interp,
00258                                         int argc, TCL_Char **argv);
00259 
00260 int
00261 TclModelBuilder_addUnloadingRule(ClientData clientData,
00262                                  Tcl_Interp *interp,
00263                                  int argc, TCL_Char **argv);
00264 
00265 int
00266 TclModelBuilder_addStrengthDegradation(ClientData clientData,
00267                                        Tcl_Interp *interp,
00268                                        int argc, TCL_Char **argv);
00269 
00270 int
00271 TclModelBuilder_addHystereticBackbone(ClientData clientData,
00272                                       Tcl_Interp *interp,
00273                                       int argc, TCL_Char **argv);
00274 #endif
00275 
00276 int
00277 TclModelBuilder_addGroundMotion(ClientData clientData, 
00278                                 Tcl_Interp *interp, 
00279                                 int argc,    
00280                                 TCL_Char **argv);
00281 
00283 int
00284 TclModelBuilder_UpdateMaterialStage(ClientData clientData, 
00285                                     Tcl_Interp *interp,  
00286                                     int argc,
00287                                     TCL_Char **argv);
00288                            
00289 
00291 int
00292 TclModelBuilder_UpdateParameter(ClientData clientData, 
00293                                     Tcl_Interp *interp,  
00294                                     int argc, 
00295                                     TCL_Char **argv);
00296 
00297 // REMO
00298 extern int
00299 TclModelBuilder_addPatch (ClientData clientData, Tcl_Interp *interp,
00300                           int argc, TCL_Char **argv,
00301                           TclModelBuilder *theTclBuilder);
00302 
00303                           
00304 extern int
00305 TclModelBuilder_addFiber (ClientData clientData, Tcl_Interp *interp,
00306                           int argc, TCL_Char **argv,
00307                           TclModelBuilder *theTclBuilder);
00308                           
00309 
00310 extern int
00311 TclModelBuilder_addReinfLayer (ClientData clientData, Tcl_Interp *interp,
00312                                int argc, TCL_Char **argv,
00313                                TclModelBuilder *theTclBuilder);
00314 
00315 
00316 extern int
00317 TclModelBuilder_addGeomTransf(ClientData, Tcl_Interp *, int, TCL_Char **,
00318                               Domain*, TclModelBuilder *);   
00319         
00320 
00321 #ifdef _LIMITSTATEMATERIAL
00322 extern int
00323 Tcl_AddLimitCurveCommand(Tcl_Interp *interp, Domain *theDomain);
00324 
00325 extern int
00326 Tcl_RemoveLimitCurve(Tcl_Interp *interp);
00327 #endif
00328 
00329 
00330 
00331 int
00332 TclModelBuilder_Package(ClientData clientData, Tcl_Interp *interp, int argc, 
00333                           TCL_Char **argv);
00334 
00335 //
00336 // CLASS CONSTRUCTOR & DESTRUCTOR
00337 //
00338 
00339 // constructor: the constructor will add certain commands to the interpreter
00340 TclModelBuilder::TclModelBuilder(Domain &theDomain, Tcl_Interp *interp, int NDM, int NDF)
00341   :ModelBuilder(theDomain), ndm(NDM), ndf(NDF), theInterp(interp)
00342 {
00343   theUniaxialMaterials = new ArrayOfTaggedObjects(32);
00344   theNDMaterials = new ArrayOfTaggedObjects(32);
00345   theSections  = new ArrayOfTaggedObjects(32);
00346   theSectionRepresents = new ArrayOfTaggedObjects(32);  
00347   the2dGeomTransfs = new ArrayOfTaggedObjects(32);  
00348   the3dGeomTransfs = new ArrayOfTaggedObjects(32);  
00349 #ifdef OO_HYSTERETIC
00350   theStiffnessDegradations = new ArrayOfTaggedObjects(32);
00351   theUnloadingRules = new ArrayOfTaggedObjects(32);
00352   theStrengthDegradations = new ArrayOfTaggedObjects(32);
00353   theHystereticBackbones= new ArrayOfTaggedObjects(32);
00354 #endif
00355   theYieldSurface_BCs = new ArrayOfTaggedObjects(32);
00356   theCycModels = new ArrayOfTaggedObjects(32); 
00357   theDamageModels = new ArrayOfTaggedObjects(32); 
00358   theYS_EvolutionModels = new ArrayOfTaggedObjects(32);
00359   thePlasticMaterials = new ArrayOfTaggedObjects(32);
00360 
00361   SP_ConstraintIter &theSPs = theDomain.getSPs();
00362   SP_Constraint *theSP;
00363   while ((theSP = theSPs()) != 0) {
00364     int spTag = theSP->getTag();
00365     if (spTag >= currentSpTag)
00366       currentSpTag = spTag+1;
00367   }    
00368 
00369   // call Tcl_CreateCommand for class specific commands
00370   Tcl_CreateCommand(interp, "parameter", TclModelBuilder_addParameter,
00371                     (ClientData)NULL, NULL);
00372 
00373   Tcl_CreateCommand(interp, "addToParameter", TclModelBuilder_addParameter,
00374                     (ClientData)NULL, NULL);
00375 
00376   Tcl_CreateCommand(interp, "updateParameter", TclModelBuilder_addParameter,
00377                     (ClientData)NULL, NULL);
00378 
00379   Tcl_CreateCommand(interp, "node", TclModelBuilder_addNode,
00380                     (ClientData)NULL, NULL);
00381 
00382   Tcl_CreateCommand(interp, "element", TclModelBuilder_addElement,
00383                     (ClientData)NULL, NULL);
00384 
00385   Tcl_CreateCommand(interp, "uniaxialMaterial", TclModelBuilder_addUniaxialMaterial,
00386                     (ClientData)NULL, NULL);
00387   
00388   Tcl_CreateCommand(interp, "nDMaterial", TclModelBuilder_addNDMaterial,
00389                     (ClientData)NULL, NULL);
00390 
00391   Tcl_CreateCommand(interp, "section", TclModelBuilder_addSection,
00392                     (ClientData)NULL, NULL);
00393 
00394   Tcl_CreateCommand(interp, "yieldSurface_BC", TclModelBuilder_addYieldSurface_BC,
00395                     (ClientData)NULL, NULL);
00396 
00397   Tcl_CreateCommand(interp, "ysEvolutionModel", TclModelBuilder_addYS_EvolutionModel,
00398                     (ClientData)NULL, NULL);
00399 
00400   Tcl_CreateCommand(interp, "plasticMaterial", TclModelBuilder_addYS_PlasticMaterial,
00401                     (ClientData)NULL, NULL);
00402 
00403   Tcl_CreateCommand(interp, "cyclicModel", TclModelBuilder_addCyclicModel,
00404                     (ClientData)NULL, NULL); 
00405 
00406   Tcl_CreateCommand(interp, "damageModel", TclModelBuilder_addDamageModel,
00407                     (ClientData)NULL, NULL); 
00408 
00409   Tcl_CreateCommand(interp, "pattern", TclModelBuilder_addPattern,
00410                     (ClientData)NULL, NULL);
00411 
00412   Tcl_CreateCommand(interp, "load", TclModelBuilder_addNodalLoad,
00413                     (ClientData)NULL, NULL);
00414 
00415   Tcl_CreateCommand(interp, "eleLoad", TclModelBuilder_addElementalLoad,
00416                     (ClientData)NULL, NULL);
00417 
00418   Tcl_CreateCommand(interp, "mass", TclModelBuilder_addNodalMass,
00419                     (ClientData)NULL, NULL);
00420 
00421   Tcl_CreateCommand(interp, "fix", TclModelBuilder_addHomogeneousBC,
00422                     (ClientData)NULL, NULL);
00423 
00424   Tcl_CreateCommand(interp, "fixX", TclModelBuilder_addHomogeneousBC_X,
00425                     (ClientData)NULL, NULL);
00426 
00427   Tcl_CreateCommand(interp, "fixY", TclModelBuilder_addHomogeneousBC_Y,
00428                     (ClientData)NULL, NULL);
00429 
00430   Tcl_CreateCommand(interp, "fixZ", TclModelBuilder_addHomogeneousBC_Z,
00431                     (ClientData)NULL, NULL);
00432 
00433   Tcl_CreateCommand(interp, "sp", TclModelBuilder_addSP,
00434                     (ClientData)NULL, NULL);
00435   
00436   Tcl_CreateCommand(interp, "imposedMotion", 
00437                     TclModelBuilder_addImposedMotionSP,
00438                     (ClientData)NULL, NULL);  
00439 
00440   Tcl_CreateCommand(interp, "imposedSupportMotion", 
00441                     TclModelBuilder_addImposedMotionSP,
00442                     (ClientData)NULL, NULL);  
00443   
00444   Tcl_CreateCommand(interp, "groundMotion", 
00445                     TclModelBuilder_addGroundMotion,
00446                     (ClientData)NULL, NULL);    
00447 
00448   Tcl_CreateCommand(interp, "equalDOF", TclModelBuilder_addEqualDOF_MP,
00449                     (ClientData)NULL, NULL);
00450 
00451   Tcl_CreateCommand(interp, "mp", TclModelBuilder_addMP,
00452                     (ClientData)NULL, NULL);
00453 
00454   // Added by Scott J. Brandenberg
00455   Tcl_CreateCommand(interp, "PySimple1Gen", TclModelBuilder_doPySimple1Gen,
00456                         (ClientData)NULL, NULL);
00457   Tcl_CreateCommand(interp, "TzSimple1Gen", TclModelBuilder_doTzSimple1Gen,
00458                         (ClientData)NULL, NULL);
00459   // End added by SJB
00460 
00461   Tcl_CreateCommand(interp, "block2D", TclModelBuilder_doBlock2D,
00462                     (ClientData)NULL, NULL);
00463 
00464   Tcl_CreateCommand(interp, "block3D", TclModelBuilder_doBlock3D,
00465                     (ClientData)NULL, NULL);
00466 
00467   Tcl_CreateCommand(interp, "patch", TclModelBuilder_addRemoPatch,
00468                     (ClientData)NULL, NULL);  
00469 
00470   Tcl_CreateCommand(interp, "layer", TclModelBuilder_addRemoLayer,
00471                     (ClientData)NULL, NULL);    
00472   
00473   Tcl_CreateCommand(interp, "fiber", TclModelBuilder_addRemoFiber,
00474                     (ClientData)NULL, NULL);    
00475 
00476   Tcl_CreateCommand(interp, "geomTransf", TclModelBuilder_addRemoGeomTransf,
00477                     (ClientData)NULL, NULL);    
00478 
00479 #ifdef OO_HYSTERETIC
00480   Tcl_CreateCommand(interp, "stiffnessDegradation",
00481                     TclModelBuilder_addStiffnessDegradation,
00482                     (ClientData)NULL, NULL);
00483 
00484   Tcl_CreateCommand(interp, "unloadingRule",
00485                     TclModelBuilder_addUnloadingRule,
00486                     (ClientData)NULL, NULL);
00487 
00488   Tcl_CreateCommand(interp, "strengthDegradation",
00489                     TclModelBuilder_addStrengthDegradation,
00490                     (ClientData)NULL, NULL);
00491   
00492   Tcl_CreateCommand(interp, "hystereticBackbone",
00493                     TclModelBuilder_addHystereticBackbone,
00494                     (ClientData)NULL, NULL);
00495 #endif
00496 
00498   Tcl_CreateCommand(interp, "updateMaterialStage", 
00499                     TclModelBuilder_UpdateMaterialStage,
00500                     (ClientData)NULL, NULL);
00501   
00503   //Tcl_CreateCommand(interp, "updateParameter", 
00504   //                TclModelBuilder_UpdateParameter,
00505   //        (ClientData)NULL, NULL);
00506 
00507 
00508 
00509 #ifdef _LIMITSTATEMATERIAL
00511   Tcl_AddLimitCurveCommand(interp, &theDomain);
00512 #endif
00513 
00514   Tcl_CreateCommand(interp, "loadPackage", TclModelBuilder_Package,
00515                     (ClientData)NULL, NULL);
00516 
00517 
00518   // set the static pointers in this file
00519   theTclBuilder = this;
00520   theTclDomain = &theDomain;
00521   theTclLoadPattern = 0;
00522   theTclMultiSupportPattern = 0;  
00523 
00524   nodeLoadTag = 0;
00525   eleArgStart = 0;
00526 }
00527 
00528 TclModelBuilder::~TclModelBuilder()
00529 {
00530   currentSpTag = 0;
00531 
00532   theUniaxialMaterials->clearAll();
00533   theNDMaterials->clearAll();
00534   theSections->clearAll(); 
00535   theSectionRepresents->clearAll();
00536   the2dGeomTransfs->clearAll();
00537   the3dGeomTransfs->clearAll();
00538   theYieldSurface_BCs->clearAll();
00539   theYS_EvolutionModels->clearAll();
00540   thePlasticMaterials->clearAll();
00541   theCycModels->clearAll();
00542   theDamageModels->clearAll();
00543   
00544 #ifdef OO_HYSTERETIC
00545   theStiffnessDegradations->clearAll();
00546   theUnloadingRules->clearAll();
00547   theStrengthDegradations->clearAll();
00548   theHystereticBackbones->clearAll();
00549 #endif
00550 
00551   // free up memory allocated in the constructor
00552   delete theUniaxialMaterials;
00553   delete theNDMaterials;
00554   delete theSections;
00555   delete theSectionRepresents;
00556   delete the2dGeomTransfs;
00557   delete the3dGeomTransfs;
00558   delete theYieldSurface_BCs;
00559   delete theYS_EvolutionModels;
00560   delete thePlasticMaterials;
00561   delete theCycModels;
00562   delete theDamageModels;
00563 
00564 #ifdef OO_HYSTERETIC
00565   delete theStiffnessDegradations;
00566   delete theUnloadingRules;
00567   delete theStrengthDegradations;
00568   delete theHystereticBackbones;
00569 #endif
00570 
00571   // set the pointers to 0 
00572   theTclDomain =0;
00573   theTclBuilder =0;
00574   theTclLoadPattern =0;
00575   theTclMultiSupportPattern = 0;  
00576   
00577   // may possibly invoke Tcl_DeleteCommand() later
00578   Tcl_DeleteCommand(theInterp, "parameter");
00579   Tcl_DeleteCommand(theInterp, "addToParameter");
00580   Tcl_DeleteCommand(theInterp, "updateParameter");
00581   Tcl_DeleteCommand(theInterp, "node");
00582   Tcl_DeleteCommand(theInterp, "element");
00583   Tcl_DeleteCommand(theInterp, "uniaxialMaterial");
00584   Tcl_DeleteCommand(theInterp, "nDMaterial");
00585   Tcl_DeleteCommand(theInterp, "section");
00586   Tcl_DeleteCommand(theInterp, "pattern");
00587   Tcl_DeleteCommand(theInterp, "load");
00588   Tcl_DeleteCommand(theInterp, "mass");
00589   Tcl_DeleteCommand(theInterp, "fix");
00590   Tcl_DeleteCommand(theInterp, "fixX");
00591   Tcl_DeleteCommand(theInterp, "fixY");
00592   Tcl_DeleteCommand(theInterp, "fixZ");
00593   Tcl_DeleteCommand(theInterp, "sp");
00594   Tcl_DeleteCommand(theInterp, "imposedSupportMotion");
00595   Tcl_DeleteCommand(theInterp, "groundMotion");
00596   Tcl_DeleteCommand(theInterp, "equalDOF");
00597   Tcl_DeleteCommand(theInterp, "mp");
00598   Tcl_DeleteCommand(theInterp, "PySimple1Gen");  // Added by Scott J. Brandenberg
00599   Tcl_DeleteCommand(theInterp, "TzSimple1Gen");  // Added by Scott J. Brandenberg
00600   Tcl_DeleteCommand(theInterp, "block2D");
00601   Tcl_DeleteCommand(theInterp, "block3D");
00602   Tcl_DeleteCommand(theInterp, "patch");
00603   Tcl_DeleteCommand(theInterp, "layer");
00604 
00605   Tcl_DeleteCommand(theInterp, "fiber");
00606   Tcl_DeleteCommand(theInterp, "geomTransf");
00607   Tcl_DeleteCommand(theInterp, "updateMaterialStage");
00608   Tcl_DeleteCommand(theInterp, "updateParameter");
00609 
00610 #ifdef OO_HYSTERETIC
00611   Tcl_DeleteCommand(theInterp, "unloadingRule");
00612   Tcl_DeleteCommand(theInterp, "stiffnessDegradation");
00613   Tcl_DeleteCommand(theInterp, "strengthDegradation");
00614   Tcl_DeleteCommand(theInterp, "hystereticBackbone");
00615 #endif
00616 
00617 #ifdef _LIMITSTATE
00618   Tcl_removeLimitCurve(Tcl_Interp *interp);
00619 #endif
00620 }
00621 
00622 
00623 //
00624 // CLASS METHODS
00625 //
00626 
00627 int 
00628 TclModelBuilder::buildFE_Model(void)
00629 {
00630   // does nothing
00631   return 0;
00632 }
00633 
00634 int 
00635 TclModelBuilder::getNDM(void) const
00636 {
00637   return ndm;
00638 }
00639 
00640 int 
00641 TclModelBuilder::getNDF(void) const
00642 {
00643   return ndf;
00644 }
00645 
00646 #ifdef OO_HYSTERETIC
00647 int
00648 TclModelBuilder::addStiffnessDegradation(StiffnessDegradation &theDegr)
00649 {
00650   bool result = theStiffnessDegradations->addComponent(&theDegr);
00651   if (result == true)
00652     return 0;
00653   else {
00654     opserr << "TclModelBuilder::addStiffnessDegradation() - failed to add StiffnessDegradation: " << theDegr;
00655     return -1;
00656   }
00657 }
00658 
00659 StiffnessDegradation*
00660 TclModelBuilder::getStiffnessDegradation(int tag)
00661 {
00662   TaggedObject *mc = theStiffnessDegradations->getComponentPtr(tag);
00663   if (mc == 0) 
00664     return 0;
00665 
00666   // do a cast and return
00667   StiffnessDegradation *result = (StiffnessDegradation *)mc;
00668   return result;
00669 }
00670 
00671 int
00672 TclModelBuilder::addUnloadingRule(UnloadingRule &theDegr)
00673 {
00674   bool result = theUnloadingRules->addComponent(&theDegr);
00675   if (result == true)
00676     return 0;
00677   else {
00678     opserr << "TclModelBuilder::addUnloadingRule() - failed to add UnloadingRule: " << theDegr;
00679     return -1;
00680   }
00681 }
00682 
00683 UnloadingRule*
00684 TclModelBuilder::getUnloadingRule(int tag)
00685 {
00686   TaggedObject *mc = theUnloadingRules->getComponentPtr(tag);
00687   if (mc == 0) 
00688     return 0;
00689 
00690   // do a cast and return
00691   UnloadingRule *result = (UnloadingRule *)mc;
00692   return result;
00693 }
00694 
00695 int
00696 TclModelBuilder::addStrengthDegradation(StrengthDegradation &theDegr)
00697 {
00698   bool result = theStrengthDegradations->addComponent(&theDegr);
00699   if (result == true)
00700     return 0;
00701   else {
00702     opserr << "TclModelBuilder::addStrengthDegradation() - failed to add StrengthDegradation: " << theDegr;
00703     return -1;
00704   }
00705 }
00706 
00707 StrengthDegradation*
00708 TclModelBuilder::getStrengthDegradation(int tag)
00709 {
00710   TaggedObject *mc = theStrengthDegradations->getComponentPtr(tag);
00711   if (mc == 0) 
00712     return 0;
00713 
00714   // do a cast and return
00715   StrengthDegradation *result = (StrengthDegradation *)mc;
00716   return result;
00717 }
00718 
00719 int
00720 TclModelBuilder::addHystereticBackbone(HystereticBackbone &theBackbone)
00721 {
00722   bool result = theHystereticBackbones->addComponent(&theBackbone);
00723   if (result == true)
00724     return 0;
00725   else {
00726     opserr << "TclModelBuilder::addBackbone() - failed to add Backbone: " << theBackbone;
00727     return -1;
00728   }
00729 }
00730 
00731 HystereticBackbone*
00732 TclModelBuilder::getHystereticBackbone(int tag)
00733 {
00734   TaggedObject *mc = theHystereticBackbones->getComponentPtr(tag);
00735   if (mc == 0) 
00736     return 0;
00737 
00738   // do a cast and return
00739   HystereticBackbone *result = (HystereticBackbone *)mc;
00740   return result;
00741 }
00742 #endif
00743 
00744 int 
00745 TclModelBuilder::addUniaxialMaterial(UniaxialMaterial &theMaterial)
00746 {
00747   bool result = theUniaxialMaterials->addComponent(&theMaterial);
00748   if (result == true)
00749     return 0;
00750   else {
00751     opserr << "TclModelBuilder::addUniaxialMaterial() - failed to add material: " << theMaterial;
00752     return -1;
00753   }
00754 }
00755 
00756 
00757 UniaxialMaterial *
00758 TclModelBuilder::getUniaxialMaterial(int tag)
00759 {
00760   TaggedObject *mc = theUniaxialMaterials->getComponentPtr(tag);
00761   if (mc == 0) 
00762     return 0;
00763 
00764   // otherweise we do a cast and return
00765   UniaxialMaterial *result = (UniaxialMaterial *)mc;
00766   return result;
00767 }
00768 
00769 int 
00770 TclModelBuilder::addNDMaterial(NDMaterial &theMaterial)
00771 {
00772   bool result = theNDMaterials->addComponent(&theMaterial);
00773   if (result == true)
00774     return 0;
00775   else {
00776     opserr << "TclModelBuilder::addNDMaterial() - failed to add material: " << theMaterial;
00777     return -1;
00778   }
00779 }
00780 
00781 
00782 NDMaterial *
00783 TclModelBuilder::getNDMaterial(int tag)
00784 {
00785   TaggedObject *mc = theNDMaterials->getComponentPtr(tag);
00786   if (mc == 0) 
00787     return 0;
00788 
00789   // otherweise we do a cast and return
00790   NDMaterial *result = (NDMaterial *)mc;
00791   return result;
00792 }
00793 
00794 int 
00795 TclModelBuilder::addSection(SectionForceDeformation &theSection)
00796 {
00797   bool result = theSections->addComponent(&theSection);
00798   if (result == true)
00799     return 0;
00800   else {
00801     opserr << "TclModelBuilder::addSection() - failed to add section: " << theSection;
00802     return -1;
00803   }
00804 }
00805 
00806 
00807 
00808 SectionForceDeformation *
00809 TclModelBuilder::getSection(int tag)
00810 {
00811   TaggedObject *mc = theSections->getComponentPtr(tag);
00812   if (mc == 0) 
00813     return 0;
00814 
00815   // do a cast and return
00816   SectionForceDeformation *result = (SectionForceDeformation *)mc;
00817   return result;
00818 }
00819 
00820 int
00821 TclModelBuilder::addYS_EvolutionModel(YS_Evolution &theModel)
00822 {
00823   bool result = theYS_EvolutionModels->addComponent(&theModel);
00824   if (result == true)
00825     return 0;
00826   else {
00827     opserr << "TclModelBuilder::addYS_EvolutionModel() - failed to add model " << theModel;
00828     return -1;
00829   }
00830 }
00831 
00832 
00833 YS_Evolution *
00834 TclModelBuilder::getYS_EvolutionModel(int tag)
00835 {
00836   TaggedObject *mc = theYS_EvolutionModels->getComponentPtr(tag);
00837   if (mc == 0)
00838     return 0;
00839 
00840   // otherweise we do a cast and return
00841   YS_Evolution *result = (YS_Evolution *)mc;
00842   return result;
00843 }
00844 
00845 int
00846 TclModelBuilder::addYieldSurface_BC(YieldSurface_BC &theYS)
00847 {
00848 //      TaggedObject *mc = &theYS;
00849 
00850   bool result = theYieldSurface_BCs->addComponent(&theYS);
00851   if (result == true)
00852     return 0;
00853   else {
00854     opserr << "TclModelBuilder::addYieldSurfaceBC() - failed to add YS: " << theYS;
00855     return -1;
00856   }
00857 }
00858 
00859 int 
00860 TclModelBuilder::addCyclicModel(CyclicModel &theCM)
00861 {
00862 //      TaggedObject *mc = &theYS;
00863 
00864   bool result = theCycModels->addComponent(&theCM);
00865   if (result == true)
00866     return 0;
00867   else {
00868     opserr << "TclModelBuilder::addCyclicModel() - failed to add : " << theCM;
00869     return -1;
00870   }
00871 }
00872 
00873 YieldSurface_BC *
00874 TclModelBuilder::getYieldSurface_BC(int tag)
00875 {
00876   TaggedObject *mc = theYieldSurface_BCs->getComponentPtr(tag);
00877   if (mc == 0)
00878     return 0;
00879 
00880   // otherweise we do a cast and return
00881   YieldSurface_BC *result = (YieldSurface_BC *)mc;
00882   return result;
00883 }
00884 
00885 CyclicModel * 
00886 TclModelBuilder::getCyclicModel(int tag)
00887 {
00888   TaggedObject *mc = theCycModels->getComponentPtr(tag);
00889   if (mc == 0)
00890     return 0;
00891 
00892   // otherweise we do a cast and return
00893   CyclicModel *result = (CyclicModel *)mc;
00894   return result;
00895 }
00896 
00897 int
00898 TclModelBuilder::addPlasticMaterial(PlasticHardeningMaterial &theMat)
00899 {
00900 //      TaggedObject *mc = &theYS;
00901 
00902   bool result = thePlasticMaterials->addComponent(&theMat);
00903   if (result == true)
00904     return 0;
00905   else {
00906     opserr << "TclModelBuilder::addPlasticMaterial() - failed to add Material: " << theMat;
00907     return -1;
00908   }
00909 }
00910 
00911 PlasticHardeningMaterial *
00912 TclModelBuilder::getPlasticMaterial(int tag)
00913 {
00914   TaggedObject *mc = thePlasticMaterials->getComponentPtr(tag);
00915   if (mc == 0)
00916     return 0;
00917 
00918   // otherweise we do a cast and return
00919   PlasticHardeningMaterial *result = (PlasticHardeningMaterial *)mc;
00920   return result;
00921 }
00922 
00923 int 
00924 TclModelBuilder::addSectionRepres(SectionRepres &theSectionRepres)
00925 {
00926   bool result = theSectionRepresents->addComponent(&theSectionRepres);
00927 
00928   if (result == true)
00929     return 0;
00930   else {
00931       opserr << "TclModelBuilder::addSectionRepres() - failed to add SectionRepres\n";
00932       return -1;
00933   }
00934 }
00935 
00936 
00937 SectionRepres *
00938 TclModelBuilder::getSectionRepres(int tag)
00939 {
00940   TaggedObject *mc = theSectionRepresents->getComponentPtr(tag);
00941   if (mc == 0) return 0;
00942   SectionRepres *result = (SectionRepres *)mc;
00943   return result;
00944 }
00945 
00946 
00947 
00948 int 
00949 TclModelBuilder::addCrdTransf2d(CrdTransf2d &theCrdTransf)
00950 {
00951   bool result = the2dGeomTransfs->addComponent(&theCrdTransf);
00952   if (result == true)
00953     return 0;
00954   else {
00955     opserr << "TclModelBuilder::addCrdTransf() - failed to add crdTransf: " << theCrdTransf;
00956     return -1;
00957   }
00958 }
00959 
00960 
00961 int 
00962 TclModelBuilder::addCrdTransf3d(CrdTransf3d &theCrdTransf)
00963 {
00964   bool result = the3dGeomTransfs->addComponent(&theCrdTransf);
00965   if (result == true)
00966     return 0;
00967   else {
00968     opserr << "TclModelBuilder::addCrdTransf() - failed to add crdTransf: " << theCrdTransf;
00969     return -1;
00970   }
00971 }
00972 
00973 
00974 
00975 CrdTransf2d *
00976 TclModelBuilder::getCrdTransf2d(int tag)
00977 {
00978   TaggedObject *mc = the2dGeomTransfs->getComponentPtr(tag);
00979   if (mc == 0) 
00980     return 0;
00981 
00982   // do a cast and return
00983   CrdTransf2d *result = (CrdTransf2d *)mc;
00984   return result;
00985 }
00986 
00987 
00988 CrdTransf3d *
00989 TclModelBuilder::getCrdTransf3d(int tag)
00990 {
00991   TaggedObject *mc = the3dGeomTransfs->getComponentPtr(tag);
00992   if (mc == 0) 
00993     return 0;
00994 
00995   // do a cast and return
00996   CrdTransf3d *result = (CrdTransf3d *)mc;
00997   return result;
00998 }
00999 
01000 //
01001 // THE FUNCTIONS INVOKED BY THE INTERPRETER
01002 //
01003 
01004 void printCommand(int argc, TCL_Char **argv)
01005 {
01006   opserr << "Input command: ";
01007   for (int i=0; i<argc; i++)
01008     opserr << argv[i] << " ";
01009   opserr << endln;
01010 } 
01011 
01012 int
01013 TclModelBuilder_addNode(ClientData clientData, Tcl_Interp *interp, int argc, 
01014                         TCL_Char **argv)
01015 {
01016 
01017   // ensure the destructor has not been called - 
01018   if (theTclBuilder == 0) {
01019     opserr << "WARNING builder has been destroyed" << endln;
01020     return TCL_ERROR;
01021   }
01022 
01023   int ndm = theTclBuilder->getNDM();
01024   int ndf = theTclBuilder->getNDF();
01025 
01026   // make sure corect number of arguments on command line
01027   if (argc < 2+ndm) {
01028     opserr << "WARNING insufficient arguments\n";
01029     printCommand(argc, argv);
01030     opserr << "Want: node nodeTag? [ndm coordinates?] <-mass [ndf values?]>\n";
01031     return TCL_ERROR;
01032   }    
01033 
01034   Node *theNode = 0;
01035 
01036   // get the nodal id
01037   int nodeId;
01038   if (Tcl_GetInt(interp, argv[1], &nodeId) != TCL_OK) {
01039     opserr << "WARNING invalid nodeTag\n";
01040     opserr << "Want: node nodeTag? [ndm coordinates?] <-mass [ndf values?]>\n";
01041     return TCL_ERROR;
01042   }
01043 
01044   // read in the coordinates and create the node
01045   double xLoc, yLoc, zLoc;
01046   if (ndm == 1) { 
01047     // create a node in 1d space
01048     if (Tcl_GetDouble(interp, argv[2], &xLoc) != TCL_OK) {
01049       opserr << "WARNING invalid XCoordinate\n";
01050       opserr << "node: " << nodeId << endln;
01051       return TCL_ERROR;
01052     }
01053     theNode = new Node(nodeId,ndf,xLoc);
01054   } 
01055 
01056   else if (ndm == 2) { 
01057     // create a node in 2d space
01058     if (Tcl_GetDouble(interp, argv[2], &xLoc) != TCL_OK) {
01059       opserr << "WARNING invalid XCoordinate\n";
01060       opserr << "node: " << nodeId << endln;
01061       return TCL_ERROR;
01062     }
01063     if (Tcl_GetDouble(interp, argv[3], &yLoc) != TCL_OK) {
01064       opserr << "WARNING invalid YCoordinate\n";
01065       opserr << "node: " << nodeId << endln;
01066       return TCL_ERROR;
01067     }
01068     theNode = new Node(nodeId,ndf,xLoc,yLoc);
01069   } 
01070 
01071   else if (ndm == 3) { 
01072     // create a node in 3d space
01073     if (Tcl_GetDouble(interp, argv[2], &xLoc) != TCL_OK) {
01074       opserr << "WARNING invalid XCoordinate\n";
01075       opserr << "node: " << nodeId << endln;
01076       return TCL_ERROR;
01077     }
01078     if (Tcl_GetDouble(interp, argv[3], &yLoc) != TCL_OK) {
01079       opserr << "WARNING invalid YCoordinate\n";
01080       opserr << "node: " << nodeId << endln;
01081       return TCL_ERROR;
01082     }
01083     if (Tcl_GetDouble(interp, argv[4], &zLoc) != TCL_OK) {
01084       opserr << "WARNING invalid ZCoordinate\n";
01085       opserr << "node: " << nodeId << endln;
01086       return TCL_ERROR;
01087     }
01088     theNode = new Node(nodeId,ndf,xLoc,yLoc,zLoc);
01089   } else {
01090       opserr << "WARNING invalid ndm\n";
01091       opserr << "node: " << nodeId << endln;;
01092       return TCL_ERROR;
01093   }
01094 
01095   if (theNode == 0) {
01096     opserr << "WARNING ran out of memory creating node\n";
01097     opserr << "node: " << nodeId << endln;
01098     return TCL_ERROR;
01099   }
01100 
01101   if (theTclDomain->addNode(theNode) == false) {
01102     opserr << "WARNING failed to add node to the domain\n";
01103     opserr << "node: " << nodeId << endln;
01104     delete theNode; // otherwise memory leak
01105     return TCL_ERROR;
01106   }
01107 
01108   // check for mass terms
01109   if (argc > 2+ndm) {
01110     if (strcmp(argv[2+ndm],"-mass") == 0) {
01111       if (argc < 3+ndm+ndf) {
01112         opserr << "WARNING incorrect number of nodal mass terms\n";
01113         opserr << "node: " << nodeId << endln;
01114         return TCL_ERROR;      
01115       } 
01116       Matrix mass(ndf,ndf);
01117       double theMass;
01118       for (int i=0; i<ndf; i++) {
01119         if (Tcl_GetDouble(interp, argv[i+3+ndm], &theMass) != TCL_OK) {
01120           opserr << "WARNING invalid nodal mass term\n";
01121           opserr << "node: " << nodeId << ", dof: " << i+1 << endln;
01122           return TCL_ERROR;
01123         }
01124         mass(i,i) = theMass;
01125       }
01126       theNode->setMass(mass);      
01127     }
01128   }
01129 
01130   // if get here we have sucessfully created the node and added it to the domain
01131   return TCL_OK;
01132 }
01133 
01134 
01135 
01136 
01137 
01138 // the function for creating ne material objects and patterns is in a seperate file.
01139 // this allows new material and patternobjects to be added without touching this file.
01140 // does so at the expense of an extra procedure call.
01141 
01142 extern int 
01143 TclModelBuilderParameterCommand(ClientData clientData, 
01144                                 Tcl_Interp *interp, int argc,    
01145                                 TCL_Char **argv, 
01146                                 Domain *theDomain, TclModelBuilder *theTclBuilder);
01147 int
01148 TclModelBuilder_addParameter(ClientData clientData, Tcl_Interp *interp, 
01149                              int argc, TCL_Char **argv)
01150                           
01151 {
01152   return TclModelBuilderParameterCommand(clientData, interp, 
01153                                          argc, argv, theTclDomain, theTclBuilder);
01154 }
01155 
01156 
01157 extern int 
01158 TclModelBuilderElementCommand(ClientData clientData, 
01159                               Tcl_Interp *interp, int argc,    
01160                               TCL_Char **argv, 
01161                               Domain *theDomain, TclModelBuilder *theTclBuilder);
01162 int
01163 TclModelBuilder_addElement(ClientData clientData, Tcl_Interp *interp, 
01164                            int argc,    TCL_Char **argv)
01165                           
01166 {
01167   return TclModelBuilderElementCommand(clientData, interp, 
01168                                        argc, argv, theTclDomain, theTclBuilder);
01169 }
01170 
01171 
01172 extern int
01173 TclModelBuilderUniaxialMaterialCommand (ClientData clienData, Tcl_Interp *interp, int argc,
01174                                  TCL_Char **argv, TclModelBuilder *theTclBuilder, Domain *theDomain);
01175 
01176 int
01177 TclModelBuilder_addUniaxialMaterial(ClientData clientData, Tcl_Interp *interp, 
01178                                     int argc, TCL_Char **argv)
01179                           
01180 {
01181   return TclModelBuilderUniaxialMaterialCommand(clientData, interp, 
01182                                                 argc, argv, theTclBuilder, theTclDomain);
01183 }
01184 
01185 extern int
01186 TclModelBuilderNDMaterialCommand (ClientData clienData, Tcl_Interp *interp, int argc,
01187                                   TCL_Char **argv, TclModelBuilder *theTclBuilder);
01188 
01189 int
01190 TclModelBuilder_addNDMaterial(ClientData clientData, Tcl_Interp *interp, 
01191                             int argc,    TCL_Char **argv)
01192                           
01193 {
01194   return TclModelBuilderNDMaterialCommand(clientData, interp, 
01195                                           argc, argv, theTclBuilder);
01196 }
01197 
01198 extern int
01199 TclModelBuilderSectionCommand (ClientData clienData, Tcl_Interp *interp, int argc,
01200                                   TCL_Char **argv, TclModelBuilder *theTclBuilder);
01201 
01202 int
01203 TclModelBuilder_addSection(ClientData clientData, Tcl_Interp *interp, 
01204                             int argc,    TCL_Char **argv)
01205                           
01206 {
01207   return TclModelBuilderSectionCommand(clientData, interp, 
01208                                        argc, argv, theTclBuilder);
01209 }
01210 
01211 
01212 
01213 extern int
01214 TclModelBuilderYieldSurface_BCCommand (ClientData clienData, Tcl_Interp *interp, int argc,
01215                                  TCL_Char **argv, TclModelBuilder *theTclBuilder);
01216 
01217 int
01218 TclModelBuilder_addYieldSurface_BC(ClientData clientData, Tcl_Interp *interp,
01219                                     int argc, TCL_Char **argv)
01220 
01221 {
01222   return TclModelBuilderYieldSurface_BCCommand(clientData, interp,
01223                                                 argc, argv, theTclBuilder);
01224 }
01225 
01226 extern int
01227 TclModelBuilderYS_EvolutionModelCommand (ClientData clienData, Tcl_Interp *interp, int argc,
01228                                  TCL_Char **argv, TclModelBuilder *theTclBuilder);
01229 
01230 int
01231 TclModelBuilder_addYS_EvolutionModel(ClientData clientData, Tcl_Interp *interp,
01232                                     int argc, TCL_Char **argv)
01233 
01234 {
01235   return TclModelBuilderYS_EvolutionModelCommand(clientData, interp,
01236                                                 argc, argv, theTclBuilder);
01237 }
01238 
01239 extern int
01240 TclModelBuilderPlasticMaterialCommand (ClientData clienData, Tcl_Interp *interp, int argc,
01241                                  TCL_Char **argv, TclModelBuilder *theTclBuilder);
01242 
01243 int
01244 TclModelBuilder_addYS_PlasticMaterial(ClientData clientData, Tcl_Interp *interp,
01245                                     int argc, TCL_Char **argv)
01246 
01247 {
01248   return TclModelBuilderPlasticMaterialCommand(clientData, interp,
01249                                                 argc, argv, theTclBuilder);
01250 }
01251 
01253 extern int TclModelBuilderCyclicModelCommand(ClientData clienData, Tcl_Interp *interp, int argc,
01254                                  TCL_Char **argv, TclModelBuilder *theTclBuilder);
01255 int
01256 TclModelBuilder_addCyclicModel(ClientData clientData, Tcl_Interp *interp,
01257                                     int argc, TCL_Char **argv)
01258 
01259 {
01260   return TclModelBuilderCyclicModelCommand(clientData, interp,
01261                                                 argc, argv, theTclBuilder);
01262 }
01263 
01265 extern int TclModelBuilderDamageModelCommand(ClientData clienData, Tcl_Interp *interp, int argc,
01266                                  TCL_Char **argv, TclModelBuilder *theTclBuilder);
01267 
01268 int
01269 TclModelBuilder_addDamageModel(ClientData clientData, Tcl_Interp *interp,
01270                                     int argc, TCL_Char **argv)
01271 
01272 {
01273   return TclModelBuilderDamageModelCommand(clientData, interp,
01274                                                 argc, argv, theTclBuilder);
01275 }
01276 
01277 extern int
01278 TclPatternCommand(ClientData clientData, Tcl_Interp *interp, 
01279                            int argc, TCL_Char **argv, Domain *theDomain);
01280                            
01281 int
01282 TclModelBuilder_addPattern(ClientData clientData, Tcl_Interp *interp, 
01283                            int argc, TCL_Char **argv)
01284                           
01285 {
01286   return TclPatternCommand(clientData, interp, argc, argv, theTclDomain);
01287 }
01288 
01289 
01290 
01291 
01292 extern int
01293 TclGroundMotionCommand(ClientData clientData, 
01294                        Tcl_Interp *interp, 
01295                        int argc,    
01296                        TCL_Char **argv,
01297                        MultiSupportPattern *thePattern);
01298 
01299 int
01300 TclModelBuilder_addGroundMotion(ClientData clientData, Tcl_Interp *interp, 
01301                            int argc, TCL_Char **argv)
01302                           
01303 {
01304   return TclGroundMotionCommand(clientData, interp, argc, argv, 
01305                                 theTclMultiSupportPattern);
01306 }
01307 
01308 
01309 int
01310 TclModelBuilder_addNodalLoad(ClientData clientData, Tcl_Interp *interp, int argc,   
01311                          TCL_Char **argv)
01312 {
01313   // ensure the destructor has not been called - 
01314   if (theTclBuilder == 0) {
01315     opserr << "WARNING builder has been destroyed - load \n";    
01316     return TCL_ERROR;
01317   }
01318 
01319   int ndf = theTclBuilder->getNDF();
01320 
01321   NodalLoad *theLoad = 0;
01322   
01323   // make sure at least one other argument to contain type of system
01324   if (argc < (2 + ndf)) {
01325     opserr << "WARNING bad command - want: load nodeId " << ndf << " forces\n";
01326     printCommand(argc, argv);
01327     return TCL_ERROR;
01328   }    
01329 
01330   // get the id of the node
01331   int nodeId;
01332   if (Tcl_GetInt(interp, argv[1], &nodeId) != TCL_OK) {
01333     opserr << "WARNING invalid nodeId: " << argv[1];
01334     opserr << " - load nodeId " << ndf << " forces\n";
01335     return TCL_ERROR;
01336   }
01337 
01338   // get the load vector
01339   Vector forces(ndf);
01340   for (int i=0; i<ndf; i++) {
01341     double theForce;
01342     if (Tcl_GetDouble(interp, argv[2+i], &theForce) != TCL_OK) {
01343       opserr << "WARNING invalid force " << i+1 << " - load " << nodeId;
01344       opserr << " " << ndf << " forces\n";
01345       return TCL_ERROR;
01346     } else
01347       forces(i) = theForce;
01348   }
01349 
01350   bool isLoadConst = false;
01351   int loadPatternTag = 123456789; // some pattern that will never be used!
01352 
01353   // allow some additional options at end of command
01354   int endMarker = 2+ndf;
01355   while (endMarker != argc) {
01356     if (strcmp(argv[endMarker],"-const") == 0) {
01357       // allow user to specify const load
01358       isLoadConst = true;
01359     } else if (strcmp(argv[endMarker],"-pattern") == 0) {
01360       // allow user to specify load pattern other than current
01361       endMarker++;
01362       if (endMarker == argc || 
01363           Tcl_GetInt(interp, argv[endMarker], &loadPatternTag) != TCL_OK) {
01364 
01365         opserr << "WARNING invalid patternTag - load " << nodeId << " ";
01366         opserr << ndf << " forces pattern patterntag\n";
01367         return TCL_ERROR;
01368       }
01369     }
01370     endMarker++;
01371   }
01372 
01373   // get the current pattern tag if no tag given in i/p
01374   if (loadPatternTag == 123456789)
01375     if (theTclLoadPattern == 0) {
01376         opserr << "WARNING no current load pattern - load " << nodeId;
01377         opserr << " " << ndf << " forces\n";
01378         return TCL_ERROR;
01379     } else 
01380         loadPatternTag = theTclLoadPattern->getTag();
01381 
01382   // create the load
01383   theLoad = new NodalLoad(nodeLoadTag, nodeId, forces, isLoadConst);
01384   if (theLoad == 0) {
01385     opserr << "WARNING ran out of memory for load  - load " << nodeId;
01386     opserr << " " << ndf << " forces\n";
01387     return TCL_ERROR;
01388   }
01389 
01390   // add the load to the domain
01391   if (theTclDomain->addNodalLoad(theLoad, loadPatternTag) == false) {
01392     opserr << "WARNING TclModelBuilder - could not add load to domain\n";
01393     printCommand(argc, argv);
01394     delete theLoad;
01395     return TCL_ERROR;
01396   }
01397   nodeLoadTag++;
01398 
01399   // if get here we have sucessfully created the load and added it to the domain
01400   return TCL_OK;
01401 }
01402 
01403 
01404 
01405 
01406 int
01407 TclModelBuilder_addElementalLoad(ClientData clientData, Tcl_Interp *interp, int argc,   
01408                          TCL_Char **argv)
01409 {
01410   // ensure the destructor has not been called - 
01411   if (theTclBuilder == 0) {
01412     opserr << "WARNING current builder has been destroyed - eleLoad\n";    
01413     return TCL_ERROR;
01414   }
01415 
01416   int ndm = theTclBuilder->getNDM();
01417   ElementalLoad *theLoad = 0;
01418 
01419   ID theEleTags(0,16);
01420 
01421   // we first create an ID containing the ele tags of all elements
01422   // for which the load applies.
01423   int count = 1;
01424   int doneEle = 0;
01425   int eleCount = 0;
01426   while (doneEle == 0 && count < argc) {
01427     if (strcmp(argv[count],"-ele") == 0) {
01428       count ++;
01429       int eleStart = count;
01430       int eleEnd = 0;
01431       int eleID;
01432       while (count < argc && eleEnd == 0) {
01433         if (Tcl_GetInt(interp, argv[count], &eleID) != TCL_OK)
01434           eleEnd = count;
01435         else
01436           count++;
01437       }
01438       if (eleStart != eleEnd) {
01439         for (int i=eleStart; i<eleEnd; i++) {
01440           Tcl_GetInt(interp, argv[i], &eleID);
01441           theEleTags[eleCount++] = eleID;
01442         }
01443       }
01444     }
01445     else if (strcmp(argv[count],"-range") == 0) {
01446       count ++;
01447       int eleStart, eleEnd;
01448       if (Tcl_GetInt(interp, argv[count], &eleStart) != TCL_OK) {
01449         opserr << "WARNING eleLoad -range invalid eleStart " << argv[count] << "\n";
01450         return TCL_ERROR;
01451       }
01452       count++;
01453       if (Tcl_GetInt(interp, argv[count], &eleEnd) != TCL_OK) {
01454         opserr << "WARNING eleLoad -range invalid eleEnd " << argv[count] << "\n";      
01455         return TCL_ERROR;
01456       }
01457       count++;
01458       for (int i=eleStart; i<=eleEnd; i++)
01459         theEleTags[eleCount++] = i;     
01460     } else
01461       doneEle = 1;
01462   }
01463 
01464 
01465   // we then create the load
01466   if (strcmp(argv[count],"-type") != 0) {
01467     opserr << "WARNING eleLoad - expecting -type option but got "
01468          << argv[count] << endln;
01469     return TCL_ERROR;
01470   } 
01471   count++;
01472   if (strcmp(argv[count],"-beamUniform") == 0 ||
01473       strcmp(argv[count],"beamUniform") == 0){
01474     count++;
01475     if (ndm == 2) {
01476       double wt;
01477       double wa = 0.0;
01478       if (count >= argc || Tcl_GetDouble(interp, argv[count], &wt) != TCL_OK) {
01479         opserr << "WARNING eleLoad - invalid wt for beamUniform \n";
01480         return TCL_ERROR;
01481       }
01482       count++;
01483       if (count < argc && Tcl_GetDouble(interp, argv[count], &wa) != TCL_OK) {
01484         opserr << "WARNING eleLoad - invalid wa for beamUniform \n";
01485         return TCL_ERROR;
01486       }
01487       theLoad = new Beam2dUniformLoad(eleLoadTag, wt, wa, theEleTags);    
01488     }
01489     else if (ndm == 3) {
01490       double wy, wz;
01491       double wx = 0.0;
01492       if (count >= argc || Tcl_GetDouble(interp, argv[count], &wy) != TCL_OK) {
01493         opserr << "WARNING eleLoad - invalid wy for beamUniform \n";
01494         return TCL_ERROR;
01495       }
01496       count++;
01497       if (count >= argc || Tcl_GetDouble(interp, argv[count], &wz) != TCL_OK) {
01498         opserr << "WARNING eleLoad - invalid wz for beamUniform \n";
01499         return TCL_ERROR;
01500       }
01501       count++;
01502       if (count < argc && Tcl_GetDouble(interp, argv[count], &wx) != TCL_OK) {
01503         opserr << "WARNING eleLoad - invalid wx for beamUniform \n";
01504         return TCL_ERROR;
01505       }
01506       theLoad = new Beam3dUniformLoad(eleLoadTag, wy, wz, wx, theEleTags);    
01507     }
01508     else { 
01509       opserr << "WARNING eleLoad beamUniform currently only valid only for ndm=2 or 3\n";     
01510       return TCL_ERROR;
01511     }
01512   } else if (strcmp(argv[count],"-beamPoint") == 0 ||
01513              strcmp(argv[count],"beamPoint") == 0 ) {
01514     count++;
01515     if (ndm == 2) {
01516       double P, x;
01517       double N = 0.0;
01518       if (count >= argc || Tcl_GetDouble(interp, argv[count], &P) != TCL_OK) {
01519         opserr << "WARNING eleLoad - invalid P for beamPoint\n";                
01520         return TCL_ERROR;
01521       } 
01522       if (count+1 >= argc || Tcl_GetDouble(interp, argv[count+1], &x) != TCL_OK) {
01523         opserr << "WARNING eleLoad - invalid xDivL for beamPoint\n";    
01524         return TCL_ERROR;
01525       } 
01526       if (count+2 < argc && Tcl_GetDouble(interp, argv[count+2], &N) != TCL_OK) {
01527         opserr << "WARNING eleLoad - invalid N for beamPoint\n";                
01528         return TCL_ERROR;
01529       } 
01530 
01531       if (x < 0.0 || x > 1.0) {
01532         opserr << "WARNING eleLoad - invalid xDivL of " << x;
01533         opserr << " for beamPoint (valid range [0.0, 1.0]\n";
01534         return TCL_ERROR;
01535       }
01536 
01537       theLoad = new Beam2dPointLoad(eleLoadTag, P, x, theEleTags, N);    
01538     }
01539     else if (ndm == 3) {
01540       double Py, Pz, x;
01541       double N = 0.0;
01542       if (count >= argc || Tcl_GetDouble(interp, argv[count], &Py) != TCL_OK) {
01543         opserr << "WARNING eleLoad - invalid Py for beamPoint\n";               
01544         return TCL_ERROR;
01545       } 
01546       if (count+1 >= argc || Tcl_GetDouble(interp, argv[count+1], &Pz) != TCL_OK) {
01547         opserr << "WARNING eleLoad - invalid Pz  for beamPoint\n";              
01548         return TCL_ERROR;
01549       } 
01550       if (count+2 >= argc || Tcl_GetDouble(interp, argv[count+2], &x) != TCL_OK) {
01551         opserr << "WARNING eleLoad - invalid xDivL for beamPoint\n";    
01552         return TCL_ERROR;
01553       } 
01554       if (count+3 < argc && Tcl_GetDouble(interp, argv[count+3], &N) != TCL_OK) {
01555         opserr << "WARNING eleLoad - invalid N for beamPoint\n";                
01556         return TCL_ERROR;
01557       } 
01558 
01559       if (x < 0.0 || x > 1.0) {
01560         opserr << "WARNING eleLoad - invalid xDivL of " << x;
01561         opserr << " for beamPoint (valid range [0.0, 1.0]\n";
01562         return TCL_ERROR;
01563       }
01564 
01565       theLoad = new Beam3dPointLoad(eleLoadTag, Py, Pz, x, theEleTags, N);    
01566     }
01567     else {
01568       opserr << "WARNING eleLoad beamPoint type currently only valid only for ndm=2 or 3\n";
01569       return TCL_ERROR;
01570     }  
01571   }
01572   // Added Joey Yang UC Davis
01573   else if (strcmp(argv[count],"-BrickW") == 0) {
01574       theLoad = new BrickSelfWeight(eleLoadTag, theEleTags);
01575   }
01576 
01577   // Added by Scott R. Hamilton   - Stanford
01578   else if (strcmp(argv[count],"-beamTemp") == 0) {
01579     count++;
01580     if (ndm == 2) {
01581       double temp1, temp2, temp3, temp4;
01582       
01583       // Four temps given, Temp change at top node 1, bottom node 1, top node 2, bottom node 2.
01584       if (argc-count == 4){
01585         if (Tcl_GetDouble(interp, argv[count], &temp1) != TCL_OK) {
01586           opserr << "WARNING eleLoad - invalid Ttop1 " << argv[count] << " for -beamTemp\n";            
01587           return TCL_ERROR;
01588         } 
01589       
01590         if (Tcl_GetDouble(interp, argv[count+1],&temp2 ) != TCL_OK) {
01591           opserr << "WARNING eleLoad - invalid Tbot1 " << argv[count+1] << " for -beamTemp\n";  
01592           return TCL_ERROR;
01593         } 
01594         if (Tcl_GetDouble(interp, argv[count+2], &temp3) != TCL_OK) {
01595           opserr << "WARNING eleLoad - invalid Ttop2 " << argv[count+1] << " for -beamTemp\n";  
01596           return TCL_ERROR;
01597         } 
01598         if (Tcl_GetDouble(interp, argv[count+3], &temp4) != TCL_OK) {
01599           opserr << "WARNING eleLoad - invalid Tbot2 " << argv[count+1] << " for -beamTemp\n";  
01600           return TCL_ERROR;
01601         } 
01602         
01603         theLoad=0;
01604         theLoad = new Beam2dTempLoad(eleLoadTag, temp1, temp2, temp3, temp4, theEleTags);
01605       }
01606       // Two temps given, temp change at top, temp at bottom of element
01607       else if (argc-count == 2) {
01608         if (Tcl_GetDouble(interp, argv[count], &temp1) != TCL_OK) {
01609           opserr << "WARNING eleLoad - invalid Ttop " << argv[count] << " for -beamTemp\n";             
01610           return TCL_ERROR;
01611         } 
01612         
01613         if (Tcl_GetDouble(interp, argv[count+1],&temp2 ) != TCL_OK) {
01614           opserr << "WARNING eleLoad - invalid Tbot " << argv[count+1] << " for -beamTemp\n";   
01615           return TCL_ERROR;
01616         }
01617         theLoad=0;
01618         theLoad = new Beam2dTempLoad(eleLoadTag, temp1, temp2, theEleTags);
01619       }
01620       // One twmp change give, uniform temp change in element
01621       else if (argc-count == 1) {
01622         if (Tcl_GetDouble(interp, argv[count],&temp1 ) != TCL_OK) {
01623           opserr << "WARNING eleLoad - invalid Tbot " << argv[count+1] << " for -beamTemp\n";   
01624           return TCL_ERROR;
01625         }
01626         theLoad=0;
01627         theLoad = new Beam2dTempLoad(eleLoadTag, temp1, theEleTags);
01628       }
01629       // No temps, no change in temp in element--not a case likely to be used
01630       else if (argc-count == 0){
01631         theLoad=0;
01632         theLoad = new Beam2dTempLoad(eleLoadTag, theEleTags);
01633       }
01634       else {
01635         opserr << "WARNING eleLoad -beamTempLoad invalid number of temperature aguments,/n looking for 0, 1, 2 or 4 arguments.\n";
01636       }
01637     } else {
01638       opserr << "WARNING eleLoad -beamTempLoad type currently only valid only for ndm=2\n";
01639       return TCL_ERROR;
01640     }  
01641   }
01642 
01643   if (theLoad == 0) {
01644     opserr << "WARNING eleLoad - out of memory creating load of type " << argv[count] ;
01645     return TCL_ERROR;
01646   }
01647 
01648   // get the current pattern tag if no tag given in i/p
01649   int loadPatternTag = theTclLoadPattern->getTag();
01650 
01651   // add the load to the domain
01652   if (theTclDomain->addElementalLoad(theLoad, loadPatternTag) == false) {
01653     opserr << "WARNING eleLoad - could not add following load to domain:\n ";
01654     opserr << theLoad;
01655     delete theLoad;
01656     return TCL_ERROR;
01657   }
01658   eleLoadTag++;
01659 
01660   // if get here we have sucessfully created the load and added it to the domain
01661   return TCL_OK;
01662 }
01663 
01664 
01665 
01666 int
01667 TclModelBuilder_addNodalMass(ClientData clientData, Tcl_Interp *interp, int argc, 
01668                         TCL_Char **argv)
01669 {
01670   // ensure the destructor has not been called - 
01671   if (theTclBuilder == 0) {
01672     opserr << "WARNING builder has been destroyed - load \n";    
01673     return TCL_ERROR;
01674   }
01675 
01676   int ndf = theTclBuilder->getNDF();
01677 
01678   // make sure at least one other argument to contain type of system
01679   if (argc < (2 + ndf)) {
01680     opserr << "WARNING bad command - want: mass nodeId " << ndf << " mass values\n";
01681     printCommand(argc, argv);
01682     return TCL_ERROR;
01683   }    
01684 
01685   // get the id of the node
01686   int nodeId;
01687   if (Tcl_GetInt(interp, argv[1], &nodeId) != TCL_OK) {
01688     opserr << "WARNING invalid nodeId: " << argv[1];
01689     opserr << " - mass nodeId " << ndf << " forces\n";
01690     return TCL_ERROR;
01691   }
01692 
01693   // check for mass terms
01694   Matrix mass(ndf,ndf);
01695   double theMass;
01696   for (int i=0; i<ndf; i++) 
01697   {
01698      if (Tcl_GetDouble(interp, argv[i+2], &theMass) != TCL_OK) 
01699      {
01700           opserr << "WARNING invalid nodal mass term\n";
01701           opserr << "node: " << nodeId << ", dof: " << i+1 << endln;
01702           return TCL_ERROR;
01703       }
01704       mass(i,i) = theMass;
01705   }
01706 
01707   if (theTclDomain->setMass(mass, nodeId) != 0) {
01708     opserr << "WARNING failed to set mass at node " << nodeId << endln;
01709     return TCL_ERROR;
01710   }
01711     
01712   // if get here we have sucessfully created the node and added it to the domain
01713   return TCL_OK;
01714 }
01715 
01716 
01717 
01718 
01719 
01720 int
01721 TclModelBuilder_addHomogeneousBC(ClientData clientData, Tcl_Interp *interp, int argc,   
01722                                  TCL_Char **argv)
01723 {
01724   // ensure the destructor has not been called - 
01725   if (theTclBuilder == 0) {
01726     opserr << "WARNING builder has been destroyed - elasticBeam \n";    
01727     return TCL_ERROR;
01728   }
01729 
01730   int ndf = theTclBuilder->getNDF();
01731 
01732   // check number of arguments
01733   if (argc < (2 + ndf)) {
01734     opserr << "WARNING bad command - want: fix nodeId " << ndf << " [0,1] conditions";
01735     printCommand(argc, argv);
01736     return TCL_ERROR;
01737   }    
01738 
01739   // get the id of the node
01740   int nodeId;
01741   if (Tcl_GetInt(interp, argv[1], &nodeId) != TCL_OK) {
01742       opserr << "WARNING invalid nodeId - fix nodeId " << ndf << " [0,1] conditions\n";
01743       return TCL_ERROR;
01744   }
01745 
01746   // get the fixity condition and add the constraint if fixed
01747   for (int i=0; i<ndf; i++) {
01748     int theFixity;
01749     if (Tcl_GetInt(interp, argv[2+i], &theFixity) != TCL_OK) {
01750       opserr << "WARNING invalid fixity " << i+1 << " - load " << nodeId;
01751       opserr << " " << ndf << " fixities\n";
01752       return TCL_ERROR;
01753     } else {
01754       if (theFixity != 0) {
01755         // create a homogeneous constraint
01756         SP_Constraint *theSP = new SP_Constraint(currentSpTag, nodeId, i, 0.0);
01757         if (theSP == 0) {
01758           opserr << "WARNING ran out of memory for SP_Constraint ";
01759           opserr << "fix " << nodeId << " " << ndf << " [0,1] conditions\n";
01760           return TCL_ERROR;
01761         }
01762         if (theTclDomain->addSP_Constraint(theSP) == false) {
01763           opserr << "WARNING could not add SP_Constraint to domain - fix";
01764           opserr << nodeId << " " << ndf << " [0,1] conditions\n";
01765           delete theSP;
01766           return TCL_ERROR;
01767         }
01768         currentSpTag++;      }
01769     }
01770   }
01771 
01772   // if get here we have sucessfully created the node and added it to the domain
01773   return TCL_OK;
01774 }
01775 
01776 
01777 int
01778 TclModelBuilder_addHomogeneousBC_X(ClientData clientData, Tcl_Interp *interp, 
01779                                    int argc, TCL_Char **argv)
01780 {
01781   // ensure the destructor has not been called - 
01782   if (theTclBuilder == 0) {
01783     opserr << "WARNING builder has been destroyed - elasticBeam \n";    
01784     return TCL_ERROR;
01785   }
01786 
01787   int ndf = theTclBuilder->getNDF();
01788 
01789   // check number of arguments
01790   if (argc < (2 + ndf)) {
01791     opserr << "WARNING bad command - want: fixX xLoc " << ndf << " [0,1] conditions";
01792     printCommand(argc, argv);
01793     return TCL_ERROR;
01794   }    
01795 
01796   // get the xCrd of nodes to be constrained
01797   double xLoc;
01798   if (Tcl_GetDouble(interp, argv[1], &xLoc) != TCL_OK) {
01799       opserr << "WARNING invalid xCrd - fixX xLoc " << ndf << " [0,1] conditions\n";
01800       return TCL_ERROR;
01801   }
01802 
01803   // read in the fixities
01804   ID fixity(ndf);
01805   for (int i=0; i<ndf; i++) {
01806     if (Tcl_GetInt(interp, argv[2+i], &fixity(i)) != TCL_OK) {
01807       opserr << "WARNING invalid fixity " << i+1 << " - fixX " << xLoc;
01808       opserr << " " << ndf << " fixities\n";
01809       return TCL_ERROR;
01810     } 
01811   }
01812 
01813   // set the tolerance, the allowable difference in nodal coordinate and
01814   // what the value user specified to see if node is constrained or not
01815   double tol = 1.0e-10;
01816   if (argc >= (4 + ndf)) {
01817     if (strcmp(argv[2+ndf],"-tol") == 0)
01818     if (Tcl_GetDouble(interp, argv[3+ndf], &tol) != TCL_OK) {
01819       opserr << "WARNING invalid tol specified - fixX " << xLoc << endln;
01820       return TCL_ERROR;
01821     }       
01822   }
01823 
01824   NodeIter &theNodes = theTclDomain->getNodes();
01825   Node *theNode;
01826 
01827   // loop over all the nodes
01828   while ((theNode = theNodes()) != 0) {
01829     const Vector &theCrd = theNode->getCrds();
01830     double nodeX = theCrd(0);
01831 
01832     // add a single point constraint if Xcrd of node is within tol of xLoc
01833     if (fabs(nodeX - xLoc) < tol) {
01834       int nodeId = theNode->getTag();
01835       int theFixity = 0;
01836 
01837       // loop over all the ndf values valid for the node
01838       int numDOF = theNode->getNumberDOF();
01839       if (numDOF  < ndf) numDOF = ndf;
01840 
01841       for (int i=0; i<numDOF; i++) {
01842         theFixity = fixity(i);
01843         if (theFixity != 0) {
01844           // create a homogeneous constraint
01845           SP_Constraint *theSP = new SP_Constraint(currentSpTag, nodeId, i, 0.0);
01846           if (theSP == 0) {
01847             opserr << "WARNING ran out of memory for SP_Constraint at node " << nodeId;
01848             opserr << " - fixX " << xLoc << " " << ndf << " [0,1] conditions\n";
01849             return TCL_ERROR;
01850           }
01851           if (theTclDomain->addSP_Constraint(theSP) == false) {
01852             opserr << "WARNING could not add SP_Constraint to domain for node " << nodeId;
01853             opserr << " - fixX " << xLoc << " " << ndf << " [0,1] conditions\n";
01854             delete theSP;
01855             return TCL_ERROR;
01856           }
01857           currentSpTag++;      
01858         }
01859       }
01860     }
01861   }
01862 
01863   // if get here we have sucessfully created the node and added it to the domain
01864   return TCL_OK;
01865 }
01866 
01867 
01868 
01869 
01870 int
01871 TclModelBuilder_addHomogeneousBC_Y(ClientData clientData, Tcl_Interp *interp, 
01872                                    int argc, TCL_Char **argv)
01873 {
01874   // ensure the destructor has not been called - 
01875   if (theTclBuilder == 0) {
01876     opserr << "WARNING builder has been destroyed - elasticBeam \n";    
01877     return TCL_ERROR;
01878   }
01879 
01880   int ndf = theTclBuilder->getNDF();
01881 
01882   // check number of arguments
01883   if (argc < (2 + ndf)) {
01884     opserr << "WARNING bad command - want: fixY yLoc " << ndf << " [0,1] conditions";
01885     printCommand(argc, argv);
01886     return TCL_ERROR;
01887   }    
01888 
01889   // get the yCrd of nodes to be constrained
01890   double yLoc;
01891   if (Tcl_GetDouble(interp, argv[1], &yLoc) != TCL_OK) {
01892       opserr << "WARNING invalid yCrd - fixY yLoc " << ndf << " [0,1] conditions\n";
01893       return TCL_ERROR;
01894   }
01895 
01896   // read in the fixities
01897   ID fixity(ndf);
01898   for (int i=0; i<ndf; i++) {
01899     if (Tcl_GetInt(interp, argv[2+i], &fixity(i)) != TCL_OK) {
01900       opserr << "WARNING invalid fixity " << i+1 << " - fixY " << yLoc;
01901       opserr << " " << ndf << " fixities\n";
01902       return TCL_ERROR;
01903     } 
01904   }
01905 
01906   // set the tolerance, the allowable difference in nodal coordinate and
01907   // what the value user specified to see if node is constrained or not
01908   double tol = 1.0e-10;
01909   if (argc >= (4 + ndf)) {
01910     if (strcmp(argv[2+ndf],"-tol") == 0)
01911     if (Tcl_GetDouble(interp, argv[3+ndf], &tol) != TCL_OK) {
01912       opserr << "WARNING invalid tol specified - fixY " << yLoc << endln;
01913       return TCL_ERROR;
01914     }       
01915   }
01916 
01917   NodeIter &theNodes = theTclDomain->getNodes();
01918   Node *theNode;
01919 
01920   // loop over all the nodes
01921   while ((theNode = theNodes()) != 0) {
01922     const Vector &theCrd = theNode->getCrds();
01923     if (theCrd.Size() > 1) {
01924       double nodeY = theCrd(1);
01925 
01926       // add a single point constraint if Xcrd of node is within tol of yLoc
01927       if (fabs(nodeY - yLoc) < tol) {
01928 
01929         int nodeId = theNode->getTag();
01930         int theFixity = 0;
01931 
01932         // loop over all the ndf values valid for the node
01933         int numDOF = theNode->getNumberDOF();
01934         if (numDOF  < ndf) numDOF = ndf;
01935 
01936         for (int i=0; i<numDOF; i++) {
01937           theFixity = fixity(i);
01938           if (theFixity != 0) {
01939             // create a homogeneous constraint
01940             SP_Constraint *theSP = new SP_Constraint(currentSpTag, nodeId, i, 0.0);
01941             if (theSP == 0) {
01942               opserr << "WARNING ran out of memory for SP_Constraint at node " << nodeId;
01943               opserr << " - fixY " << yLoc << " " << ndf << " [0,1] conditions\n";
01944               return TCL_ERROR;
01945             }
01946             if (theTclDomain->addSP_Constraint(theSP) == false) {
01947               opserr << "WARNING could not add SP_Constraint to domain for node " << nodeId;
01948               opserr << " - fixY " << yLoc << " " << ndf << " [0,1] conditions\n";
01949               delete theSP;
01950               return TCL_ERROR;
01951             }
01952             currentSpTag++;      
01953           }
01954         }
01955       }
01956     }
01957   }
01958 
01959   // if get here we have sucessfully created the node and added it to the domain
01960   return TCL_OK;
01961 }
01962 
01963 
01964 
01965 int
01966 TclModelBuilder_addHomogeneousBC_Z(ClientData clientData, Tcl_Interp *interp, 
01967                                    int argc, TCL_Char **argv)
01968 {
01969   // ensure the destructor has not been called - 
01970   if (theTclBuilder == 0) {
01971     opserr << "WARNING builder has been destroyed - elasticBeam \n";    
01972     return TCL_ERROR;
01973   }
01974 
01975   int ndf = theTclBuilder->getNDF();
01976 
01977   // check number of arguments
01978   if (argc < (2 + ndf)) {
01979     opserr << "WARNING bad command - want: fixZ zLoc " << ndf << " [0,1] conditions";
01980     printCommand(argc, argv);
01981     return TCL_ERROR;
01982   }    
01983 
01984   // get the yCrd of nodes to be constrained
01985   double zLoc;
01986   if (Tcl_GetDouble(interp, argv[1], &zLoc) != TCL_OK) {
01987       opserr << "WARNING invalid zCrd - fixZ zLoc " << ndf << " [0,1] conditions\n";
01988       return TCL_ERROR;
01989   }
01990 
01991   // read in the fixities
01992   ID fixity(ndf);
01993   for (int i=0; i<ndf; i++) {
01994     if (Tcl_GetInt(interp, argv[2+i], &fixity(i)) != TCL_OK) {
01995       opserr << "WARNING invalid fixity " << i+1 << " - fixZ " << zLoc;
01996       opserr << " " << ndf << " fixities\n";
01997       return TCL_ERROR;
01998     } 
01999   }
02000 
02001   // set the tolerance, the allowable difference in nodal coordinate and
02002   // what the value user specified to see if node is constrained or not
02003   double tol = 1.0e-10;
02004   if (argc >= (4 + ndf)) {
02005     if (strcmp(argv[2+ndf],"-tol") == 0)
02006     if (Tcl_GetDouble(interp, argv[3+ndf], &tol) != TCL_OK) {
02007       opserr << "WARNING invalid tol specified - fixZ " << zLoc << endln;
02008       return TCL_ERROR;
02009     }       
02010   }
02011 
02012   NodeIter &theNodes = theTclDomain->getNodes();
02013   Node *theNode;
02014 
02015   // loop over all the nodes
02016   while ((theNode = theNodes()) != 0) {
02017     const Vector &theCrd = theNode->getCrds();
02018     if (theCrd.Size() > 2) {
02019       double nodeZ = theCrd(2);
02020 
02021       // add a single point constraint if Xcrd of node is within tol of zLoc
02022       if (fabs(nodeZ - zLoc) < tol) {
02023 
02024         int nodeId = theNode->getTag();
02025         int theFixity = 0;
02026 
02027         // loop over all the ndf values valid for the node
02028         int numDOF = theNode->getNumberDOF();
02029         if (numDOF  < ndf) numDOF = ndf;
02030 
02031         for (int i=0; i<numDOF; i++) {
02032           theFixity = fixity(i);
02033           if (theFixity != 0) {
02034             // create a homogeneous constraint
02035             SP_Constraint *theSP = new SP_Constraint(currentSpTag, nodeId, i, 0.0);
02036             if (theSP == 0) {
02037               opserr << "WARNING ran out of memory for SP_Constraint at node " << nodeId;
02038               opserr << " - fixZ " << zLoc << " " << ndf << " [0,1] conditions\n";
02039               return TCL_ERROR;
02040             }
02041             if (theTclDomain->addSP_Constraint(theSP) == false) {
02042               opserr << "WARNING could not add SP_Constraint to domain for node " << nodeId;
02043               opserr << " - fixZ " << zLoc << " " << ndf << " [0,1] conditions\n";
02044               delete theSP;
02045               return TCL_ERROR;
02046             }
02047             currentSpTag++;      
02048           }
02049         }
02050       }
02051     }
02052   }
02053 
02054   // if get here we have sucessfully created the node and added it to the domain
02055   return TCL_OK;
02056 }
02057 
02058 
02059 
02060 int
02061 TclModelBuilder_addSP(ClientData clientData, Tcl_Interp *interp, int argc,   
02062                       TCL_Char **argv)
02063 {
02064   // ensure the destructor has not been called - 
02065   if (theTclBuilder == 0) {
02066     opserr << "WARNING builder has been destroyed - sp \n";    
02067     return TCL_ERROR;
02068   }
02069 
02070   int ndf = theTclBuilder->getNDF();
02071 
02072   // check number of arguments
02073   if (argc < 4) {
02074     opserr << "WARNING bad command - want: sp nodeId dofID value";
02075     printCommand(argc, argv);
02076     return TCL_ERROR;
02077   }    
02078 
02079   // get the nodeID, dofId and value of the constraint
02080   int nodeId, dofId;
02081   double value;
02082 
02083   if (Tcl_GetInt(interp, argv[1], &nodeId) != TCL_OK) {
02084     opserr << "WARNING invalid nodeId: " << argv[1] << " -  sp nodeId dofID value\n";
02085     return TCL_ERROR;
02086   }
02087   if (Tcl_GetInt(interp, argv[2], &dofId) != TCL_OK) {
02088     opserr << "WARNING invalid dofId: " << argv[2] << " -  sp ";
02089     opserr << nodeId << " dofID value\n";
02090       return TCL_ERROR;
02091   }
02092   dofId--; // DECREMENT THE DOF VALUE BY 1 TO GO TO OUR C++ INDEXING
02093 
02094   if (Tcl_GetDouble(interp, argv[3], &value) != TCL_OK) {
02095     opserr << "WARNING invalid value: " << argv[3] << " -  sp ";
02096     opserr << nodeId << " dofID value\n";
02097       return TCL_ERROR;
02098   }
02099 
02100   bool isSpConst = false;
02101   int loadPatternTag = 123456789; // some pattern that will never be used!
02102 
02103   // allow some additional options at end of command
02104   theTclLoadPattern->getTag();
02105   int endMarker = 4;
02106   while (endMarker != argc) {
02107     if (strcmp(argv[endMarker],"-const") == 0) {
02108       // allow user to specify const load
02109       isSpConst = true;
02110     } else if (strcmp(argv[endMarker],"-pattern") == 0) {
02111       // allow user to specify load pattern other than current
02112       endMarker++;
02113       if (endMarker == argc || 
02114           Tcl_GetInt(interp, argv[endMarker], &loadPatternTag) != TCL_OK) {
02115 
02116         opserr << "WARNING invalid patternTag - load " << nodeId << " ";
02117         opserr << ndf << " forces pattern patterntag\n";
02118         return TCL_ERROR;
02119       }
02120     }  
02121     endMarker++;
02122   }
02123 
02124   // if load pattern tag has not changed - get the pattern tag from current one
02125   if (loadPatternTag == 123456789) {
02126     if (theTclLoadPattern == 0) {
02127       opserr << "WARNING no current pattern - sp " << nodeId << " dofID value\n";
02128       return TCL_ERROR;
02129     } else      
02130       loadPatternTag = theTclLoadPattern->getTag();
02131   }
02132   
02133   LoadPattern *thePattern = theTclDomain->getLoadPattern(loadPatternTag);
02134   SP_ConstraintIter &theSPs = thePattern->getSPs();
02135   int numSPs = 0;
02136   SP_Constraint *theSP2;
02137   while ((theSP2 = theSPs()) != 0)
02138       numSPs++;
02139   
02140   
02141   // create a homogeneous constraint
02142   SP_Constraint *theSP = new SP_Constraint(numSPs, nodeId, dofId, value, isSpConst);
02143 
02144   if (theSP == 0) {
02145     opserr << "WARNING ran out of memory for SP_Constraint ";
02146     opserr << " - sp " << nodeId << " dofID value\n";
02147     return TCL_ERROR;
02148   }
02149   if (theTclDomain->addSP_Constraint(theSP, loadPatternTag) == false) {
02150     opserr << "WARNING could not add SP_Constraint to domain ";
02151     printCommand(argc, argv);
02152     delete theSP;
02153     return TCL_ERROR;
02154   }
02155 
02156   // if get here we have sucessfully created the node and added it to the domain
02157   return TCL_OK;
02158 }
02159 
02160 
02161 
02162 int
02163 TclModelBuilder_addImposedMotionSP(ClientData clientData, 
02164                                    Tcl_Interp *interp, 
02165                                    int argc,   
02166                                    TCL_Char **argv)
02167 {
02168   // ensure the destructor has not been called - 
02169   if (theTclBuilder == 0) {
02170     opserr << "WARNING builder has been destroyed - sp \n";    
02171     return TCL_ERROR;
02172   }
02173 
02174   int ndf = theTclBuilder->getNDF();
02175 
02176   // check number of arguments
02177   if (argc < 4) {
02178     opserr << "WARNING bad command - want: imposedMotion nodeId dofID gMotionID\n";
02179     printCommand(argc, argv);
02180     return TCL_ERROR;
02181   }    
02182 
02183   // get the nodeID, dofId and value of the constraint
02184   int nodeId, dofId, gMotionID;
02185 
02186   if (Tcl_GetInt(interp, argv[1], &nodeId) != TCL_OK) {
02187     opserr << "WARNING invalid nodeId: " << argv[1];
02188     opserr << " - imposedMotion nodeId dofID gMotionID\n";    
02189     return TCL_ERROR;
02190   }
02191 
02192   if (Tcl_GetInt(interp, argv[2], &dofId) != TCL_OK) {
02193     opserr << "WARNING invalid dofId: " << argv[2] << " -  imposedMotion ";
02194     opserr << nodeId << " dofID gMotionID\n";    
02195       return TCL_ERROR;
02196   }
02197   dofId--; // DECREMENT THE DOF VALUE BY 1 TO GO TO OUR C++ INDEXING
02198 
02199   if (Tcl_GetInt(interp, argv[3], &gMotionID) != TCL_OK) {
02200     opserr << "WARNING invalid gMotionID: " << argv[3] << " -  imposedMotion ";
02201     opserr << nodeId << " dofID gMotionID\n";
02202     return TCL_ERROR;
02203   }
02204 
02205   bool alt = false;
02206   if (argc == 5) {
02207     if (strcmp(argv[4],"-other") == 0) 
02208       alt = true;
02209   }
02210 
02211   MultiSupportPattern *thePattern = theTclMultiSupportPattern;
02212   int loadPatternTag = thePattern->getTag();
02213   
02214   SP_ConstraintIter &theSPs = thePattern->getSPs();
02215   int numSPs = 0;
02216   SP_Constraint *theSP2;
02217   while ((theSP2 = theSPs()) != 0)
02218       numSPs++;
02219 
02220   // create a new ImposedMotionSP
02221   SP_Constraint *theSP;
02222   if (alt == true) {
02223     theSP = new ImposedMotionSP1(numSPs, nodeId, dofId, loadPatternTag, gMotionID);
02224   }
02225   else {
02226     theSP = new ImposedMotionSP(numSPs, nodeId, dofId, loadPatternTag, gMotionID);
02227   }
02228 
02229   if (theSP == 0) {
02230     opserr << "WARNING ran out of memory for ImposedMotionSP ";
02231     opserr << " -  imposedMotion ";
02232     opserr << nodeId << " " << dofId++ << " " << gMotionID << endln;
02233     return TCL_ERROR;
02234   }
02235   if (thePattern->addSP_Constraint(theSP) == false) {
02236     opserr << "WARNING could not add SP_Constraint to pattern ";
02237     printCommand(argc, argv);
02238     delete theSP;
02239     return TCL_ERROR;
02240   }
02241 
02242   // if get here we have sucessfully created the node and added it to the domain
02243   return TCL_OK;
02244 }
02245 
02246 
02247 
02248 
02249 
02250 
02251 int
02252 TclModelBuilder_addEqualDOF_MP (ClientData clientData, Tcl_Interp *interp,
02253                                 int argc, TCL_Char **argv)
02254 {
02255         // Ensure the destructor has not been called
02256         if (theTclBuilder == 0) {
02257           opserr << "WARNING builder has been destroyed - equalDOF \n";
02258           return TCL_ERROR;
02259         }
02260 
02261         // Check number of arguments
02262         if (argc < 4) {
02263           opserr << "WARNING bad command - want: equalDOF RnodeID? CnodeID? DOF1? DOF2? ...";
02264           printCommand (argc, argv);
02265           return TCL_ERROR;
02266         }
02267 
02268         // Read in the node IDs and the DOF
02269         int RnodeID, CnodeID, dofID;
02270 
02271         if (Tcl_GetInt (interp, argv[1], &RnodeID) != TCL_OK) {
02272           opserr << "WARNING invalid RnodeID: " << argv[1]
02273                << " equalDOF RnodeID? CnodeID? DOF1? DOF2? ...";
02274           return TCL_ERROR;
02275         }
02276         if (Tcl_GetInt (interp, argv[2], &CnodeID) != TCL_OK) {
02277           opserr << "WARNING invalid CnodeID: " << argv[2]
02278                << " equalDOF RnodeID? CnodeID? DOF1? DOF2? ...";
02279           return TCL_ERROR;
02280         }
02281 
02282         // The number of DOF to be coupled
02283         int numDOF = argc - 3;
02284 
02285         // The constraint matrix ... U_c = C_cr * U_r
02286         Matrix Ccr (numDOF, numDOF);
02287         Ccr.Zero();
02288 
02289         // The vector containing the retained and constrained DOFs
02290         ID rcDOF (numDOF);
02291 
02292         int i, j;
02293         // Read the degrees of freedom which are to be coupled
02294         for (i = 3, j = 0; i < argc; i++, j++) {
02295           if (Tcl_GetInt (interp, argv[i], &dofID) != TCL_OK) {
02296             opserr << "WARNING invalid dofID: " << argv[3]
02297                  << " equalDOF RnodeID? CnodeID? DOF1? DOF2? ...";
02298             return TCL_ERROR;
02299           }
02300 
02301           dofID -= 1; // Decrement for C++ indexing
02302           if (dofID < 0) {
02303             opserr << "WARNING invalid dofID: " << argv[i]
02304                    << " must be >= 1";
02305             return TCL_ERROR;
02306           }
02307           rcDOF (j) = dofID;    
02308           Ccr (j,j) = 1.0;
02309         }
02310 
02311         // Use this for the MP tag
02312         int numMPs = theTclDomain->getNumMPs();
02313 
02314         // Create the multi-point constraint
02315         MP_Constraint *theMP = new MP_Constraint (numMPs, RnodeID, CnodeID, Ccr, rcDOF, rcDOF);
02316         if (theMP == 0) {
02317           opserr << "WARNING ran out of memory for equalDOF MP_Constraint ";
02318           printCommand (argc, argv);
02319           return TCL_ERROR;
02320         }
02321 
02322         // Add the multi-point constraint to the domain
02323         if (theTclDomain->addMP_Constraint (theMP) == false) {
02324           opserr << "WARNING could not add equalDOF MP_Constraint to domain ";
02325           printCommand(argc, argv);
02326           delete theMP;
02327           return TCL_ERROR;
02328         }
02329 
02330         return TCL_OK;
02331 }
02332 
02333 
02334 
02335 int
02336 TclModelBuilder_addMP(ClientData clientData, Tcl_Interp *interp, int argc,   
02337                            TCL_Char **argv)
02338 {
02339   opserr << "WARNING - TclModelBuilder_addMP() not yet implemented\n";
02340   return TCL_OK;
02341 }
02342 
02344 // Added by Scott J. Brandenberg, UC Davis, sjbrandenberg@ucdavis.edu
02345 int
02346 TclModelBuilder_doPySimple1Gen(ClientData clientData, Tcl_Interp *interp, int argc,
02347                                TCL_Char **argv)
02348 {
02349         if(argc < 6 || argc > 7){
02350                 opserr << "WARNING PySimple1Gen file1? file2? file3? file4? file5? <file6?>";
02351                 opserr << "Must have either 5 or 6 arguments." << endln;
02352         }
02353         
02354         PySimple1Gen *thePySimple1Gen;
02355         thePySimple1Gen = new PySimple1Gen;
02356 
02357         if(argc==6)
02358                 thePySimple1Gen->WritePySimple1(argv[1], argv[2], argv[3], argv[4], argv[5]);
02359         if(argc==7)
02360                 thePySimple1Gen->WritePySimple1(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
02361 
02362         delete thePySimple1Gen;
02363 
02364         return TCL_OK;
02365 }
02366 
02367 int
02368 TclModelBuilder_doTzSimple1Gen(ClientData clientData, Tcl_Interp *interp, int argc,
02369                                TCL_Char **argv)
02370 {
02371         if(argc < 6 || argc > 7){
02372                 opserr << "WARNING TzSimple1Gen file1? file2? file3? file4? file5? <file6?>";
02373                 opserr << "Must have either 5 or 6 arguments." << endln;
02374         }
02375 
02376         TzSimple1Gen *theTzSimple1Gen;
02377         theTzSimple1Gen = new TzSimple1Gen;
02378 
02379         if(argc==6)
02380                 theTzSimple1Gen->WriteTzSimple1(argv[1], argv[2], argv[3], argv[4], argv[5]);
02381         if(argc==7)
02382                 theTzSimple1Gen->WriteTzSimple1(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
02383 
02384         delete theTzSimple1Gen;
02385 
02386         return TCL_OK;
02387 }
02388 // End Added by Scott J. Brandenberg
02390 
02391 int
02392 TclModelBuilder_doBlock2D(ClientData clientData, Tcl_Interp *interp, int argc,   
02393                           TCL_Char **argv)
02394 {
02395 
02396   int ndm = theTclBuilder->getNDM();
02397   if (ndm < 2) {
02398     opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02399     opserr << " : model dimension (ndm) must be at leat 2 " << endln;
02400     return TCL_ERROR;
02401   }
02402 
02403   if (argc < 8) {
02404     opserr << "WARNING incorrect numer of args :block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02405     return TCL_ERROR;
02406   }
02407   int numX, numY, startNodeNum, startEleNum;
02408   if (Tcl_GetInt (interp, argv[1], &numX) != TCL_OK) {
02409     opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02410     opserr << " : invalid numX: " << argv[1] << endln;
02411     return TCL_ERROR;
02412   }
02413   if (Tcl_GetInt (interp, argv[2], &numY) != TCL_OK) {
02414     opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02415     opserr << " : invalid numY: " << argv[2] << endln;
02416     return TCL_ERROR;
02417   }
02418   if (Tcl_GetInt (interp, argv[3], &startNodeNum) != TCL_OK) {
02419     opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02420     opserr << " : invalid startNode: " << argv[3] << endln;
02421     return TCL_ERROR;
02422   }
02423   if (Tcl_GetInt (interp, argv[4], &startEleNum) != TCL_OK) {
02424     opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02425     opserr << " : invalid startEle: " << argv[4] << endln;
02426     return TCL_ERROR;
02427   }
02428 
02429 
02430   static Matrix Coordinates(9,3);
02431   static ID     haveNode(9);
02432   Coordinates.Zero();
02433   for (int k=0; k<9; k++) haveNode(k) = -1;
02434 
02435   int numNodes = 4;
02436   if (argc == 10) {
02437     if (strcmp(argv[7],"-numEleNodes") == 0) 
02438       if (Tcl_GetInt (interp, argv[8], &numNodes) != TCL_OK) {
02439         opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02440         opserr << " -numEleNodes numNodes?: invalid numNodes: " << argv[8] << endln;
02441         return TCL_ERROR;
02442       }
02443     if (numNodes != 4 && numNodes != 9) {
02444       opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs? ";
02445       opserr << "-numEleNodes numNodes?: invalid numNodes: " << argv[8] << " 4 or 9 only\n";
02446       return TCL_ERROR;
02447     }
02448 
02449     if (numNodes == 9) {
02450       if (((numX % 2) != 0) || ((numY % 2) != 0)) {
02451         opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs? ";
02452         opserr << "-numEleNodes 9: numX and numY MUST BOTH BE EVEN\n";
02453         return TCL_ERROR;
02454       }
02455     }
02456   }
02457 
02458 
02459   //  char *nodalInfo;
02460   int nodalInfo = 9;
02461   if (numNodes == 4)
02462     //nodalInfo = argv[7];
02463     nodalInfo=7;
02464   //  else
02465   //nodalInfo = argv[9];
02466 
02467   TCL_Char **argvNodes;
02468   int  argcNodes;
02469   
02470   Tcl_SplitList(interp, argv[nodalInfo], &argcNodes, &argvNodes);
02471 
02472   int ndf = theTclBuilder->getNDF();
02473   
02474   int count = 0;
02475   while (count < argcNodes) {
02476     if ((count + ndm + 1) >  argcNodes) {
02477       opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02478       opserr << " : invalid number of node args: " << argv[7] << endln;
02479       Tcl_Free((char *)argvNodes);
02480       return TCL_ERROR; 
02481     }
02482     int nodeTag;
02483     double value;
02484     if (Tcl_GetInt (interp, argvNodes[count], &nodeTag) != TCL_OK) {
02485       opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02486       opserr << " : invalid node tag: " << argvNodes[count] << endln;
02487       Tcl_Free((char *)argvNodes);
02488       return TCL_ERROR; 
02489     }
02490     if (nodeTag < 1 || nodeTag > 9) {
02491       opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02492       opserr << " : invalid node tag out of bounds [1,9]: " << argvNodes[count] << endln;
02493       Tcl_Free((char *)argvNodes);
02494       return TCL_ERROR;
02495     }
02496     for (int i=0; i<ndm; i++) {
02497       if (Tcl_GetDouble(interp, argvNodes[count+1+i], &value) != TCL_OK) {
02498         opserr << "WARNING block2D numX? numY? startNode? startEle? eleType? eleArgs?";
02499         opserr << " : invalid node coordinate for node: " << argvNodes[count] << endln;
02500         Tcl_Free((char *)argvNodes);
02501         return TCL_ERROR;
02502       }
02503       Coordinates(nodeTag-1,i) = value;
02504       haveNode(nodeTag-1) = nodeTag;
02505     }      
02506     count += 1 + ndm;
02507   }
02508 
02509   Tcl_Free((char *)argvNodes);
02510 
02511   Block2D  theBlock(numX, numY, haveNode, Coordinates, numNodes);
02512 
02513   // create the nodes: (numX+1)*(numY+1) nodes to be created
02514   int nodeID = startNodeNum;
02515   int jj;
02516   for (jj=0; jj<=numY; jj++) {
02517     for (int ii=0; ii<=numX; ii++) {
02518       const Vector &nodeCoords = theBlock.getNodalCoords(ii,jj);
02519       double xLoc = nodeCoords(0);
02520       double yLoc = nodeCoords(1);
02521       double zLoc = nodeCoords(2);
02522       Node *theNode = 0;
02523       if (ndm == 2) {
02524         theNode = new Node(nodeID,ndf,xLoc, yLoc);
02525       } else if (ndm == 3) {
02526         theNode = new Node(nodeID,ndf,xLoc, yLoc, zLoc);
02527       } 
02528 
02529       if (theNode == 0) {
02530         opserr << "WARNING ran out of memory creating node\n";
02531         opserr << "node: " << nodeID << endln;
02532         return TCL_ERROR;
02533       }
02534 
02535       if (theTclDomain->addNode(theNode) == false) {
02536         opserr << "WARNING failed to add node to the domain\n";
02537         opserr << "node: " << nodeID << endln;
02538         delete theNode; // otherwise memory leak
02539         return TCL_ERROR;
02540       }
02541 
02542       nodeID++;
02543     }
02544   }
02545     
02546   // create the elements: numX*numY elements to be created if 4 node elements
02547   //                      numX/2 * numY /2 nodes to be v=created if 9 node elements
02548   TCL_Char *eleType = argv[5];
02549   TCL_Char *additionalEleArgs = argv[6];
02550   //  const ID &nodeTags = theBlock.getElementNodes(0,0);  
02551   //  int numNodes = nodeTags.Size();
02552 
02553   // assumes 15 is largest string for individual nodeTags
02554   count = 10 + strlen(eleType) + strlen(additionalEleArgs) + 15 * (numNodes+1);
02555   char *eleCommand = new char[count];
02556   int initialCount = 8 + strlen(eleType);
02557 
02558   int  eleID = startEleNum; 
02559   if (numNodes == 9) {
02560     numX /= 2;
02561     numY /= 2;
02562   }
02563     
02564 
02565   for (jj=0; jj<numY; jj++) {
02566     for (int ii=0; ii<numX; ii++) {
02567       count = initialCount;
02568 
02569       const ID &nodeTags = theBlock.getElementNodes(ii,jj);
02570       
02571       // create the string to be evaluated
02572       strcpy(eleCommand, "element ");
02573       strcpy(&eleCommand[8], eleType);
02574       count += sprintf(&eleCommand[count], " %d ", eleID);
02575       for (int i=0; i<numNodes; i++) {
02576         int nodeTag = nodeTags(i)+startNodeNum;
02577         count += sprintf(&eleCommand[count], " %d ", nodeTag);
02578       }
02579       strcat(eleCommand, additionalEleArgs);      
02580 
02581       // now to create the element we get the string eveluated
02582       if (Tcl_Eval(interp, eleCommand) != TCL_OK) {
02583           delete [] eleCommand;
02584         return TCL_ERROR;
02585       }
02586       eleID++;
02587     }
02588   }
02589 
02590   delete [] eleCommand;
02591   return TCL_OK;
02592 }
02593 
02594 
02595 int
02596 TclModelBuilder_doBlock3D(ClientData clientData, Tcl_Interp *interp, int argc,   
02597                           TCL_Char **argv)
02598 {
02599 
02600   int ndm = theTclBuilder->getNDM();
02601   if (ndm < 3) {
02602     opserr << "WARNING block3D numX? numY? startNode? startEle? eleType? eleArgs?";
02603     opserr << " : model dimension (ndm) must be at leat 2 " << endln;
02604     return TCL_ERROR;
02605   }
02606 
02607   int numX, numY, numZ, startNodeNum, startEleNum;
02608   if (Tcl_GetInt (interp, argv[1], &numX) != TCL_OK) {
02609     opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02610     opserr << " : invalid numX: " << argv[1] << endln;
02611     return TCL_ERROR;
02612   }
02613   if (Tcl_GetInt (interp, argv[2], &numY) != TCL_OK) {
02614     opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02615     opserr << " : invalid numY: " << argv[2] << endln;
02616     return TCL_ERROR;
02617   }
02618   if (Tcl_GetInt (interp, argv[3], &numZ) != TCL_OK) {
02619     opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02620     opserr << " : invalid numZ: " << argv[3] << endln;
02621     return TCL_ERROR;
02622   }
02623   if (Tcl_GetInt (interp, argv[4], &startNodeNum) != TCL_OK) {
02624     opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02625     opserr << " : invalid startNode: " << argv[4] << endln;
02626     return TCL_ERROR;
02627   }
02628   if (Tcl_GetInt (interp, argv[5], &startEleNum) != TCL_OK) {
02629     opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02630     opserr << " : invalid startEle: " << argv[5] << endln;
02631     return TCL_ERROR;
02632   }
02633 
02634   static Matrix Coordinates(27,3);
02635   static ID     haveNode(27);
02636   Coordinates.Zero();
02637   for (int k=0; k<27; k++) haveNode(k) = -1;
02638 
02639   TCL_Char *nodalInfo = argv[8];
02640   TCL_Char **argvNodes;
02641   int  argcNodes;
02642   
02643   Tcl_SplitList(interp, nodalInfo, &argcNodes, &argvNodes);
02644 
02645   int ndf = theTclBuilder->getNDF();
02646   
02647   int count = 0;
02648   while (count < argcNodes) {
02649     if ((count + ndm + 1) > argcNodes) {
02650       opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02651       opserr << " : invalid number of node args: " << argv[8] << endln;
02652       Tcl_Free((char *)argvNodes);
02653       return TCL_ERROR; 
02654     }
02655     int nodeTag;
02656     double value;
02657     if (Tcl_GetInt (interp, argvNodes[count], &nodeTag) != TCL_OK) {
02658       opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02659       opserr << " : invalid node id in node args: " << argvNodes[count] << endln;
02660       Tcl_Free((char *)argvNodes);
02661       return TCL_ERROR; 
02662     }
02663     if (nodeTag < 1 || nodeTag > 27) {
02664       opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02665       opserr << " : node tag out of bounds [1, 27]: " << argvNodes[count] << endln;
02666       Tcl_Free((char *)argvNodes);
02667       return TCL_ERROR;
02668     }
02669     for (int i=0; i<ndm; i++) {
02670       if (Tcl_GetDouble(interp, argvNodes[count+1+i], &value) != TCL_OK) {
02671         opserr << "WARNING block3D numX? numY? numZ? startNode? startEle? eleType? eleArgs?";
02672         opserr << " : invalid coordinate in node args: " << argvNodes[count] << endln;
02673         Tcl_Free((char *)argvNodes);
02674         return TCL_ERROR;
02675       }
02676       Coordinates(nodeTag-1,i) = value;
02677       haveNode(nodeTag-1) = nodeTag;
02678     }      
02679     count += 1 + ndm;
02680   }
02681 
02682   Tcl_Free((char *)argvNodes);
02683 
02684   Block3D  theBlock(numX, numY, numZ, haveNode, Coordinates);
02685 
02686   // create the nodes: (numX+1)*(numY+1) nodes to be created
02687   int nodeID = startNodeNum;
02688   int kk;
02689   for (kk=0; kk<=numZ; kk++) {
02690     for (int jj=0; jj<=numY; jj++) {
02691       for (int ii=0; ii<=numX; ii++) {
02692         const Vector &nodeCoords = theBlock.getNodalCoords(ii,jj,kk);
02693         double xLoc = nodeCoords(0);
02694         double yLoc = nodeCoords(1);
02695         double zLoc = nodeCoords(2);
02696         Node *theNode = 0;
02697         theNode = new Node(nodeID,ndf,xLoc, yLoc, zLoc);
02698         
02699         if (theNode == 0) {
02700           opserr << "WARNING ran out of memory creating node\n";
02701           opserr << "node: " << nodeID << endln;
02702           return TCL_ERROR;
02703         }
02704 
02705         if (theTclDomain->addNode(theNode) == false) {
02706           opserr << "WARNING failed to add node to the domain\n";
02707           opserr << "node: " << nodeID << endln;
02708           delete theNode; // otherwise memory leak
02709           return TCL_ERROR;
02710         }
02711         
02712         nodeID++;
02713       }
02714     }
02715   }
02716     
02717   // create the elements: numX*numY elements to be created
02718   TCL_Char *eleType = argv[6];
02719   TCL_Char *additionalEleArgs = argv[7];
02720   const ID &nodeTags = theBlock.getElementNodes(0,0,0);  
02721   int numNodes = nodeTags.Size();
02722 
02723   // assumes 15 is largest string for individual nodeTags
02724   count = 10 + strlen(eleType) + strlen(additionalEleArgs) + 15 * (numNodes+1);
02725   char *eleCommand = new char[count];
02726   int initialCount = 8 + strlen(eleType);
02727 
02728   int  eleID = startEleNum;  
02729   for (kk=0; kk<numZ; kk++) {
02730     for (int jj=0; jj<numY; jj++) {
02731       for (int ii=0; ii<numX; ii++) {
02732         count = initialCount;
02733 
02734         const ID &nodeTags = theBlock.getElementNodes(ii,jj,kk);
02735       
02736         // create the string to be evaluated
02737         strcpy(eleCommand, "element ");
02738         strcpy(&eleCommand[8], eleType);
02739         count += sprintf(&eleCommand[count], " %d ", eleID);
02740         for (int i=0; i<numNodes; i++) {
02741           int nodeTag = nodeTags(i)+startNodeNum;
02742           count += sprintf(&eleCommand[count], " %d ", nodeTag);
02743         }
02744         strcat(eleCommand, additionalEleArgs);      
02745         
02746         // now to create the element we get the string eveluated
02747         if (Tcl_Eval(interp, eleCommand) != TCL_OK) {
02748         delete [] eleCommand;
02749           return TCL_ERROR;
02750         }
02751         eleID++;
02752       }
02753     }
02754   }
02755 
02756   delete [] eleCommand;
02757   return TCL_OK;
02758 }
02759 
02760 
02761 
02762 
02763 int
02764 TclModelBuilder_addRemoPatch(ClientData clientData, Tcl_Interp *interp, int argc,   
02765                            TCL_Char **argv)
02766 {
02767   return TclModelBuilder_addPatch(clientData, interp, argc,argv,
02768                                     theTclBuilder);
02769 }
02770 
02771 int
02772 TclModelBuilder_addRemoFiber(ClientData clientData, Tcl_Interp *interp, int argc,   
02773                            TCL_Char **argv)
02774 {
02775   return TclModelBuilder_addFiber(clientData, interp, argc,argv,
02776                                   theTclBuilder);
02777 }
02778 
02779 int
02780 TclModelBuilder_addRemoLayer(ClientData clientData, Tcl_Interp *interp, int argc,   
02781                            TCL_Char **argv)
02782 {
02783   return TclModelBuilder_addReinfLayer(clientData, interp, argc,argv,
02784                                        theTclBuilder);
02785 }
02786 
02787 
02788                                          
02789 int
02790 TclModelBuilder_addRemoGeomTransf(ClientData clientData, Tcl_Interp *interp, int argc,   
02791                            TCL_Char **argv)
02792 {
02793   return TclModelBuilder_addGeomTransf(clientData, interp, argc,argv,
02794                                        theTclDomain,
02795                                        theTclBuilder);
02796 }
02797 
02798 #ifdef OO_HYSTERETIC
02799 extern int
02800 TclModelBuilderStiffnessDegradationCommand(ClientData clientData,
02801                                            Tcl_Interp *interp,
02802                                            int argc, TCL_Char **argv,
02803                                            TclModelBuilder *theTclBuilder);
02804 
02805 int
02806 TclModelBuilder_addStiffnessDegradation(ClientData clientData,
02807                                         Tcl_Interp *interp,
02808                                         int argc, TCL_Char **argv)
02809 {
02810   return TclModelBuilderStiffnessDegradationCommand(clientData, interp, 
02811                                                     argc, argv, theTclBuilder);
02812 }
02813 
02814 extern int
02815 TclModelBuilderUnloadingRuleCommand(ClientData clientData,
02816                                     Tcl_Interp *interp,
02817                                     int argc, TCL_Char **argv,
02818                                     TclModelBuilder *theTclBuilder);
02819 
02820 int
02821 TclModelBuilder_addUnloadingRule(ClientData clientData,
02822                                  Tcl_Interp *interp,
02823                                  int argc, TCL_Char **argv)
02824 {
02825   return TclModelBuilderUnloadingRuleCommand(clientData, interp, 
02826                                              argc, argv, theTclBuilder);
02827 }
02828 
02829 extern int
02830 TclModelBuilderStrengthDegradationCommand(ClientData clientData,
02831                                           Tcl_Interp *interp,
02832                                           int argc, TCL_Char **argv,
02833                                           TclModelBuilder *theTclBuilder);
02834 
02835 int
02836 TclModelBuilder_addStrengthDegradation(ClientData clientData,
02837                                        Tcl_Interp *interp,
02838                                        int argc, TCL_Char **argv)
02839 {
02840   return TclModelBuilderStrengthDegradationCommand(clientData, interp, 
02841                                                    argc, argv, theTclBuilder);
02842 }
02843 
02844 extern int
02845 TclModelBuilderHystereticBackboneCommand(ClientData clientData,
02846                                          Tcl_Interp *interp,
02847                                          int argc, TCL_Char **argv,
02848                                          TclModelBuilder *theTclBuilder);
02849 
02850 int
02851 TclModelBuilder_addHystereticBackbone(ClientData clientData,
02852                                       Tcl_Interp *interp,
02853                                       int argc, TCL_Char **argv)
02854 {
02855   return TclModelBuilderHystereticBackboneCommand(clientData, interp, 
02856                                                   argc, argv, theTclBuilder);
02857 }
02858 #endif
02859 
02861 extern int 
02862 TclModelBuilderUpdateMaterialStageCommand(ClientData clientData, 
02863                                           Tcl_Interp *interp, 
02864                                           int argc, 
02865                                           TCL_Char **argv, 
02866                                           TclModelBuilder *theTclBuilder);
02867 int
02868 TclModelBuilder_UpdateMaterialStage(ClientData clientData, 
02869                                     Tcl_Interp *interp,  
02870                                     int argc, 
02871                                     TCL_Char **argv)
02872 {
02873   return TclModelBuilderUpdateMaterialStageCommand(clientData, interp, 
02874                                        argc, argv, theTclBuilder);
02875 }
02876 
02878 extern int 
02879 TclModelBuilderUpdateParameterCommand(ClientData clientData, 
02880                                           Tcl_Interp *interp, 
02881                                           int argc, 
02882                                           TCL_Char **argv, 
02883                                           TclModelBuilder *theTclBuilder);
02884 int
02885 TclModelBuilder_UpdateParameter(ClientData clientData, 
02886                                     Tcl_Interp *interp,  
02887                                     int argc, 
02888                                     TCL_Char **argv)
02889 {
02890   return TclModelBuilderUpdateParameterCommand(clientData, interp, 
02891                                        argc, argv, theTclBuilder);
02892 }
02893 
02894 int 
02895 TclModelBuilder::addDamageModel(DamageModel &theDM)
02896 {
02897   bool result = theDamageModels->addComponent(&theDM);
02898   if (result == true)
02899     return 0;
02900   else {
02901     opserr << "TclModelBuilder::addDamageModel() - failed to add : " << theDM;
02902     return -1;
02903   }
02904 }
02905 
02906 DamageModel * 
02907 TclModelBuilder::getDamageModel(int tag)
02908 {
02909   TaggedObject *mc = theDamageModels->getComponentPtr(tag);
02910   if (mc == 0)
02911     return 0;
02912 
02913   // otherweise we do a cast and return
02914   DamageModel *result = (DamageModel *)mc;
02915   return result;
02916 }
02917 
02918 int 
02919 TclModelBuilder_Package(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
02920 {
02921   
02922   void *libHandle;
02923   int (*funcPtr)(ClientData clientData, Tcl_Interp *interp,  int argc, 
02924                  TCL_Char **argv, Domain*, TclModelBuilder*);       
02925   
02926   const char *funcName = 0;
02927   int res = -1;
02928   
02929   if (argc == 2) {
02930     res = getLibraryFunction(argv[1], argv[1], &libHandle, (void **)&funcPtr);
02931   } else if (argc == 3) {
02932     res = getLibraryFunction(argv[1], argv[2], &libHandle, (void **)&funcPtr);
02933   }
02934 
02935   if (res == 0) {
02936     int result = (*funcPtr)(clientData, interp,
02937                             argc, 
02938                             argv,
02939                             theTclDomain,
02940                             theTclBuilder);     
02941   } else {
02942     opserr << "Error: Could not find function: " << argv[1] << res << endln;
02943     return -1;
02944   }
02945 
02946   return res;
02947 }
02948 
02949 
02950 

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