TclUniaxialMaterialTester.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.5 $
00022 // $Date: 2003/02/25 23:34:26 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/modelbuilder/tcl/TclUniaxialMaterialTester.cpp,v $
00024                                                                         
00025 // File: ~/modelbuilder/tcl/TclUniaxialMaterialTester.C
00026 // 
00027 // Written: fmk 
00028 // Created: 03/01
00029 //
00030 // Description: This file contains the implementaion of the TclUniaxialMaterialTester class.
00031 //
00032 // What: "@(#) TclUniaxialMaterialTester.C, revA"
00033 
00034 #include <stdlib.h>
00035 #include <string.h>
00036 
00037 #include <ArrayOfTaggedObjects.h>
00038 #include <UniaxialMaterial.h>
00039 #include <TclUniaxialMaterialTester.h>
00040 
00041 //
00042 // SOME STATIC POINTERS USED IN THE FUNCTIONS INVOKED BY THE INTERPRETER
00043 //
00044 
00045 static TclUniaxialMaterialTester *theTclBuilder =0;
00046 static UniaxialMaterial *theTestingUniaxialMaterial =0;
00047 
00048 // 
00049 // THE PROTOTYPES OF THE FUNCTIONS INVOKED BY THE INTERPRETER
00050 //
00051 
00052 int  TclUniaxialMaterialTester_setUniaxialMaterial(ClientData clientData, Tcl_Interp *interp, 
00053                                                    int argc,   TCL_Char **argv);
00054                                     
00055 int  TclUniaxialMaterialTester_setStrainUniaxialMaterial(ClientData clientData, Tcl_Interp *interp,
00056                                                          int argc,   TCL_Char **argv);
00057 
00058 int  TclUniaxialMaterialTester_getStressUniaxialMaterial(ClientData clientData, Tcl_Interp *interp,
00059                                                          int argc,   TCL_Char **argv);
00060 
00061 
00062 int  TclUniaxialMaterialTester_getTangUniaxialMaterial(ClientData clientData, Tcl_Interp *interp,
00063                                                        int argc,   TCL_Char **argv);
00064 
00065 //
00066 // CLASS CONSTRUCTOR & DESTRUCTOR
00067 //
00068 
00069 static int count;
00070 static int countsTillCommit;
00071                                     
00072 // constructor: the constructor will add certain commands to the interpreter
00073 TclUniaxialMaterialTester::TclUniaxialMaterialTester(Domain &theDomain, Tcl_Interp *interp, int cTC)
00074   :TclModelBuilder(theDomain, interp, 1, 1), theInterp(interp)
00075 {
00076   countsTillCommit = cTC;
00077   Tcl_CreateCommand(interp, "uniaxialTest", TclUniaxialMaterialTester_setUniaxialMaterial,
00078                     (ClientData)NULL, NULL);
00079 
00080   Tcl_CreateCommand(interp, "strainUniaxialTest", TclUniaxialMaterialTester_setStrainUniaxialMaterial,
00081                     (ClientData)NULL, NULL);
00082 
00083   Tcl_CreateCommand(interp, "stressUniaxialTest", TclUniaxialMaterialTester_getStressUniaxialMaterial,
00084                     (ClientData)NULL, NULL);
00085 
00086   Tcl_CreateCommand(interp, "tangUniaxialTest", TclUniaxialMaterialTester_getTangUniaxialMaterial,
00087                     (ClientData)NULL, NULL);
00088   
00089   
00090   // set the static pointers in this file
00091   theTclBuilder = this;
00092 }
00093 
00094 TclUniaxialMaterialTester::~TclUniaxialMaterialTester()
00095 {
00096 
00097   theTclBuilder =0;
00098 
00099   Tcl_DeleteCommand(theInterp, "uniaxialTest");
00100   Tcl_DeleteCommand(theInterp, "strainUniaxialTest");
00101   Tcl_DeleteCommand(theInterp, "stressUniaxialTest");
00102   Tcl_DeleteCommand(theInterp, "tangUniaxialTest");
00103 }
00104 
00105 
00106 //
00107 // THE FUNCTIONS INVOKED BY THE INTERPRETER
00108 //
00109 
00110 int
00111 TclUniaxialMaterialTester_setUniaxialMaterial(ClientData clientData, Tcl_Interp *interp, int argc,   
00112                                               TCL_Char **argv)
00113 {
00114   count = 1;
00115   // ensure the destructor has not been called - 
00116   if (theTclBuilder == 0) {
00117     Tcl_SetResult(interp, "WARNING builder has been destroyed", TCL_STATIC);
00118     return TCL_ERROR;
00119   }
00120 
00121   // check number of arguments in command line
00122   if (argc < 2) {
00123     Tcl_SetResult(interp, "WARNING bad command - want: uniaxialTest matID?", TCL_STATIC);
00124     return TCL_ERROR;
00125   }    
00126 
00127   // get the matID form command line
00128   int matID;
00129   if (Tcl_GetInt(interp, argv[1], &matID) != TCL_OK) {
00130     Tcl_SetResult(interp, "WARNING could not read matID: uniaxialTest matID?", TCL_STATIC);
00131     return TCL_ERROR;
00132   }
00133 
00134   // delete the old testing material
00135   if (theTestingUniaxialMaterial !=0) {
00136     delete theTestingUniaxialMaterial;
00137     theTestingUniaxialMaterial = 0;
00138   }
00139 
00140   // get the material from the modelbuilder with matID 
00141   // and set the testing material to point to a copy of it
00142   UniaxialMaterial *theOrigMaterial = theTclBuilder->getUniaxialMaterial(matID);
00143   if (theOrigMaterial == 0) {
00144     Tcl_SetResult(interp, "WARNING no material found with matID", TCL_STATIC);
00145     return TCL_ERROR;
00146   }  else {
00147     theTestingUniaxialMaterial = theOrigMaterial->getCopy();
00148   }
00149 
00150   return TCL_OK;
00151 }
00152 
00153 
00154 int  
00155 TclUniaxialMaterialTester_setStrainUniaxialMaterial(ClientData clientData, Tcl_Interp *interp,
00156                                                     int argc,   TCL_Char **argv)
00157 {
00158   // ensure the destructor has not been called - 
00159   if (theTclBuilder == 0) {
00160     Tcl_SetResult(interp, "WARNING builder has been destroyed", TCL_STATIC);
00161     return TCL_ERROR;
00162   }
00163 
00164   // check number of arguments in command line
00165   if (argc < 2) {
00166     Tcl_SetResult(interp, "WARNING bad command - want: strainUniaxialTest strain?", TCL_STATIC);
00167     return TCL_ERROR;
00168   }    
00169 
00170   // get the matID form command line
00171   double strain;
00172   if (Tcl_GetDouble(interp, argv[1], &strain) != TCL_OK) {
00173     Tcl_SetResult(interp, "WARNING could not read strain: strainUniaxialTest strain?", TCL_STATIC);
00174     return TCL_ERROR;
00175   }
00176 
00177   // delete the old testing material
00178   if (theTestingUniaxialMaterial !=0) {
00179     theTestingUniaxialMaterial->setTrialStrain(strain);
00180     if (count == countsTillCommit) {
00181       theTestingUniaxialMaterial->commitState();    
00182       count = 1;
00183     } else count++;
00184   }
00185   return TCL_OK;
00186 }
00187 
00188 
00189 
00190 int  TclUniaxialMaterialTester_getStressUniaxialMaterial(ClientData clientData, Tcl_Interp *interp,
00191                                                          int argc,   TCL_Char **argv)
00192 {
00193   double stress = 0.0;
00194 
00195   // delete the old testing material
00196   if (theTestingUniaxialMaterial !=0) {
00197     stress = theTestingUniaxialMaterial->getStress();
00198     sprintf(interp->result,"%.10e",stress);
00199     return TCL_OK;
00200   } else {
00201     Tcl_SetResult(interp, "WARNING no active UniaxialMaterial - use uniaxialTest command", TCL_STATIC);    
00202     return TCL_ERROR;
00203   }
00204 }
00205 
00206 int  TclUniaxialMaterialTester_getTangUniaxialMaterial(ClientData clientData, Tcl_Interp *interp,
00207                                                        int argc,   TCL_Char **argv)
00208 {
00209   double tangent = 0.0;
00210 
00211   // delete the old testing material
00212   if (theTestingUniaxialMaterial !=0) {
00213     tangent = theTestingUniaxialMaterial->getTangent();
00214     sprintf(interp->result,"%.10e",tangent);
00215     return TCL_OK;
00216   } else {
00217     Tcl_SetResult(interp, "WARNING no active UniaxialMaterial - use uniaxialTest command", TCL_STATIC);    
00218     return TCL_ERROR;
00219   }
00220 }
00221 
00222   
00223 
00224 
00225 

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