XC Open source finite element analysis program
ElemPlano.h
1 //----------------------------------------------------------------------------
2 // XC program; finite element analysis code
3 // for structural analysis and design.
4 //
5 // Copyright (C) Luis Claudio Pérez Tato
6 //
7 // This program derives from OpenSees <http://opensees.berkeley.edu>
8 // developed by the «Pacific earthquake engineering research center».
9 //
10 // Except for the restrictions that may arise from the copyright
11 // of the original program (see copyright_opensees.txt)
12 // XC is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program.
25 // If not, see <http://www.gnu.org/licenses/>.
26 //----------------------------------------------------------------------------
27 //ElemPlano.h
28 
29 #ifndef ElemPlano_h
30 #define ElemPlano_h
31 
32 #include <domain/mesh/element/ElemWithMaterial.h>
33 #include "xc_utils/src/geom/d2/Poligono3d.h"
34 #include "xc_utils/src/geom/d1/Segmento3d.h"
35 #include "xc_utils/src/geom/pos_vec/Pos3d.h"
36 #include "preprocessor/Preprocessor.h"
37 
38 #include "domain/mesh/node/Node.h"
39 
40 namespace XC {
42 //
44 //
47 template <int NNODOS,class PhysProp>
48 class ElemPlano : public ElemWithMaterial<NNODOS, PhysProp>
49  {
50  protected:
51  mutable std::vector<double> areasTributarias;
52  public:
53  ElemPlano(int tag, int classTag,const PhysProp &);
54  void checkElem(void);
55  void setDomain(Domain *theDomain);
56 
57  virtual Poligono3d getPoligono(bool initialGeometry= true) const;
58  virtual Segmento3d getLado(const size_t &i,bool initialGeometry= true) const;
59  Pos3d getPosCdg(bool initialGeometry= true) const;
60  double getPerimetro(bool initialGeometry= true) const;
61  double getArea(bool initialGeometry= true) const;
62  virtual void calculaAreasTributarias(bool initialGeometry= true) const;
63  double getAreaTributaria(const Node *) const;
64 
65  double getDist2(const Pos2d &p,bool initialGeometry= true) const;
66  double getDist(const Pos2d &p,bool initialGeometry= true) const;
67  double getDist2(const Pos3d &p,bool initialGeometry= true) const;
68  double getDist(const Pos3d &p,bool initialGeometry= true) const;
69 
70  size_t getDimension(void) const;
71 
72  };
73 
75 template <int NNODOS,class PhysProp>
76 XC::ElemPlano<NNODOS, PhysProp>::ElemPlano(int tag,int classTag,const PhysProp &physProp)
77  :ElemWithMaterial<NNODOS, PhysProp>(tag,classTag,physProp), areasTributarias(NNODOS,0.0)
78  {}
79 
81 template <int NNODOS,class PhysProp>
83  {
84  if(this->getNodePtrs().hasNull())
85  std::cerr << "the element: " << this->getTag()
86  << " tiene pointers to node, nulos." << std::endl;
87  else
88  {
89  const double area= this->getArea();
90  if(area<1e-3)
91  {
92  std::cerr << "Element: " << this->getTag() << " with nodes: [";
93  const std::vector<int> inodos= this->getNodePtrs().getTags();
94  std::vector<int>::const_iterator i= inodos.begin();
95  std::cerr << *i;
96  i++;
97  for(;i!=inodos.end();i++)
98  std::cerr << "," << *i;
99  std::cerr << "] has a very little area (" << area << ").\n";
100  }
101  }
102  }
103 
105 template <int NNODOS,class PhysProp>
107  {
109  if(theDomain)
110  checkElem();
111  else
112  std::cerr << "ElemPlano::setDomain -- Domain is null\n";
113  }
114 
116 template <int NNODOS,class PhysProp>
117 Pos3d XC::ElemPlano<NNODOS, PhysProp>::getPosCdg(bool initialGeometry) const
118  { return getPoligono(initialGeometry).Cdg(); }
119 
121 template <int NNODOS,class PhysProp>
123  { return 2; }
124 
126 template <int NNODOS,class PhysProp>
127 double XC::ElemPlano<NNODOS, PhysProp>::getPerimetro(bool initialGeometry) const
128  { return getPoligono(initialGeometry).Perimetro(); }
129 
131 template <int NNODOS,class PhysProp>
132 double XC::ElemPlano<NNODOS, PhysProp>::getArea(bool initialGeometry) const
133  { return getPoligono(initialGeometry).Area(); }
134 
136 template <int NNODOS,class PhysProp>
138  {
139  areasTributarias= getPoligono(initialGeometry).getAreasTributarias();
140  this->vuelcaTributarias(areasTributarias);
141  }
142 
144 template <int NNODOS,class PhysProp>
146  {
147  double retval= 0.0;
148  const int i= this->theNodes.find(nod);
149  if(i>=0) //The node belongs to this element.
150  retval= areasTributarias[i];
151  return retval;
152  }
153 
155 template <int NNODOS,class PhysProp>
156 Poligono3d XC::ElemPlano<NNODOS, PhysProp>::getPoligono(bool initialGeometry) const
157  {
158  const std::list<Pos3d> posiciones= this->getPosNodos(initialGeometry);
159  return Poligono3d(posiciones.begin(),posiciones.end());
160  }
161 
163 // Redefine for elements with more than two nodes by face.
164 template <int NNODOS,class PhysProp>
165 Segmento3d XC::ElemPlano<NNODOS, PhysProp>::getLado(const size_t &i,bool initialGeometry) const
166  {
167  Segmento3d retval;
168  const NodePtrsWithIDs &nodos= this->getNodePtrs();
169  const size_t sz= nodos.size();
170  if(i<sz)
171  {
172  const Pos3d p1= nodos.getPosNodo(i,initialGeometry);
173  if(i<(sz-1))
174  retval= Segmento3d(p1,nodos.getPosNodo(i+1,initialGeometry));
175  else
176  retval= Segmento3d(p1,nodos.getPosNodo(0,initialGeometry));
177  }
178  return retval;
179  }
180 
183 template <int NNODOS,class PhysProp>
184 double XC::ElemPlano<NNODOS, PhysProp>::getDist2(const Pos2d &p,bool initialGeometry) const
185  { return getDist2(To3dXY2d(p),initialGeometry); }
186 
189 template <int NNODOS,class PhysProp>
190 double XC::ElemPlano<NNODOS, PhysProp>::getDist(const Pos2d &p,bool initialGeometry) const
191  { return getDist(To3dXY2d(p),initialGeometry); }
192 
195 template <int NNODOS,class PhysProp>
196 double XC::ElemPlano<NNODOS, PhysProp>::getDist2(const Pos3d &p,bool initialGeometry) const
197  { return getPoligono(initialGeometry).dist2(p); }
198 
201 template <int NNODOS,class PhysProp>
202 double XC::ElemPlano<NNODOS, PhysProp>::getDist(const Pos3d &p,bool initialGeometry) const
203  { return getPoligono(initialGeometry).dist(p); }
204 
205 } // end of XC namespace
206 #endif
void checkElem(void)
Sets nodes and checks the element.
Definition: ElemPlano.h:82
double getArea(bool initialGeometry=true) const
Returns element area.
Definition: ElemPlano.h:132
Element with material.
Definition: ElemWithMaterial.h:40
Domain (mesh and boundary conditions) of the finite element model.
Definition: Domain.h:98
NodePtrsWithIDs theNodes
pointers to node.
Definition: ElementBase.h:49
void setDomain(Domain *theDomain)
Sets the element domain.
Definition: ElemPlano.h:106
Mesh node.
Definition: Node.h:99
const std::vector< int > & getTags(void) const
Returns a vector con los tags of the nodes.
Definition: NodePtrs.cc:261
virtual Segmento3d getLado(const size_t &i, bool initialGeometry=true) const
Returns a lado of the element.
Definition: ElemPlano.h:165
std::list< Pos3d > getPosNodos(bool initialGeometry=true) const
Returns the coordinates of the nodes.
Definition: Element.cpp:765
size_t getDimension(void) const
Return the element dimension (0, 1, 2 o3 3).
Definition: ElemPlano.h:122
Base class for plane elements.
Definition: ElemPlano.h:48
virtual void calculaAreasTributarias(bool initialGeometry=true) const
Computes tributary areas that correspond to each node.
Definition: ElemPlano.h:137
Node pointer container for elements.
Definition: NodePtrsWithIDs.h:45
Pos3d getPosCdg(bool initialGeometry=true) const
Return the position of the element centroid.
Definition: ElemPlano.h:117
double getPerimetro(bool initialGeometry=true) const
Returns the perimeter of the element.
Definition: ElemPlano.h:127
iterator find(const int &)
Returns an iterator to the node identified by the tag being passed as parameter.
Definition: NodePtrs.cc:146
double getAreaTributaria(const Node *) const
Returns tributary area for the node being passed as parameter.
Definition: ElemPlano.h:145
double getDist2(const Pos2d &p, bool initialGeometry=true) const
Returns the squared distance from the element to the point being passed as parameter.
Definition: ElemPlano.h:184
void vuelcaTributarias(const std::vector< double > &) const
Adds to the tributary magnitude of each node the vector being passed as parameter.
Definition: Element.cpp:800
double getDist(const Pos2d &p, bool initialGeometry=true) const
Return the distance from the element to the point being passed as parameter.
Definition: ElemPlano.h:190
NodePtrsWithIDs & getNodePtrs(void)
Returns a pointer to the vector de nodos.
Definition: ElementBase.h:107
virtual Poligono3d getPoligono(bool initialGeometry=true) const
Returns the element contour as a polygon.
Definition: ElemPlano.h:156
================================================================================
Definition: ContinuaReprComponent.h:34
void setDomain(Domain *theDomain)
Sets the domain for the element.
Definition: Element.cpp:170
ElemPlano(int tag, int classTag, const PhysProp &)
Constructor.
Definition: ElemPlano.h:76
Pos3d getPosNodo(const size_t &i, bool initialGeometry=true) const
Return the position of the i-th node.
Definition: NodePtrs.cc:352