1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __MEDPARTITIONER_MESHCOLLECTION_HXX__
21 #define __MEDPARTITIONER_MESHCOLLECTION_HXX__
23 #include "MEDPARTITIONER.hxx"
24 #include "MEDPARTITIONER_Graph.hxx"
25 #include "MEDPARTITIONER_Utils.hxx"
35 class MEDCouplingUMesh;
37 class MEDCouplingSkyLineArray;
40 namespace MEDPARTITIONER
43 class MeshCollectionDriver;
44 class ParaDomainSelector;
48 typedef enum{MedAscii, MedXml, Undefined} DriverType;
49 typedef std::multimap<std::pair<int,int>, std::pair<int,int> > NodeMapping ;
50 typedef std::vector<std::pair<int,int> > NodeList;
52 class MEDPARTITIONER_EXPORT MeshCollection
56 //Constructing from an existing mesh and a new topology
57 MeshCollection(MeshCollection&, Topology*, bool family_splitting=false, bool create_empty_groups=false);
58 //Constructing the mesh collection from a file
59 MeshCollection(const std::string& filename);
60 //Constructing the mesh collection from a file
61 MeshCollection(const std::string& filename, ParaDomainSelector& domainSelector);
62 //Constructing the mesh collection from a file
63 MeshCollection(const std::string& filename, const std::string& meshname);
65 bool isParallelMode() const { return _domain_selector; }
67 //writing to a distributed file
68 void write(const std::string& filename);
71 MeshCollectionDriver *retrieveDriver();
72 MeshCollectionDriver *getDriver() const;
73 void setDriverType(MEDPARTITIONER::DriverType type) { _driver_type=type; }
75 //creation of the cell graph
76 void buildCellGraph(MEDCoupling::MEDCouplingSkyLineArray* & array,int *& edgeweights );
77 //creation of the cell graph
78 void buildParallelCellGraph(MEDCoupling::MEDCouplingSkyLineArray* & array,int *& edgeweights );
80 //creation and partition of the associated graph
81 Topology* createPartition(int nbdomain, Graph::splitter_type type = Graph::METIS,
82 const std::string& ="", int* edgeweights=0, int* verticesweights=0);
84 //creation of a user specified partition
85 Topology* createPartition(const int* partition);
87 //getting mesh dimension
88 int getMeshDimension() const;
89 int getNbOfLocalMeshes() const;
90 int getNbOfGlobalMeshes() const { return _mesh.size(); }
91 int getNbOfLocalCells() const;
92 int getNbOfLocalFaces() const;
94 //getting a reference to mesh vector
95 std::vector<MEDCoupling::MEDCouplingUMesh*>& getMesh();
96 std::vector<MEDCoupling::MEDCouplingUMesh*>& getFaceMesh();
97 std::vector<std::vector<MEDCoupling::MEDCouplingUMesh*> >& getGroupMeshes();
99 MEDCoupling::MEDCouplingUMesh* getMesh(int idomain) const;
100 MEDCoupling::MEDCouplingUMesh* getFaceMesh(int idomain);
101 std::vector<MEDCoupling::MEDCouplingUMesh*>& getGroupMeshes(int idomain);
103 std::vector<MEDCoupling::DataArrayInt*>& getCellFamilyIds() { return _cell_family_ids; }
104 std::vector<MEDCoupling::DataArrayInt*>& getFaceFamilyIds() { return _face_family_ids; }
106 std::map<std::string, MEDCoupling::DataArrayInt*>& getMapDataArrayInt() { return _map_dataarray_int; }
107 std::map<std::string, MEDCoupling::DataArrayDouble*>& getMapDataArrayDouble() { return _map_dataarray_double; }
109 std::map<std::string,int>& getFamilyInfo() { return _family_info; }
110 std::map<std::string, std::vector<std::string> >& getGroupInfo() { return _group_info; }
112 MEDCoupling::DataArrayDouble* getField(std::string descriptionField, int iold);
113 std::vector<std::string>& getFieldDescriptions() { return _field_descriptions; }
114 void prepareFieldDescriptions();
115 void filterFaceOnCell();
117 //getting a reference to connect zones vector
118 std::vector<MEDPARTITIONER::ConnectZone*>& getCZ();
120 //getting a pointer to topology
121 Topology* getTopology() const ;
122 ParaDomainSelector* getParaDomainSelector() const { return _domain_selector; }
123 void setParaDomainSelector(ParaDomainSelector* pds) { _domain_selector = pds; }
124 //setting a new topology
125 void setTopology(Topology* topology, bool takeOwneship);
127 //getting/setting the name of the global mesh (as opposed
128 //to the name of a subdomain \a nn, which is name_nn)
129 std::string getName() const { return _name; }
130 void setName(const std::string& name) { _name=name; }
131 void setDomainNames(const std::string& name);
133 void setNonEmptyMesh(int number) { _i_non_empty_mesh=number;}
135 //getting/setting the description of the global mesh
136 std::string getDescription() const { return _description; }
137 void setDescription(const std::string& name) { _description=name; }
139 //creates the node mapping between an old collection and the present one
140 void createNodeMapping(MeshCollection& initialCollection,
141 std::multimap<std::pair<int,int>,std::pair<int,int> >& nodeMapping);
143 void castCellMeshes(MeshCollection& initialCollection,
144 std::vector<std::vector<std::vector<int> > >& new2oldIds,
145 std::vector<MEDCoupling::DataArrayInt*> & o2nRenumber);
147 //creates faces on the new collection
148 void castFaceMeshes(MeshCollection& initialCollection,
149 const std::multimap<std::pair<int,int>, std::pair<int,int> >& nodeMapping,
150 std::vector<std::vector<std::vector<int> > >& new2oldIds);
152 //constructing connect zones
153 void buildConnectZones( const NodeMapping& nodeMapping,
154 const std::vector<MEDCoupling::DataArrayInt*> & o2nRenumber,
155 int nbInitialDomains );
157 // Find faces common with neighbor domains and put them in groups
158 void buildBoundaryFaces();
161 void castIntField(std::vector<MEDCoupling::MEDCouplingUMesh*>& meshesCastFrom,
162 std::vector<MEDCoupling::MEDCouplingUMesh*>& meshesCastTo,
163 std::vector<MEDCoupling::DataArrayInt*>& arrayFrom,
164 std::string nameArrayTo);
166 void castAllFields(MeshCollection& initialCollection,
167 std::string nameArrayTo);
169 void findCommonDistantNodes(std::vector<std::vector<std::multimap<int,int> > >& commonDistantNodes);
172 void remapIntField(int inew, int iold,
173 const MEDCoupling::MEDCouplingUMesh& sourceMesh,
174 const MEDCoupling::MEDCouplingUMesh& targetMesh,
175 const int* fromArray,
176 std::string nameArrayTo,
177 const BBTreeOfDim* tree);
179 void remapDoubleField(int inew, int iold,
180 MEDCoupling::DataArrayDouble* fromArray,
181 std::string nameArrayTo,
182 std::string descriptionField);
184 void createJointGroup( const std::vector< int >& faces,
190 //link to mesh_collection topology
193 //control over topology
196 //Driver for read/write operations
197 MeshCollectionDriver* _driver;
199 //Parallelizer - mark of parallel execution mode
200 ParaDomainSelector* _domain_selector;
203 std::vector<MEDCoupling::MEDCouplingUMesh*> _mesh;
204 std::vector<MEDCoupling::MEDCouplingUMesh*> _face_mesh;
206 //index of a non empty mesh within _mesh (in parallel mode all of meshes can be empty)
207 int _i_non_empty_mesh;
209 //family ids storages
210 std::vector<MEDCoupling::DataArrayInt*> _cell_family_ids;
211 std::vector<MEDCoupling::DataArrayInt*> _face_family_ids;
213 //DataArrayInt* storages
214 std::map<std::string, MEDCoupling::DataArrayInt*> _map_dataarray_int;
215 //DataArrayDouble* storages
216 std::map<std::string, MEDCoupling::DataArrayDouble*> _map_dataarray_double;
218 //fields to be partitioned
219 std::vector<std::string> _field_descriptions;
221 //group family conversion
222 std::map<std::string, int> _family_info;
223 std::map<std::string, std::vector<std::string> > _group_info;
225 //list of groups that are not to be splitted
226 std::vector<std::string> _indivisible_regions;
228 //name of global mesh
231 //description of global mesh
232 std::string _description;
234 //specifies the driver associated to the collection
235 DriverType _driver_type;
237 //flag specifying that the splitter should create boundary constituent entity
238 //so that they are written in joints
239 bool _subdomain_boundary_creates;
241 //flag specifying that families must be preserved by the splitting
242 bool _family_splitting;
244 //flag specifying that groups must be created on all domains, even if they are empty
245 bool _create_empty_groups;
247 JointFinder* _joint_finder;