xc
SurfaceMap.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 //SurfaceMap.h
29 
30 #ifndef MAPSurfaces_H
31 #define MAPSurfaces_H
32 
33 #include "EntityMap.h"
34 #include "preprocessor/multi_block_topology/entities/2d/Face.h"
35 
36 namespace XC {
37 class QuadSurface;
38 class PolygonalFace;
39 
41 //
43 class SurfaceMap: public EntityMap<Face>
44  {
45  protected:
46  class Graph
47  {
48  public:
49  typedef const Edge *vertex_type;
50  typedef std::list<vertex_type> vertex_list;
51  typedef std::map<vertex_type, vertex_list > graph_container;
52  typedef std::pair<vertex_type, vertex_list> map_pair;
53  protected:
54  graph_container edges;
55  public:
56  typedef graph_container::iterator iterator;
57  typedef graph_container::const_iterator const_iterator;
58 
59  const_iterator find(const vertex_type &v) const
60  { return edges.find(v); }
61  const_iterator begin(void) const
62  { return edges.begin(); }
63  const_iterator end(void) const
64  { return edges.end(); }
65  void add_vertex(const Edge *);
66  void add_edge(vertex_type v,vertex_type w)
67  {
68  edges[v].push_back(w);
69  edges[w].push_back(v);
70  }
71 
72  std::set<const Edge *> breadth_first_search(vertex_type s) const
73  {
74  std::set<const Edge *> retval;
75  std::map<vertex_type,bool> visited;
76  std::list<vertex_type> q;
77  visited[s]= true;
78  q.push_back(s);
79  while(!q.empty())
80  {
81  s = q.front();
82  retval.insert(s);
83  q.pop_front();
84  const_iterator i_edges= find(s);
85  for(auto i : i_edges->second)
86  {
87  if(!visited[i])
88  {
89  visited[i] = true;
90  q.push_back(i);
91  }
92  }
93  }
94  return retval;
95  }
96 
97  };
98  private:
99  Graph edgeGraph;
100  void add_graph_vertex(const Edge *e);
101  void updateGraph(const Face &);
102  void updateSets(Face *) const;
103  public:
104  SurfaceMap(MultiBlockTopology *mbt= nullptr);
105 
106  bool conciliaNDivs(void);
107  std::deque<const Edge *> getNDivErrors(void) const;
108  std::deque<int> getNDivErrorTags(void) const;
109  boost::python::list getNDivErrorTagsPy(void) const;
110  bool checkNDivs(void) const;
111  std::set<const XC::Edge *> getHomologousSides(const Edge *) const;
112 
113  template <class F>
114  Face *New(void);
115  template <class F>
116  Face *New(const size_t &);
117  Face *New(const size_t &, const std::string &);
118  Face *findOrCreateFace(Pnt *,Pnt *,Pnt *,Pnt *);
119 
120  QuadSurface *newQuadSurfacePts(const size_t &, const size_t &,const size_t &,const size_t &);
121  QuadSurface *newQuadSurfaceLines(const size_t &, const size_t &,const size_t &,const size_t &);
122  QuadSurface *newQuadSurfaceGridPoints(const boost::python::list &);
124  PolygonalFace *newPolygonalFacePointsPy(const boost::python::list &);
125  double getAverageArea(void) const;
126 
127  // Surface orientation.
128  void reverse(void);
129 
130  boost::python::dict getPyDict(void) const;
131  void setPyDict(const boost::python::dict &);
132  };
133 
134 
136 template <class F>
138  {
139  Face *retval= busca(getTag());
140  if(!retval) //Surface is new.
141  {
142  Preprocessor *preprocessor= getPreprocessor();
143  retval= new F(preprocessor);
144  if(retval)
145  {
146  retval->Name()= "f"+boost::lexical_cast<std::string>(getTag());
147  (*this)[getTag()]= retval;
148  updateSets(retval);
149  tag++;
150  }
151  }
152  return retval;
153  }
154 
156 template <class F>
157 XC::Face *SurfaceMap::New(const size_t &tag)
158  {
159  size_t old_tag= getTag();
160  Face *retval= nullptr;
161  setTag(tag); // Edge identifier.
162  retval= busca(getTag());
163  if(retval)
164  {
165  std::cerr << getClassName() << "::" << __FUNCTION__
166  << "; surface with identifier: " << tag
167  << " already exists. Command ignored." << std::endl;
168  }
169  else
170  { retval= New<F>(); }
171  setTag(old_tag);
172  return retval;
173  }
174 
175 } //end of XC namespace
176 #endif
Definition: SurfaceMap.h:46
QuadSurface * newQuadSurfaceLines(const size_t &, const size_t &, const size_t &, const size_t &)
New quadrilateral surface.
Definition: SurfaceMap.cc:214
Base class for one-dimensional geometry objects.
Definition: Edge.h:48
Geometric entities container (points, lines, surfaces,...).
Definition: EntityMap.h:43
Polygonal face defined by an arbitrary number of vertices.
Definition: PolygonalFace.h:45
std::set< const XC::Edge * > getHomologousSides(const Edge *) const
Return the homologous sides to that passed as a parameter.
Definition: SurfaceMap.cc:151
Finite element model generation tools.
Definition: Preprocessor.h:59
std::deque< const Edge * > getNDivErrors(void) const
Returns a list with the edges that have an incompatible number of divisions.
Definition: SurfaceMap.cc:99
bool checkNDivs(void) const
Verifies that number of divisions of the edges are compatible.
Definition: SurfaceMap.cc:141
Model geometry manager.
Definition: MultiBlockTopology.h:68
PolygonalFace * newPolygonalFacePointsPy(const boost::python::list &)
New polygonalr face.
Definition: SurfaceMap.cc:245
boost::python::list getNDivErrorTagsPy(void) const
Returns the indentifiers of the edges that have an incompatible number of divisions.
Definition: SurfaceMap.cc:127
Model points container.
Definition: SurfaceMap.h:43
Vector of integers.
Definition: ID.h:95
void reverse(void)
Reverse the orientation of the surfaces.
Definition: SurfaceMap.cc:265
std::string & Name(void)
Return a reference to the object name.
Definition: NamedEntity.h:52
bool conciliaNDivs(void)
Conciliate the number of divisions of the lines.
Definition: SurfaceMap.cc:92
virtual std::string getClassName(void) const
Returns demangled class name.
Definition: EntityWithOwner.cc:90
Quadrangle defined by its four vertices.
Definition: QuadSurface.h:41
Point (KPoint).
Definition: Pnt.h:50
Face * findOrCreateFace(Pnt *, Pnt *, Pnt *, Pnt *)
Find a face between the points or creates a new one.
Definition: SurfaceMap.cc:166
const Preprocessor * getPreprocessor(void) const
Return a pointer to preprocessor.
Definition: ModelComponentContainerBase.cc:54
Face * New(void)
Creates a new surface.
Definition: SurfaceMap.h:137
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: SurfaceMap.cc:272
PolygonalFace * newPolygonalFacePoints(const ID &)
New polygonalr face.
Definition: SurfaceMap.cc:236
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
SurfaceMap(MultiBlockTopology *mbt=nullptr)
Constructor.
Definition: SurfaceMap.cc:42
QuadSurface * newQuadSurfaceGridPoints(const boost::python::list &)
New quadrilateral surface.
Definition: SurfaceMap.cc:226
QuadSurface * newQuadSurfacePts(const size_t &, const size_t &, const size_t &, const size_t &)
New quadrilateral surface.
Definition: SurfaceMap.cc:202
std::deque< int > getNDivErrorTags(void) const
Returns the indentifiers of the edges that have an incompatible number of divisions.
Definition: SurfaceMap.cc:114
Surface.
Definition: Face.h:45
double getAverageArea(void) const
Return the average area of the surfaces.
Definition: SurfaceMap.cc:255
Face * busca(const Indice &)
Return a pointer to the geometry entity whose identifier is passed as parameter.
Definition: ModelComponentContainer.h:78
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: SurfaceMap.cc:288