Add A New Element

From OpenSeesWiki
Revision as of 23:03, 12 July 2010 by Fmk (talk | contribs)
Jump to navigation Jump to search

To add a new Element into the interpreted applications, the developer must:

  1. provide a new C++ subclass of the Element class
  2. provide an interface function that will be used to parse the input and create the new element.

Element Class

The Element class itself is an abstract base class. It inherits from both the DomainComponent class, which is itself a subclass of TaggedObject class and the MovableObject class. The class has a large number of methods defined in the interface, not all these methods need to be included in a new Element class. The following is the minimal interface that should be considered:

The Element Class:

class Element : public DomainComponent
{
  public:
    Element(int tag, int classTag);
    virtual ~Element();

    // methods dealing with nodes and number of external dof                          
    virtual int getNumExternalNodes(void) const =0;
    virtual const ID &getExternalNodes(void)  =0;
    virtual Node **getNodePtrs(void)  =0;
    virtual int getNumDOF(void) =0;

    // methods dealing with committed state and update                                
    virtual int commitState(void);
    virtual int revertToLastCommit(void) = 0;
    virtual int revertToStart(void);
    virtual int update(void);
    virtual bool isSubdomain(void);

    // methods dealing with element stiffness                                                      
    virtual const Matrix &getTangentStiff(void) =0;
    virtual const Matrix &getInitialStiff(void) =0;

  
    // methods dealing with element forces 
    virtual void zeroLoad(void);
    virtual int addLoad(ElementalLoad *theLoad, double loadFactor);        
    virtual const Vector &getResistingForce(void) =0;

    // method for obtaining information specific to an element                   
    virtual Response *setResponse(const char **argv, int argc, OPS_Stream &theHandler);
    virtual int getResponse(int responseID, Information &eleInformation);
}

Example - Truss2D

In the following section we will provide all necessary code to add a new 2d planar truss element into an OpenSees interpreter. To demonstrate the power of object-oriented programming, the stress-strain relationship will be provided by a UniaxialMaterial object.

Header

The header for thew new class, which we will call Truss2D is as follows:

// include directives
#include <Element.h>
#include <Matrix.h>
#include <Vector.h>

// forward declarations
class Node;
class UniaxialMaterial;

class Truss2D : public Element
{
  public:
    // constructors                                                                   
    Truss2D(int tag,
            int Nd1, int Nd2,
            UniaxialMaterial &theMaterial,
            double A);

    Truss2D();

    // destructor                                                                     
    ~Truss2D();


    // public methods to obtain inforrmation about dof & connectivity                 
    int getNumExternalNodes(void) const;
    const ID &getExternalNodes(void);
    Node **getNodePtrs(void);
    int getNumDOF(void);
    void setDomain(Domain *theDomain);

    // public methods to set the state of the element                                 
    int commitState(void);
    int revertToLastCommit(void);
    int revertToStart(void);
    int update(void);

   // public methods to obtain stiffness, mass, damping and residual information    
    const Matrix &getTangentStiff(void);
    const Matrix &getInitialStiff(void);

    const Vector &getResistingForce(void);

    // public methods for output                                                      
    int sendSelf(int commitTag, Channel &theChannel);
    int recvSelf(int commitTag, Channel &theChannel, FEM_ObjectBroker &theBroker);
    void Print(OPS_Stream &s, int flag =0);

    Response *setResponse(const char **argv, int argc, OPS_Stream &s);
    int getResponse(int responseID, Information &eleInformation);

  protected:

  private:
    // private member functions - only available to objects of the class              
    double computeCurrentStrain(void) const;

    // private attributes - a copy for each object of the class                       
    UniaxialMaterial *theMaterial;       // pointer to a material                     
    ID  externalNodes;                   // contains the id's of end nodes            
    Matrix trans;       // hold the transformation matrix, could use a Vector         
                        // if ever bother to change the Vector interface for          
                        // x-product.                                                 

    double L;           // length of truss (undeformed configuration) - set in setDom\
ain()                                                                                 
    double A;           // area of truss                                              
    Node *theNodes[2];  // node pointers                                              

    // static data - single copy for all objects of the class                         
    static Matrix trussK;   // class wide matrix for returning stiffness                            
    static Vector trussR;   // class wide vector for returning residual               
};
#endif

The header file defines the interface and variables for the class Truss2D. It defines the new class to be a sublass of the Element class. In the public interface are 2 constructors and 1 destructor in addition to minimal set of methods we showed for the Element class. There are no protected data or methods as we do not expect this class to be subclassed. In the private section we define one private method, computeCurrentStrain(), we define a number of private variables, and we also define a number of static variables.

The header has a number of #include directives, one is needed for the base class and every class used as a variable in the list of data (except those that are used as pointers). For those classes that only appear as pointers in the header file (Node, UniaxialMaterial) a forward declaration is all that is needed (the include could also have been used, but using the forward declaration simplifies dependencies and reduces the amount of code that ha to be recompiled later if changes are made).