00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
00056 if (theTclBuilder == 0) {
00057 opserr << "WARNING builder has been destroyed\n";
00058 return TCL_ERROR;
00059 }
00060
00061
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
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
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], §ID) != 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
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
00184 return TCL_OK;
00185 }
00186
00187
00188