Add A New Element: Difference between revisions

From OpenSeesWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
To add a new Element into the interpreted applications, the developer must:
The OpenSees applications allows developers to use their own element modules to the application. Unlike most other programs, the elements are added at run-time and not at compile time. The advantage of this is the the developers:
# provide a new C++ subclass of the Element class
# Do not need the OpenSees source files or libraries to compile and link the application.
# provide an interface function that will be used to parse the input and create the new element.  
# Can share their modules with others without having to provide the source code.


=== Element Class ===
The element modules can be written using either C++, C, or Fortran. Whatever the language the developer wishes to use,
the element modules make use of the [[OpenSees API]] to for example find nodal coordinates and displacements, and make use of material modules
that exist in OpenSees or are also added as external routines.


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.
# [[Add a New Element C++]]
The following is the minimal interface that should be considered:
# [[Add a New Element C]]
 
# [[Add a New Element Fortran]]
The Element Class:
 
<source lang="cpp">
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);
}
 
</source>
 
=== 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:
 
<source lang="cpp">
// 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
</source>
 
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).

Latest revision as of 23:04, 13 July 2010

The OpenSees applications allows developers to use their own element modules to the application. Unlike most other programs, the elements are added at run-time and not at compile time. The advantage of this is the the developers:

  1. Do not need the OpenSees source files or libraries to compile and link the application.
  2. Can share their modules with others without having to provide the source code.

The element modules can be written using either C++, C, or Fortran. Whatever the language the developer wishes to use, the element modules make use of the OpenSees API to for example find nodal coordinates and displacements, and make use of material modules that exist in OpenSees or are also added as external routines.

  1. Add a New Element C++
  2. Add a New Element C
  3. Add a New Element Fortran