XC Open source finite element analysis program
MapEnt.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 //MapEnt.h
28 
29 #ifndef MAPENT_H
30 #define MAPENT_H
31 
32 #include "preprocessor/cad/MapCadMember.h"
33 #include "EntMdlr.h"
34 #include <map>
35 
36 namespace XC {
37 
39 //
41 template <class T>
42 class MapEnt: public MapCadMember<T>
43  {
44  protected:
45 
46  public:
47  typedef typename MapCadMember<T>::iterator iterator;
48  typedef typename MapCadMember<T>::const_iterator const_iterator;
49 
50  MapEnt(Cad *cad= nullptr);
51 
52  T *getNearest(const Pos3d &p);
53  const T *getNearest(const Pos3d &p) const;
54  void numera(void);
55  };
56 
58 template <class T>
60  : MapCadMember<T>(cad) {}
61 
63 template <class T>
64 T *MapEnt<T>::getNearest(const Pos3d &p)
65  {
66  //Commented code is buggy (inifinite recursion) if
67  //the function is called from Python
68  /* MapEnt<T> *this_no_const= const_cast<MapEnt<T> *>(this); */
69  /* return const_cast<T *>(this_no_const->getNearest(p)); */
70  T *retval= nullptr;
71  if(!this->empty())
72  {
73  iterator i= this->begin();
74  double d2= (*i).second->DistanciaA2(p);
75  retval= (*i).second; i++;
76  double tmp;
77  for(;i!=this->end();i++)
78  {
79  tmp= (*i).second->DistanciaA2(p);
80  if(tmp<d2)
81  {
82  d2= tmp;
83  retval= (*i).second;
84  }
85  }
86  }
87  return retval;
88  }
89 
91 template <class T>
92 const T *MapEnt<T>::getNearest(const Pos3d &p) const
93  {
94  const T *retval= nullptr;
95  if(!this->empty())
96  {
97  const_iterator i= this->begin();
98  double d2= (*i).second->DistanciaA2(p);
99  retval= (*i).second; i++;
100  double tmp;
101  for(;i!=this->end();i++)
102  {
103  tmp= (*i).second->DistanciaA2(p);
104  if(tmp<d2)
105  {
106  d2= tmp;
107  retval= (*i).second;
108  }
109  }
110  }
111  return retval;
112  }
113 
115 template <class T>
117  {
118  size_t idx= 0;
119  for(iterator i= this->begin();i!=this->end();i++,idx++)
120  {
121  EntMdlr *ptr= (*i).second;
122  ptr->set_indice(idx);
123  }
124  }
125 
126 } //end of XC namespace
127 #endif
Multiblock topology object (point, line, face, block,...).
Definition: EntMdlr.h:53
MapEnt(Cad *cad=nullptr)
Constructor.
Definition: MapEnt.h:59
Container for model entities.
Definition: MapCadMember.h:42
Model geometry manager. Management of geometry entities: points, lines, surfaces, bodies...
Definition: Cad.h:69
void numera(void)
Set indices to the objects to allow its use in VTK.
Definition: MapEnt.h:116
virtual void set_indice(const size_t &i)
Assigns the objects index for its use in VTK arrays(see numera in Set).
Definition: EntMdlr.cc:76
T * getNearest(const Pos3d &p)
Returns the object closest to the position being passed as parameter.
Definition: MapEnt.h:64
================================================================================
Definition: ContinuaReprComponent.h:34
Geometric entities container (points, lines, surfaces,...).
Definition: MapEnt.h:42