]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx
Salome HOME
0022875: EDF 7690 MED: Creating joints with medpartitioner in the MEDCoupling API
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_MeshCollection.hxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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   class MEDCouplingSkyLineArray;
40 }
41
42 namespace MEDPARTITIONER
43 {
44   class Topology;
45   class MeshCollectionDriver;
46   class ParaDomainSelector;
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(ParaMEDMEM::MEDCouplingSkyLineArray* & array,int *& edgeweights );
79    //creation of the cell graph
80     void buildParallelCellGraph(ParaMEDMEM::MEDCouplingSkyLineArray* & array,int *& edgeweights );
81
82     //creation and partition of the associated graph
83     Topology* createPartition(int nbdomain, Graph::splitter_type type = Graph::METIS,
84                               const std::string& ="", int* edgeweights=0, int* verticesweights=0);
85
86     //creation of a user specified partition
87     Topology* createPartition(const int* partition);
88
89     //getting mesh dimension
90     int getMeshDimension() const;
91     int getNbOfLocalMeshes() const;
92     int getNbOfGlobalMeshes() const { return _mesh.size(); }
93     int getNbOfLocalCells() const;
94     int getNbOfLocalFaces() const;
95     
96     //getting a reference to mesh vector
97     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getMesh();
98     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getFaceMesh();
99     std::vector<std::vector<ParaMEDMEM::MEDCouplingUMesh*> >& getGroupMeshes();
100
101     ParaMEDMEM::MEDCouplingUMesh* getMesh(int idomain) const;
102     ParaMEDMEM::MEDCouplingUMesh* getFaceMesh(int idomain);
103     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getGroupMeshes(int idomain);
104
105     std::vector<ParaMEDMEM::DataArrayInt*>& getCellFamilyIds() { return _cell_family_ids; }
106     std::vector<ParaMEDMEM::DataArrayInt*>& getFaceFamilyIds() { return _face_family_ids; }
107     
108     std::map<std::string, ParaMEDMEM::DataArrayInt*>& getMapDataArrayInt() { return _map_dataarray_int; }
109     std::map<std::string, ParaMEDMEM::DataArrayDouble*>& getMapDataArrayDouble() { return _map_dataarray_double; }
110
111     std::map<std::string,int>& getFamilyInfo() { return _family_info; }
112     std::map<std::string, std::vector<std::string> >& getGroupInfo() { return _group_info; }
113
114     ParaMEDMEM::DataArrayDouble* getField(std::string descriptionField, int iold);
115     std::vector<std::string>&  getFieldDescriptions() { return _field_descriptions; }
116     void prepareFieldDescriptions();
117     void filterFaceOnCell();
118      
119     //getting a reference to connect zones vector
120     std::vector<MEDPARTITIONER::ConnectZone*>& getCZ();
121
122     //getting a pointer to topology
123     Topology* getTopology() const ;
124     ParaDomainSelector* getParaDomainSelector() const { return _domain_selector; }
125     void setParaDomainSelector(ParaDomainSelector* pds) { _domain_selector = pds; }
126     //setting a new topology
127     void setTopology(Topology* topology, bool takeOwneship);
128
129     //getting/setting the name of the global mesh (as opposed 
130     //to the name of a subdomain \a nn, which is name_nn) 
131     std::string getName() const { return _name; }
132     void setName(const std::string& name) { _name=name; }
133     void setDomainNames(const std::string& name);
134
135     void setNonEmptyMesh(int number) { _i_non_empty_mesh=number;}
136
137     //getting/setting the description of the global mesh
138     std::string getDescription() const { return _description; }
139     void setDescription(const std::string& name) { _description=name; }
140
141     //creates the node mapping between an old collection and the present one
142     void createNodeMapping(MeshCollection& initialCollection, 
143                            std::multimap<std::pair<int,int>,std::pair<int,int> >& nodeMapping);
144     
145     void castCellMeshes(MeshCollection& initialCollection, 
146                         std::vector<std::vector<std::vector<int> > >& new2oldIds,
147                         std::vector<ParaMEDMEM::DataArrayInt*> & o2nRenumber);
148     
149     //creates faces on the new collection
150     void castFaceMeshes(MeshCollection& initialCollection,
151                         const std::multimap<std::pair<int,int>, std::pair<int,int> >& nodeMapping,
152                         std::vector<std::vector<std::vector<int> > >& new2oldIds);
153
154     //constructing connect zones
155     void buildConnectZones( const NodeMapping& nodeMapping,
156                             const std::vector<ParaMEDMEM::DataArrayInt*> & o2nRenumber,
157                             int nbInitialDomains );
158
159     // Find faces common with neighbor domains and put them in groups
160     void buildBoundaryFaces();
161
162   private:
163     void castIntField(std::vector<ParaMEDMEM::MEDCouplingUMesh*>& meshesCastFrom,
164                        std::vector<ParaMEDMEM::MEDCouplingUMesh*>& meshesCastTo,
165                        std::vector<ParaMEDMEM::DataArrayInt*>& arrayFrom,
166                        std::string nameArrayTo);
167
168     void castAllFields(MeshCollection& initialCollection,
169                        std::string nameArrayTo);
170
171     void findCommonDistantNodes(std::vector<std::vector<std::multimap<int,int> > >& commonDistantNodes);
172
173     
174     void remapIntField(int inew, int iold, 
175                        const ParaMEDMEM::MEDCouplingUMesh& sourceMesh,
176                        const ParaMEDMEM::MEDCouplingUMesh& targetMesh,
177                        const int* fromArray,
178                        std::string nameArrayTo,
179                        const BBTreeOfDim* tree);
180
181     void remapDoubleField(int inew, int iold,
182                            ParaMEDMEM::DataArrayDouble* fromArray,
183                            std::string nameArrayTo,
184                            std::string descriptionField);
185
186     void createJointGroup( const std::vector< int >& faces,
187                            const int                 inew1,
188                            const int                 inew2,
189                            const bool                is2nd );
190   private:
191
192     //link to mesh_collection topology
193     Topology* _topology;
194     
195     //control over topology
196     bool _owns_topology;
197     
198     //Driver for read/write operations
199     MeshCollectionDriver* _driver;
200     
201     //Parallelizer - mark of parallel execution mode
202     ParaDomainSelector* _domain_selector;
203     
204     //links to meshes
205     std::vector<ParaMEDMEM::MEDCouplingUMesh*> _mesh;
206     std::vector<ParaMEDMEM::MEDCouplingUMesh*> _face_mesh;
207     
208     //index of a non empty mesh within _mesh (in parallel mode all of meshes can be empty)
209     int _i_non_empty_mesh;
210     
211     //family ids storages
212     std::vector<ParaMEDMEM::DataArrayInt*> _cell_family_ids;
213     std::vector<ParaMEDMEM::DataArrayInt*> _face_family_ids;
214     
215     //DataArrayInt* storages
216     std::map<std::string, ParaMEDMEM::DataArrayInt*> _map_dataarray_int;
217     //DataArrayDouble* storages
218     std::map<std::string, ParaMEDMEM::DataArrayDouble*> _map_dataarray_double;
219     
220     //fields to be partitioned
221     std::vector<std::string> _field_descriptions;
222     
223     //group family conversion
224     std::map<std::string, int> _family_info;
225     std::map<std::string, std::vector<std::string> > _group_info;
226   
227     //list of groups that are not to be splitted
228     std::vector<std::string> _indivisible_regions;
229
230     //name of global mesh
231     std::string _name;
232
233     //description of global mesh
234     std::string _description;
235
236     //specifies the driver associated to the collection
237     DriverType _driver_type;
238
239     //flag specifying that the splitter should create boundary constituent entity
240     //so that they are written in joints
241     bool _subdomain_boundary_creates;
242
243     //flag specifying that families must be preserved by the splitting
244     bool _family_splitting;
245
246     //flag specifying that groups must be created on all domains, even if they are empty
247     bool _create_empty_groups;
248
249     JointFinder* _joint_finder;
250   };
251 }
252 #endif