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