xc
ElementBase.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // XC program; finite element analysis code
4 // for structural analysis and design.
5 //
6 // Copyright (C) Luis C. Pérez Tato
7 //
8 // This program derives from OpenSees <http://opensees.berkeley.edu>
9 // developed by the «Pacific earthquake engineering research center».
10 //
11 // Except for the restrictions that may arise from the copyright
12 // of the original program (see copyright_opensees.txt)
13 // XC is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // This software is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program.
26 // If not, see <http://www.gnu.org/licenses/>.
27 //----------------------------------------------------------------------------
28 //ElementBase.h
29 
30 #ifndef ElementBase_h
31 #define ElementBase_h
32 
33 #include "Element.h"
34 #include "domain/mesh/element/utils/NodePtrsWithIDs.h"
35 #include "material/Material.h"
36 #include "domain/domain/Domain.h"
37 #include "utility/geom/pos_vec/Pos3d.h"
38 
39 namespace XC {
40 class Node;
41 
43 //
46 template <int NNODES>
47 class ElementBase: public Element
48  {
49  protected:
51 
52  template <class TIPOMAT>
53  TIPOMAT *cast_material(const Material *ptr_mat);
54 
55  int sendData(Communicator &comm);
56  int recvData(const Communicator &comm);
57 
58  public:
59  ElementBase(int tag, int classTag);
60  ElementBase(const ElementBase &);
62 
64  static inline const int numNodes(void)
65  { return NNODES; }
66  // public methods to obtain information about dof & connectivity
67  int getNumExternalNodes(void) const;
69  const NodePtrsWithIDs &getNodePtrs(void) const;
70  Pos3d getCenterOfMassPosition(bool initialGeometry= true) const;
71 
72  boost::python::dict getPyDict(void) const;
73  void setPyDict(const boost::python::dict &);
74  };
75 
76 
77 
79 template <int NNODES>
81  : Element(tag,classTag), theNodes(this,NNODES) {}
82 
84 template <int NNODES>
86  : Element(other), theNodes(other.theNodes)
87  { theNodes.set_owner(this); }
88 
90 template <int NNODES>
92  {
93  Element::operator=(other);
94  theNodes= other.theNodes;
95  theNodes.set_owner(this);
96  return *this;
97  }
98 
100 template <int NNODES>
102  { return theNodes.size(); }
103 
105 template <int NNODES>
107  { return theNodes; }
108 
110 template <int NNODES>
112  { return theNodes; }
113 
115 template <int NNODES> template <class TIPOMAT>
117  {
118  TIPOMAT *retval= nullptr;
119  const TIPOMAT *tmp = dynamic_cast<const TIPOMAT *>(ptr_mat);
120  if(tmp)
121  retval= tmp->getCopy();
122  else
123  {
124  std::cerr << getClassName() << "::" << __FUNCTION__
125  << "; on element: " << getTag()
126  << " the material " << ptr_mat->getTag()
127  << " with name: " << ptr_mat->getName()
128  << " and type: " << ptr_mat->getClassName()
129  << " has not a suitable type." << std::endl;
130  abort();
131  }
132  if(!retval)
133  {
134  std::cerr << getClassName() << "::" << __FUNCTION__
135  << "; on element: " << getTag()
136  << "can't get a copy of the material with tag: "
137  << ptr_mat->getTag() << std::endl;
138  abort();
139  }
140  return retval;
141  }
142 
144 template <int NNODES>
146  {
147  int res= Element::sendData(comm);
148  res+= comm.sendMovable(theNodes,getDbTagData(),CommMetaData(6));
149  return res;
150  }
151 
153 template <int NNODES>
155  {
156  int res= Element::recvData(comm);
157  res+= comm.receiveMovable(theNodes,getDbTagData(),CommMetaData(6));
158  return res;
159  }
160 
162 template <int NNODES>
163 boost::python::dict XC::ElementBase<NNODES>::getPyDict(void) const
164  {
165  boost::python::dict retval= Element::getPyDict();
166  retval["nodes"]= theNodes.getPyDict();
167  return retval;
168  }
170 template <int NNODES>
171 void XC::ElementBase<NNODES>::setPyDict(const boost::python::dict &d)
172  {
173  Element::setPyDict(d);
174  theNodes.setPyDict(boost::python::extract<boost::python::dict>(d["nodes"]));
175  }
176 
178 template <int NNODES>
180  { return theNodes.getCenterOfMassPosition(initialGeometry); }
181 
182 } //end of XC namespace
183 #endif
int sendMovable(MovableObject &, DbTagData &, const CommMetaData &)
Sends a movable object through the communicator argument.
Definition: Communicator.cc:1163
NodePtrsWithIDs theNodes
pointers to node.
Definition: ElementBase.h:50
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: ElementBase.h:163
int getNumExternalNodes(void) const
Return the number of external nodes.
Definition: ElementBase.h:101
Communication parameters between processes.
Definition: Communicator.h:66
std::string getName(void) const
Returns the name of the material.
Definition: Material.cpp:167
int receiveMovable(MovableObject &, DbTagData &, const CommMetaData &) const
Receives a movable object trhrough the communicator argument.
Definition: Communicator.cc:1174
Base class for materials.
Definition: Material.h:93
Data about the index, size,,...
Definition: CommMetaData.h:39
Pos3d getCenterOfMassPosition(bool initialGeometry=true) const
Return position of the element centroid.
Definition: ElementBase.h:179
Base class for the finite elements.
Definition: Element.h:112
virtual std::string getClassName(void) const
Returns demangled class name.
Definition: EntityWithOwner.cc:90
TIPOMAT * cast_material(const Material *ptr_mat)
Casts the material pointer to a suitable type.
Definition: ElementBase.h:116
ElementBase & operator=(const ElementBase &)
Assignment operator.
Definition: ElementBase.h:91
ElementBase(int tag, int classTag)
Default constructor.
Definition: ElementBase.h:80
Node pointer container for elements.
Definition: NodePtrsWithIDs.h:46
Posición en tres dimensiones.
Definition: Pos3d.h:44
NodePtrsWithIDs & getNodePtrs(void)
Returns a pointer to the node vector.
Definition: ElementBase.h:111
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
int sendData(Communicator &comm)
Send members through the communicator argument.
Definition: ElementBase.h:145
int getTag(void) const
Returns the tag associated with the object.
Definition: TaggedObject.h:119
Base class for finite element with pointer to nodes container.
Definition: ElementBase.h:47
void set_owner(EntityWithOwner *owr)
Assigns the owner of the object.
Definition: EntityWithOwner.cc:111
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: ElementBase.h:171
static const int numNodes(void)
Returns the element number of nodes.
Definition: ElementBase.h:64
int recvData(const Communicator &comm)
Receives members through the communicator argument.
Definition: ElementBase.h:154