xc
PlaneElement.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 //PlaneElement.h
28 
29 #ifndef PlaneElement_h
30 #define PlaneElement_h
31 
32 #include <domain/mesh/element/ElemWithMaterial.h>
33 #include "xc_utils/src/geom/d2/Polygon3d.h"
34 #include "xc_utils/src/geom/d1/Segment3d.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 {
44 //
47 template <int NNODES,class PhysProp>
48 class PlaneElement : public ElemWithMaterial<NNODES, PhysProp>
49  {
50  protected:
51  mutable std::vector<double> tributaryAreas;
52  public:
53  PlaneElement(int tag, int classTag,const PhysProp &);
54  void checkElem(void);
55  void setDomain(Domain *theDomain);
56 
57  virtual Polygon3d getPolygon(bool initialGeometry= true) const;
58  virtual Segment3d getSide(const size_t &i,bool initialGeometry= true) const;
59  Pos3d getCenterOfMassPosition(bool initialGeometry= true) const;
60  double getPerimeter(bool initialGeometry= true) const;
61  double getArea(bool initialGeometry= true) const;
62  virtual void computeTributaryAreas(bool initialGeometry= true) const;
63  double getTributaryArea(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 NNODES,class PhysProp>
76 XC::PlaneElement<NNODES, PhysProp>::PlaneElement(int tag,int classTag,const PhysProp &physProp)
77  :ElemWithMaterial<NNODES, PhysProp>(tag,classTag,physProp), tributaryAreas(NNODES,0.0)
78  {}
79 
81 template <int NNODES,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> inodes= this->getNodePtrs().getTags();
94  std::vector<int>::const_iterator i= inodes.begin();
95  std::cerr << *i;
96  i++;
97  for(;i!=inodes.end();i++)
98  std::cerr << "," << *i;
99  std::cerr << "] has a very little area (" << area << ").\n";
100  }
101  }
102  }
103 
105 template <int NNODES,class PhysProp>
107  {
109  if(theDomain)
110  checkElem();
111  else
112  std::cerr << "PlaneElement::setDomain -- Domain is null\n";
113  }
114 
116 template <int NNODES,class PhysProp>
118  { return getPolygon(initialGeometry).getCenterOfMass(); }
119 
121 template <int NNODES,class PhysProp>
123  { return 2; }
124 
126 template <int NNODES,class PhysProp>
127 double XC::PlaneElement<NNODES, PhysProp>::getPerimeter(bool initialGeometry) const
128  { return getPolygon(initialGeometry).getPerimeter(); }
129 
133 template <int NNODES,class PhysProp>
134 double XC::PlaneElement<NNODES, PhysProp>::getArea(bool initialGeometry) const
135  { return getPolygon(initialGeometry).getArea(); }
136 
138 template <int NNODES,class PhysProp>
140  {
141  tributaryAreas= getPolygon(initialGeometry).getTributaryAreas();
142  this->dumpTributaries(tributaryAreas);
143  }
144 
146 template <int NNODES,class PhysProp>
148  {
149  double retval= 0.0;
150  const int i= this->theNodes.find(nod);
151  if(i>=0) //The node belongs to this element.
152  retval= tributaryAreas[i];
153  return retval;
154  }
155 
157 template <int NNODES,class PhysProp>
158 Polygon3d XC::PlaneElement<NNODES, PhysProp>::getPolygon(bool initialGeometry) const
159  {
160  const std::list<Pos3d> positions= this->getPosNodes(initialGeometry);
161  return Polygon3d(positions.begin(),positions.end());
162  }
163 
165 // Redefine for elements with more than two nodes by face.
166 template <int NNODES,class PhysProp>
167 Segment3d XC::PlaneElement<NNODES, PhysProp>::getSide(const size_t &i,bool initialGeometry) const
168  {
169  Segment3d retval;
170  const NodePtrsWithIDs &nodes= this->getNodePtrs();
171  const size_t sz= nodes.size();
172  if(i<sz)
173  {
174  const Pos3d p1= nodes.getPosNode(i,initialGeometry);
175  if(i<(sz-1))
176  retval= Segment3d(p1,nodes.getPosNode(i+1,initialGeometry));
177  else
178  retval= Segment3d(p1,nodes.getPosNode(0,initialGeometry));
179  }
180  return retval;
181  }
182 
185 template <int NNODES,class PhysProp>
186 double XC::PlaneElement<NNODES, PhysProp>::getDist2(const Pos2d &p,bool initialGeometry) const
187  { return getDist2(To3dXY2d(p),initialGeometry); }
188 
191 template <int NNODES,class PhysProp>
192 double XC::PlaneElement<NNODES, PhysProp>::getDist(const Pos2d &p,bool initialGeometry) const
193  { return getDist(To3dXY2d(p),initialGeometry); }
194 
197 template <int NNODES,class PhysProp>
198 double XC::PlaneElement<NNODES, PhysProp>::getDist2(const Pos3d &p,bool initialGeometry) const
199  { return getPolygon(initialGeometry).dist2(p); }
200 
203 template <int NNODES,class PhysProp>
204 double XC::PlaneElement<NNODES, PhysProp>::getDist(const Pos3d &p,bool initialGeometry) const
205  { return getPolygon(initialGeometry).dist(p); }
206 
207 } // end of XC namespace
208 #endif
double getDist2(const Pos2d &p, bool initialGeometry=true) const
Returns the squared distance from the element to the point being passed as parameter.
Definition: PlaneElement.h:186
Pos3d getPosNode(const size_t &i, bool initialGeometry=true) const
Return the position of the i-th node.
Definition: NodePtrs.cc:349
double getArea(bool initialGeometry=true) const
Returns element area.
Definition: PlaneElement.h:134
double getTributaryArea(const Node *) const
Returns tributary area for the node being passed as parameter.
Definition: PlaneElement.h:147
void checkElem(void)
Sets nodes and checks the element.
Definition: PlaneElement.h:82
PlaneElement(int tag, int classTag, const PhysProp &)
Constructor.
Definition: PlaneElement.h:76
virtual void computeTributaryAreas(bool initialGeometry=true) const
Computes tributary areas that correspond to each node.
Definition: PlaneElement.h:139
virtual Segment3d getSide(const size_t &i, bool initialGeometry=true) const
Returns a lado of the element.
Definition: PlaneElement.h:167
void setDomain(Domain *theDomain)
Sets the element domain.
Definition: PlaneElement.h:106
double getDist(const Pos2d &p, bool initialGeometry=true) const
Return the distance from the element to the point being passed as parameter.
Definition: PlaneElement.h:192
Pos3d getCenterOfMassPosition(bool initialGeometry=true) const
Return the position of the element centroid.
Definition: PlaneElement.h:117
Node pointer container for elements.
Definition: NodePtrsWithIDs.h:45
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:34
double getPerimeter(bool initialGeometry=true) const
Returns the perimeter of the element.
Definition: PlaneElement.h:127
Element with material.
Definition: ElemWithMaterial.h:40
size_t getDimension(void) const
Return the element dimension (0, 1, 2 o3 3).
Definition: PlaneElement.h:122
virtual Polygon3d getPolygon(bool initialGeometry=true) const
Returns the element contour as a polygon.
Definition: PlaneElement.h:158
Domain (mesh and boundary conditions) of the finite element model.
Definition: Domain.h:116
Mesh node.
Definition: Node.h:110
Base class for plane elements.
Definition: PlaneElement.h:48