Salome HOME
a8cb82d2de9427bc3cbb0e5dfe6ba895e2479429
[modules/med.git] / src / MEDMEM / MEDMEM_MeshFuse.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : MEDMEM_MeshFuse.hxx
20 // Created   : Tue Jul  7 17:04:38 2009
21 // Author    : Edward AGAPOV (eap)
22
23 #ifndef __MEDMEM_MeshFuse_HXX__
24 #define __MEDMEM_MeshFuse_HXX__
25
26 #include "MEDMEM_Meshing.hxx"
27
28 #include <vector>
29 #include <map>
30 #include <set>
31
32 namespace MEDMEM
33 {
34   /*!
35    * \brief Mesh able to concatenate other meshes
36    */
37   class MEDMEM_EXPORT MeshFuse : public MESHING
38   {
39   public:
40     MeshFuse();
41     virtual ~MeshFuse();
42
43     void concatenate( const MESH* mesh, const std::vector<int>& node_glob_numbers );
44
45     // unite glob_numbers and add_glob_numbers 
46     void append( MED_EN::medEntityMesh   entity,
47                  std::vector<int>&       glob_numbers,
48                  const std::vector<int>& add_glob_numbers );
49
50     // if MeshFuse is filled via MESHING
51     void setNodeNumbers( const std::vector<int>& node_glob_numbers );
52
53     // return number collected during all concatenate()s
54     const std::vector<int> & getNodeNumbers() const { return _node_glob_numbers; }
55
56   private:
57
58     int makeNewNodeIds(const std::vector<int>& node_glob_numbers);
59
60     void expandCoordinates(int final_nb_nodes);
61
62     void expandConnectivity(int final_nb_nodes);
63
64     void updateNodeIds( CONNECTIVITY* connectivity );
65
66     struct TConnData
67     {
68       int _nb_elems;
69       std::vector< int > _connectivity, _index;
70
71       TConnData(): _nb_elems(0) {}
72     };
73
74     int appendConnectivity( TConnData&                 data,
75                             const MESH*                mesh,
76                             MED_EN::medEntityMesh      entity,
77                             MED_EN::medGeometryElement type);
78
79     template< class TSUPPORT >
80     TSUPPORT* updateOldSupport(TSUPPORT* support) const;
81
82     template< class TSUPPORT >
83     TSUPPORT* makeSupport(const TSUPPORT* add_support, TSUPPORT* same_name_support);
84
85     void expandSupports();
86
87     int getElemNbShift( const MED_EN::medEntityMesh& entity,
88                         MED_EN::medGeometryElement   type,
89                         int which, bool prev ) const;
90
91     void uniteSupportElements(const SUPPORT*             add_support,
92                               SUPPORT*                   old_support,
93                               MED_EN::medGeometryElement type,
94                               std::vector<int> &         elements);
95
96     void makeNewElemIds(MED_EN::medEntityMesh      entity,
97                         MED_EN::medGeometryElement type,
98                         std::vector< int > &       new_ids);
99
100     void findEqualOldElements(MED_EN::medEntityMesh      entity,
101                               MED_EN::medGeometryElement type,
102                               std::vector< int > &       old_ids);
103
104   private:
105
106     const MESH* _mesh; // mesh to add
107
108     std::vector<int> _node_glob_numbers; // global numbers of nodes
109
110     // local ids of merged entities (whose all nodes are merged) of the added mesh
111     std::map< MED_EN::medGeometryElement, std::vector<int> > _merged_of_type;
112     // and corresponding ids of EQUAL elements (if any) of OLD mesh
113     std::map< MED_EN::medGeometryElement, std::vector<int> > _equalo_of_type;
114
115     // ids in final mesh of added elements of a geom type filled in case of double elements
116     std::map< MED_EN::medGeometryElement, std::vector<int> > _new_elem_ids_of_type;
117
118     // global numbering index by type:
119     // - of old mesh before addition
120     // - of added mesh before addition
121     // - of mesh added (taking merging into account)
122     enum { INIT_OLD=0, INIT_ADD, RSLT_ADD, NB_INDICES };
123     typedef std::map< MED_EN::medGeometryElement, int > TNbOfGeom;
124     vector< TNbOfGeom > _nb_index[NB_INDICES]; // for each entity
125
126   };
127 }
128
129 #endif