xc
EntityMap.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 //EntityMap.h
29 
30 #ifndef MAPENT_H
31 #define MAPENT_H
32 
33 #include "preprocessor/multi_block_topology/ModelComponentContainer.h"
34 #include "preprocessor/multi_block_topology/entities/EntMdlr.h"
35 #include <map>
36 
37 namespace XC {
38 
40 //
42 template <class Entity>
43 class EntityMap: public ModelComponentContainer<Entity>
44  {
45  public:
46  typedef typename ModelComponentContainer<Entity>::iterator iterator;
47  typedef typename ModelComponentContainer<Entity>::const_iterator const_iterator;
48 
49  EntityMap(MultiBlockTopology *mbt= nullptr);
50 
51  Entity *getNearest(const Pos3d &p);
52  const Entity *getNearest(const Pos3d &p) const;
53  void numerate(void);
54  void genMesh(meshing_dir dm);
55  };
56 
58 template <class Entity>
60  : ModelComponentContainer<Entity>(mbt) {}
61 
63 template <class Entity>
65  {
66  //Commented code is buggy (infinite recursion) if
67  //the function is called from Python
68  /* EntityMap<Entity> *this_no_const= const_cast<EntityMap<Entity> *>(this); */
69  /* return const_cast<Entity *>(this_no_const->getNearest(p)); */
70  Entity *retval= nullptr;
71  if(!this->empty())
72  {
73  iterator i= this->begin();
74  double d2= (*i).second->getSquaredDistanceTo(p);
75  retval= (*i).second; i++;
76  double tmp;
77  for(;i!=this->end();i++)
78  {
79  tmp= (*i).second->getSquaredDistanceTo(p);
80  if(tmp<d2)
81  {
82  d2= tmp;
83  retval= (*i).second;
84  }
85  }
86  }
87  return retval;
88  }
89 
91 template <class Entity>
92 const Entity *EntityMap<Entity>::getNearest(const Pos3d &p) const
93  {
94  EntityMap<Entity> *this_no_const= const_cast<EntityMap<Entity> *>(this);
95  return this_no_const->getNearest(p);
96  }
97 
99 template <class Entity>
101  {
102  size_t idx= 0;
103  for(iterator i= this->begin();i!=this->end();i++,idx++)
104  {
105  EntMdlr *ptr= (*i).second;
106  ptr->set_index(idx);
107  }
108  }
109 
111 template <class Entity>
112 void EntityMap<Entity>::genMesh(meshing_dir dm)
113  {
114  for(iterator i= this->begin();i!=this->end();i++)
115  {
116  EntMdlr *ptr= (*i).second;
117  ptr->genMesh(dm);
118  }
119  }
120 } //end of XC namespace
121 #endif
Geometric entities container (points, lines, surfaces,...).
Definition: EntityMap.h:43
Model geometry manager.
Definition: MultiBlockTopology.h:68
void genMesh(meshing_dir dm)
Generate mesh.
Definition: EntityMap.h:112
Multiblock topology object (point, line, face, block,...).
Definition: EntMdlr.h:55
void numerate(void)
Set indices to the objects to allow its use in VTK.
Definition: EntityMap.h:100
Posición en tres dimensiones.
Definition: Pos3d.h:44
EntityMap(MultiBlockTopology *mbt=nullptr)
Constructor.
Definition: EntityMap.h:59
virtual void set_index(const size_t &i)
Assigns the objects index for its use in VTK arrays (see numerate in Set).
Definition: EntMdlr.cc:96
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
virtual void genMesh(meshing_dir dm)
Generates a finite element mesh from the set components.
Definition: SetBase.cc:86
Container for model entities.
Definition: ModelComponentContainer.h:43
Entity * getNearest(const Pos3d &p)
Returns the object closest to the position being passed as parameter.
Definition: EntityMap.h:64