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 #include "utility/utils/misc_utils/colormod.h"
39 
40 namespace XC {
41 class Node;
42 
44 //
47 template <int NNODES>
48 class ElementBase: public Element
49  {
50  protected:
52 
53  template <class TIPOMAT>
54  TIPOMAT *cast_material(const Material *ptr_mat);
55 
56  int sendData(Communicator &comm);
57  int recvData(const Communicator &comm);
58 
59  public:
60  ElementBase(int tag, int classTag);
61  ElementBase(const ElementBase &);
63 
65  static inline const int numNodes(void)
66  { return NNODES; }
67  // public methods to obtain information about dof & connectivity
68  int getNumExternalNodes(void) const;
70  const NodePtrsWithIDs &getNodePtrs(void) const;
71  Pos3d getCenterOfMassPosition(bool initialGeometry= true) const;
72 
73 
76  boost::python::list getConnectedElementsPy(void);
77  boost::python::list getConnectedElementTags(void) const;
78 
81  boost::python::list getConnectedElementsPy(const SetBase *);
82  boost::python::list getConnectedElementTags(const SetBase *) const;
83 
84  boost::python::dict getPyDict(void) const;
85  void setPyDict(const boost::python::dict &);
86  };
87 
88 
89 
91 template <int NNODES>
92 ElementBase<NNODES>::ElementBase(int tag, int classTag)
93  : Element(tag,classTag), theNodes(this,NNODES) {}
94 
96 template <int NNODES>
98  : Element(other), theNodes(other.theNodes)
99  { theNodes.set_owner(this); }
100 
102 template <int NNODES>
104  {
105  Element::operator=(other);
106  theNodes= other.theNodes;
107  theNodes.set_owner(this);
108  return *this;
109  }
110 
112 template <int NNODES>
114  { return theNodes.size(); }
115 
117 template <int NNODES>
119  { return theNodes; }
120 
122 template <int NNODES>
124  { return theNodes; }
125 
127 template <int NNODES> template <class TIPOMAT>
129  {
130  TIPOMAT *retval= nullptr;
131  if(ptr_mat)
132  {
133  const TIPOMAT *tmp = dynamic_cast<const TIPOMAT *>(ptr_mat);
134  if(tmp)
135  retval= tmp->getCopy();
136  else
137  {
138  std::cerr << Color::red << getClassName() << "::" << __FUNCTION__
139  << "; on element: " << getTag()
140  << " the material " << ptr_mat->getTag()
141  << " with name: " << ptr_mat->getName()
142  << " and type: " << ptr_mat->getClassName()
143  << " has not a suitable type."
144  << Color::def << std::endl;
145  abort();
146  }
147  if(!retval)
148  {
149  std::cerr << Color::red << getClassName() << "::" << __FUNCTION__
150  << "; on element: " << getTag()
151  << " can't get a copy of the material with tag: "
152  << ptr_mat->getTag()
153  << Color::def << std::endl;
154  abort();
155  }
156  }
157  else
158  {
159  std::cerr << Color::red << getClassName() << "::" << __FUNCTION__
160  << "; on element: " << getTag()
161  << " pointer to material is null. "
162  << Color::def << std::endl;
163  abort();
164  }
165  return retval;
166  }
167 
169 template <int NNODES>
171  {
172  int res= Element::sendData(comm);
173  res+= comm.sendMovable(theNodes,getDbTagData(),CommMetaData(6));
174  return res;
175  }
176 
178 template <int NNODES>
180  {
181  int res= Element::recvData(comm);
182  res+= comm.receiveMovable(theNodes,getDbTagData(),CommMetaData(6));
183  return res;
184  }
185 
187 template <int NNODES>
188 boost::python::dict ElementBase<NNODES>::getPyDict(void) const
189  {
190  boost::python::dict retval= Element::getPyDict();
191  retval["nodes"]= theNodes.getPyDict();
192  return retval;
193  }
195 template <int NNODES>
196 void ElementBase<NNODES>::setPyDict(const boost::python::dict &d)
197  {
198  Element::setPyDict(d);
199  theNodes.setPyDict(boost::python::extract<boost::python::dict>(d["nodes"]));
200  }
201 
203 template <int NNODES>
205  { return theNodes.getCenterOfMassPosition(initialGeometry); }
206 
208 template <int NNODES>
210  { return theNodes.getConnectedElements(); }
211 
214 template <int NNODES>
216  { return theNodes.getConnectedElements(s); }
217 
219 template <int NNODES>
221  { return theNodes.getConnectedElements(); }
222 
225 template <int NNODES>
227  { return theNodes.getConnectedElements(s); }
228 
231 template <int NNODES>
233  { return theNodes.getConnectedElementsPy(); }
234 
237 template <int NNODES>
239  { return theNodes.getConnectedElementsPy(s); }
240 
241 
244 template <int NNODES>
245 boost::python::list ElementBase<NNODES>::getConnectedElementTags(void) const
246  { return theNodes.getConnectedElementTags(); }
247 
250 template <int NNODES>
251 boost::python::list ElementBase<NNODES>::getConnectedElementTags(const SetBase *s) const
252  { return theNodes.getConnectedElementTags(s); }
253 
254 } //end of XC namespace
255 #endif
int sendMovable(MovableObject &, DbTagData &, const CommMetaData &)
Sends a movable object through the communicator argument.
Definition: Communicator.cc:1163
Node::ElementConstPtrSet ElementConstPtrSet
Container of const element pointers.
Definition: NodePtrs.h:70
boost::python::list getConnectedElementsPy(void)
Return a python list of pointers to the elements that are connected with this node.
Definition: ElementBase.h:232
NodePtrsWithIDs theNodes
pointers to node.
Definition: ElementBase.h:51
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: ElementBase.h:188
ElementBase & operator=(const ElementBase &)
Assignment operator.
Definition: ElementBase.h:103
int getNumExternalNodes(void) const
Return the number of external nodes.
Definition: ElementBase.h:113
Communication parameters between processes.
Definition: Communicator.h:66
std::string getName(void) const
Returns the name of the material.
Definition: Material.cpp:168
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
boost::python::list getConnectedElementTags(void) const
Return a python list containing the tags of the elements that are connected with this node...
Definition: ElementBase.h:245
Pos3d getCenterOfMassPosition(bool initialGeometry=true) const
Return position of the element centroid.
Definition: ElementBase.h:204
Base de las clases Set y SetEstruct.
Definition: SetBase.h:51
Base class for the finite elements.
Definition: Element.h:112
virtual std::string getClassName(void) const
Returns demangled class name.
Definition: EntityWithOwner.cc:90
NodePtrs::ElementConstPtrSet getConnectedElements(void) const
Return a set of pointers to the elements that are connected with this node.
Definition: ElementBase.h:209
TIPOMAT * cast_material(const Material *ptr_mat)
Casts the material pointer to a suitable type.
Definition: ElementBase.h:128
ElementBase(int tag, int classTag)
Default constructor.
Definition: ElementBase.h:92
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:123
Node::ElementPtrSet ElementPtrSet
Container of element pointers.
Definition: NodePtrs.h:69
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:170
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:48
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:196
static const int numNodes(void)
Returns the element number of nodes.
Definition: ElementBase.h:65
int recvData(const Communicator &comm)
Receives members through the communicator argument.
Definition: ElementBase.h:179