TclTrussCommand.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.6 $
00022 // $Date: 2003/03/12 19:20:46 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/element/truss/TclTrussCommand.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/element/TclTrussCommand.C
00027 // 
00028 // Written: fmk 
00029 // Created: 07/99
00030 // Revision: A
00031 //
00032 // Description: This file contains the implementation of the TclModelBuilder_addTruss()
00033 // command. 
00034 //
00035 // What: "@(#) TclModelBuilder.C, revA"
00036 
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <Domain.h>
00040 
00041 #include <Truss.h>
00042 #include <TrussSection.h>
00043 #include <TclModelBuilder.h>
00044 #include <CorotTruss.h>
00045 #include <CorotTrussSection.h>
00046 
00047 
00048 extern void printCommand(int argc, TCL_Char **argv);
00049 
00050 int
00051 TclModelBuilder_addTruss(ClientData clientData, Tcl_Interp *interp,  int argc, 
00052                          TCL_Char **argv, Domain*theTclDomain,
00053                          TclModelBuilder *theTclBuilder, int eleArgStart)
00054 {
00055   // ensure the destructor has not been called - 
00056   if (theTclBuilder == 0) {
00057     opserr << "WARNING builder has been destroyed\n";    
00058     return TCL_ERROR;
00059   }
00060 
00061   // check the number of arguments is correct
00062   if ((argc-eleArgStart) < 5) {
00063     opserr << "WARNING insufficient arguments\n";
00064     printCommand(argc, argv);
00065     opserr << "Want: element truss eleTag? iNode? jNode? A? matTag?\n";
00066     opserr << " -or- element truss eleTag? iNode? jNode? sectTag?" << endln;
00067     return TCL_ERROR;
00068   }    
00069 
00070   int ndm = theTclBuilder->getNDM();
00071 
00072   // get the id and end nodes 
00073   int trussId, iNode, jNode, matID;
00074   double A;
00075   double rho = 0.0;
00076   if (Tcl_GetInt(interp, argv[1+eleArgStart], &trussId) != TCL_OK) {
00077     opserr << "WARNING invalid truss eleTag" << endln;
00078     return TCL_ERROR;
00079   }
00080   if (Tcl_GetInt(interp, argv[2+eleArgStart], &iNode) != TCL_OK) {
00081     opserr << "WARNING invalid iNode\n";
00082     opserr << "truss element: " << trussId << endln;
00083     return TCL_ERROR;
00084   }
00085   if (Tcl_GetInt(interp, argv[3+eleArgStart], &jNode) != TCL_OK) {
00086      opserr << "WARNING invalid jNode\n";
00087      opserr << "truss element: " << trussId << endln;
00088      return TCL_ERROR;
00089   }
00090 
00091   for (int i = 4+eleArgStart; i < argc; i++) {
00092     if (i+1 < argc && strcmp(argv[i], "-rho") == 0) {
00093       if (Tcl_GetDouble(interp, argv[i+1], &rho) != TCL_OK) {
00094         opserr << "WARNING invalid rho\n";
00095         opserr << "truss element: " << trussId << endln;
00096         return TCL_ERROR;
00097       }
00098       argc -= 2;
00099       break;
00100     }
00101   }
00102 
00103   if ((argc-eleArgStart) == 6) {  
00104       if (Tcl_GetDouble(interp, argv[4+eleArgStart], &A) != TCL_OK) {
00105           opserr << "WARNING invalid A\n";
00106           opserr << "truss element: " << trussId << endln;
00107           return TCL_ERROR;
00108       }
00109 
00110       if (Tcl_GetInt(interp, argv[5+eleArgStart], &matID) != TCL_OK) {
00111           opserr << "WARNING invalid matTag\n";
00112           opserr << "truss element: " << trussId << endln;
00113           return TCL_ERROR;
00114       }
00115       
00116       UniaxialMaterial *theMaterial = theTclBuilder->getUniaxialMaterial(matID);
00117       
00118       if (theMaterial == 0) {
00119           opserr << "WARNING material not found\n";
00120           opserr << "Material: " << matID;
00121           opserr << "\ntruss element: " << trussId << endln;
00122           return TCL_ERROR;
00123       }
00124 
00125       // now create the truss and add it to the Domain
00126       Element *theTruss = 0;
00127       if (strcmp(argv[eleArgStart],"corotTruss") == 0)
00128           theTruss = new CorotTruss(trussId,ndm,iNode,jNode,*theMaterial,A,rho);
00129       else
00130           theTruss = new Truss(trussId,ndm,iNode,jNode,*theMaterial,A,rho);
00131 
00132       if (theTruss == 0) {
00133           opserr << "WARNING ran out of memory creating element\n";
00134           opserr << "truss element: " << trussId << endln;
00135           return TCL_ERROR;
00136       }
00137 
00138       if (theTclDomain->addElement(theTruss) == false) {
00139           opserr << "WARNING could not add element to the domain\n";
00140           opserr << "truss element: " << trussId << endln;
00141           delete theTruss;
00142           return TCL_ERROR;
00143       }
00144   } else {
00145       int sectID;
00146       if (Tcl_GetInt(interp, argv[4+eleArgStart], &sectID) != TCL_OK) {
00147           opserr << "WARNING invalid matTag\n";
00148           opserr << "truss element: " << trussId << endln;
00149           return TCL_ERROR;
00150       }
00151       
00152       SectionForceDeformation *theSection = theTclBuilder->getSection(sectID);
00153 
00154       if (theSection == 0) {
00155               opserr << "WARNING section not found\n";
00156               opserr << "section tag: " << sectID;
00157               opserr << "\ntruss element: " << trussId << endln;
00158               return TCL_ERROR;
00159       }
00160   
00161       // now create the truss and add it to the Domain
00162       Element *theTruss = 0;
00163       if (strcmp(argv[eleArgStart],"corotTruss") == 0)
00164           theTruss = new CorotTrussSection(trussId,ndm,iNode,jNode,*theSection,rho);
00165       else
00166           theTruss = new TrussSection(trussId,ndm,iNode,jNode,*theSection,rho);
00167       
00168       if (theTruss == 0) {
00169           opserr << "WARNING ran out of memory creating element\n";
00170           opserr << "truss element: " << trussId << endln;
00171           return TCL_ERROR;
00172       }
00173 
00174       if (theTclDomain->addElement(theTruss) == false) {
00175           opserr << "WARNING could not add element to the domain\n";
00176           opserr << "truss element: " << trussId << endln;
00177           delete theTruss;
00178           return TCL_ERROR;
00179       }
00180   }
00181       
00182 
00183   // if get here we have sucessfully created the node and added it to the domain
00184   return TCL_OK;
00185 }
00186 
00187 
00188 

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