Salome HOME
Merge from V6_main 11/02/2013
[modules/med.git] / src / MEDPartitioner / MEDPARTITIONER_MeshCollection.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
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
20 #ifndef __MEDPARTITIONER_MESHCOLLECTION_HXX__
21 #define __MEDPARTITIONER_MESHCOLLECTION_HXX__
22
23 #include "MEDPARTITIONER.hxx"
24 #include "MEDPARTITIONER_Graph.hxx"
25 #include "MEDPARTITIONER_Utils.hxx"
26
27 #include "MEDCouplingUMesh.hxx"
28
29 #include <map>
30 #include <vector>
31 #include <string>
32
33 #include "BBTree.txx"
34
35 namespace ParaMEDMEM
36 {
37   class MEDCouplingUMesh;
38   class DataArrayInt;
39 }
40
41 namespace MEDPARTITIONER
42 {
43   class Topology;
44   class MeshCollectionDriver;
45   class ParaDomainSelector;
46   class SkyLineArray;
47   class ConnectZone;
48   class JointFinder;
49   
50   typedef enum{MedAscii, MedXml, Undefined} DriverType;
51   typedef std::multimap<std::pair<int,int>, std::pair<int,int> > NodeMapping ;
52   typedef std::vector<std::pair<int,int> >  NodeList;
53   
54   class MEDPARTITIONER_EXPORT MeshCollection
55   {
56   public:
57     MeshCollection();
58     //Constructing from an existing mesh and a new topology
59     MeshCollection(MeshCollection&, Topology*, bool family_splitting=false, bool create_empty_groups=false);
60     //Constructing the mesh collection from a file
61     MeshCollection(const std::string& filename);
62     //Constructing the mesh collection from a file
63     MeshCollection(const std::string& filename, ParaDomainSelector& domainSelector);
64     //Constructing the mesh collection from a file
65     MeshCollection(const std::string& filename, const std::string& meshname);
66     ~MeshCollection();
67     bool isParallelMode() const { return _domain_selector; }
68     
69     //writing to a distributed file
70     void write(const std::string& filename);
71     
72     //getting the driver
73     MeshCollectionDriver *retrieveDriver();
74     MeshCollectionDriver *getDriver() const;
75     void setDriverType(MEDPARTITIONER::DriverType type) { _driver_type=type; }
76
77     //creation of the cell graph
78     void buildCellGraph(MEDPARTITIONER::SkyLineArray* & array,int *& edgeweights );
79     //creation and partition of the associated graph
80     Topology* createPartition(int nbdomain, Graph::splitter_type type = Graph::METIS,
81                               const std::string& ="", int* edgeweights=0, int* verticesweights=0);
82
83     //creation of a user specified partition
84     Topology* createPartition(const int* partition);
85
86     //getting mesh dimension
87     int getMeshDimension() const;
88     int getNbOfLocalMeshes() const;
89     int getNbOfGlobalMeshes() const { return _mesh.size(); }
90     int getNbOfLocalCells() const;
91     int getNbOfLocalFaces() const;
92     
93     //getting a reference to mesh vector
94     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getMesh();
95     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getFaceMesh();
96     std::vector<std::vector<ParaMEDMEM::MEDCouplingUMesh*> >& getGroupMeshes();
97
98     ParaMEDMEM::MEDCouplingUMesh* getMesh(int idomain) const;
99     ParaMEDMEM::MEDCouplingUMesh* getFaceMesh(int idomain);
100     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getGroupMeshes(int idomain);
101
102     std::vector<ParaMEDMEM::DataArrayInt*>& getCellFamilyIds() { return _cell_family_ids; }
103     std::vector<ParaMEDMEM::DataArrayInt*>& getFaceFamilyIds() { return _face_family_ids; }
104     
105     std::map<std::string, ParaMEDMEM::DataArrayInt*>& getMapDataArrayInt() { return _map_dataarray_int; }
106     std::map<std::string, ParaMEDMEM::DataArrayDouble*>& getMapDataArrayDouble() { return _map_dataarray_double; }
107
108     std::map<std::string,int>& getFamilyInfo() { return _family_info; }
109     std::map<std::string, std::vector<std::string> >& getGroupInfo() { return _group_info; }
110
111     ParaMEDMEM::DataArrayDouble* getField(std::string descriptionField, int iold);
112     std::vector<std::string>&  getFieldDescriptions() { return _field_descriptions; }
113     void prepareFieldDescriptions();
114     void filterFaceOnCell();
115      
116     //getting a reference to connect zones vector
117     std::vector<MEDPARTITIONER::ConnectZone*>& getCZ();
118
119     //getting a pointer to topology
120     Topology* getTopology() const ;
121     ParaDomainSelector* getParaDomainSelector() const { return _domain_selector; }
122     //setting a new topology
123     void setTopology(Topology* topology);
124
125     //getting/setting the name of the global mesh (as opposed 
126     //to the name of a subdomain \a nn, which is name_nn) 
127     std::string getName() const { return _name; }
128     void setName(const std::string& name) { _name=name; }
129     void setDomainNames(const std::string& name);
130
131     //getting/setting the description of the global mesh
132     std::string getDescription() const { return _description; }
133     void setDescription(const std::string& name) { _description=name; }
134
135     //creates the node mapping between an old collection and the present one
136     void createNodeMapping(MeshCollection& initialCollection, 
137                            std::multimap<std::pair<int,int>,std::pair<int,int> >& nodeMapping);
138     
139     void castCellMeshes(MeshCollection& initialCollection, 
140                         std::vector<std::vector<std::vector<int> > >& new2oldIds);
141     
142     //creates faces on the new collection
143     void castFaceMeshes(MeshCollection& initialCollection,
144                         const std::multimap<std::pair<int,int>, std::pair<int,int> >& nodeMapping,
145                         std::vector<std::vector<std::vector<int> > >& new2oldIds);
146
147     //constructing connect zones
148     void buildConnectZones();
149
150   private:
151     void castIntField(std::vector<ParaMEDMEM::MEDCouplingUMesh*>& meshesCastFrom,
152                        std::vector<ParaMEDMEM::MEDCouplingUMesh*>& meshesCastTo,
153                        std::vector<ParaMEDMEM::DataArrayInt*>& arrayFrom,
154                        std::string nameArrayTo);
155
156     void castAllFields(MeshCollection& initialCollection,
157                        std::string nameArrayTo);
158
159     void findCommonDistantNodes(std::vector<std::vector<std::multimap<int,int> > >& commonDistantNodes);
160
161     
162     void remapIntField(int inew, int iold, 
163                        const ParaMEDMEM::MEDCouplingUMesh& sourceMesh,
164                        const ParaMEDMEM::MEDCouplingUMesh& targetMesh,
165                        const int* fromArray,
166                        std::string nameArrayTo,
167                        const BBTreeOfDim* tree);
168
169     void remapDoubleField(int inew, int iold,
170                            ParaMEDMEM::DataArrayDouble* fromArray,
171                            std::string nameArrayTo,
172                            std::string descriptionField);
173
174     void createJointGroup( const std::vector< int >& faces,
175                            const int                 inew1,
176                            const int                 inew2,
177                            const bool                is2nd );
178   private:
179
180     //link to mesh_collection topology
181     Topology* _topology;
182     
183     //control over topology
184     bool _owns_topology;
185     
186     //Driver for read/write operations
187     MeshCollectionDriver* _driver;
188     
189     //Parallelizer - mark of parallel execution mode
190     ParaDomainSelector* _domain_selector;
191     
192     //links to meshes
193     std::vector<ParaMEDMEM::MEDCouplingUMesh*> _mesh;
194     std::vector<ParaMEDMEM::MEDCouplingUMesh*> _face_mesh;
195     
196     //index of a non empty mesh within _mesh (in parallel mode all of meshes can be empty)
197     int _i_non_empty_mesh;
198     
199     //links to connectzones
200     std::vector<MEDPARTITIONER::ConnectZone*> _connect_zones;
201
202     //family ids storages
203     std::vector<ParaMEDMEM::DataArrayInt*> _cell_family_ids;
204     std::vector<ParaMEDMEM::DataArrayInt*> _face_family_ids;
205     
206     //DataArrayInt* storages
207     std::map<std::string, ParaMEDMEM::DataArrayInt*> _map_dataarray_int;
208     //DataArrayDouble* storages
209     std::map<std::string, ParaMEDMEM::DataArrayDouble*> _map_dataarray_double;
210     
211     //fields to be partitioned
212     std::vector<std::string> _field_descriptions;
213     
214     //group family conversion
215     std::map<std::string, int> _family_info;
216     std::map<std::string, std::vector<std::string> > _group_info;
217   
218     //list of groups that are not to be splitted
219     std::vector<std::string> _indivisible_regions;
220
221     //name of global mesh
222     std::string _name;
223
224     //description of global mesh
225     std::string _description;
226
227     //specifies the driver associated to the collection
228     DriverType _driver_type;
229
230     //flag specifying that the splitter should create boundary constituent entity
231     //so that they are written in joints
232     bool _subdomain_boundary_creates;
233
234     //flag specifying that families must be preserved by the splitting
235     bool _family_splitting;
236
237     //flag specifying that groups must be created on all domains, even if they are empty
238     bool _create_empty_groups;
239
240     JointFinder* _joint_finder;
241   };
242 }
243 #endif