TclParameterCommands.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 2001, 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.1 $
00022 // $Date: 2006/09/05 20:21:04 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/component/TclParameterCommands.cpp,v $
00024 
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <OPS_Stream.h>
00028 #include <Domain.h>
00029 
00030 #include <TclModelBuilder.h>
00031 
00032 #include <Parameter.h>
00033 
00034 int
00035 TclModelBuilderParameterCommand(ClientData clientData, Tcl_Interp *interp,
00036                                 int argc, TCL_Char **argv,
00037                                 Domain *theTclDomain,
00038                                 TclModelBuilder *theTclBuilder)
00039 {
00040   // ensure the destructor has not been called -
00041   if (theTclBuilder == 0) {
00042     opserr << "WARNING builder has been destroyed\n";
00043     return TCL_ERROR;
00044   }
00045   
00046   // check at least two arguments so don't segemnt fault on strcmp
00047   if (argc < 2) {
00048     opserr << "WARNING need to specify a parameter tag\n";
00049     opserr << "Want: parameter tag <specific parameter args> .. see manual for valid parameter types and arguments\n";
00050     return TCL_ERROR;
00051   }
00052 
00053   // Figure out which parameter we are dealing with
00054   int paramTag;
00055   if (Tcl_GetInt(interp, argv[1], &paramTag) != TCL_OK) {
00056 
00057     return TCL_ERROR;    
00058   }
00059 
00060   Parameter *theParameter = theTclDomain->getParameter(paramTag);
00061 
00062   // Now handle the parameter according to which command is invoked
00063   if (strcmp(argv[0],"parameter") == 0 || strcmp(argv[0],"addToParameter") == 0) {
00064 
00065     int argStart = 0;
00066 
00067     DomainComponent *theObject;
00068 
00069     if (strcmp(argv[2],"element") == 0) {
00070 
00071       if (argc < 4) {
00072         opserr << "WARNING parameter -- insufficient number of arguments for parameter with tag " << paramTag << '\n';
00073         return TCL_ERROR;
00074       }
00075 
00076       int eleTag;
00077       if (Tcl_GetInt(interp, argv[3], &eleTag) != TCL_OK) {
00078         opserr << "WARNING parameter -- invalid element tag\n";
00079         return TCL_ERROR;    
00080       }
00081 
00082       // Retrieve element from domain
00083       theObject = (DomainComponent *) theTclDomain->getElement(eleTag);
00084 
00085       argStart = 4;
00086     }
00087     else if (strcmp(argv[2],"node") == 0) {
00088 
00089     }
00090     else if (strcmp(argv[2],"loadPattern") == 0) {
00091       if (argc < 4) {
00092         opserr << "WARNING parameter -- insufficient number of arguments for parameter with tag " << paramTag << '\n';
00093         return TCL_ERROR;
00094       }
00095 
00096       int loadTag;
00097       if (Tcl_GetInt(interp, argv[3], &loadTag) != TCL_OK) {
00098         opserr << "WARNING parameter -- invalid load pattern tag\n";
00099         return TCL_ERROR;    
00100       }
00101 
00102       // Retrieve element from domain
00103       theObject = (DomainComponent *) theTclDomain->getLoadPattern(loadTag);
00104 
00105       argStart = 4;
00106     }
00107     else {
00108       opserr << "WARNING - unable to assign parameter to object of type "
00109              << argv[2] << '\n';
00110       return TCL_ERROR;
00111     }
00112 
00114 
00115     // Create new parameter
00116     if (strcmp(argv[0],"parameter") == 0) {
00117       
00118       if (theParameter != 0) {
00119         opserr << "WARNING parameter -- parameter with tag " << paramTag
00120                << " already exists in domain\n";
00121         return TCL_ERROR;
00122       }
00123       else {
00124         Parameter *newParameter = new Parameter(paramTag, theObject,
00125                                                 &argv[argStart],
00126                                                 argc-argStart);
00127         
00128         theTclDomain->addParameter(newParameter);
00129       }
00130     }
00131     // Add to an existing parameter
00132     if (strcmp(argv[0],"addToParameter") == 0) {
00133       
00134       if (theParameter == 0) {
00135         opserr << "WARNING addToParameter -- parameter with tag " << paramTag
00136                << " not found in domain\n";
00137         return TCL_ERROR;
00138       }
00139       else {
00140         theParameter->addObject(theObject, &argv[argStart], argc-argStart);
00141       }
00142     }
00143 
00144     return TCL_OK;
00145   }
00146   
00147   if (strcmp(argv[0],"updateParameter") == 0) {
00148     
00149     // Cannot update a parameter that is not present
00150     if (theParameter == 0) {
00151       opserr << "WARNING updateParameter -- parameter with tag " << paramTag
00152              << " not found in domain\n";
00153       return TCL_ERROR;
00154     }
00155     
00156     double newValue;
00157     if (Tcl_GetDouble(interp, argv[2], &newValue) != TCL_OK) {
00158       opserr << "WARNING updateParameter -- invalid parameter value\n";
00159       return TCL_ERROR;
00160     }
00161 
00162     theParameter->update(newValue);
00163 
00164   }
00165 
00166   return TCL_OK;
00167 }

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