1 // Copyright (C) 2007-2021 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"
26 #include "MEDCouplingSkyLineArray.hxx"
36 class MEDCouplingUMesh;
38 class MEDCouplingSkyLineArray;
41 namespace MEDPARTITIONER
44 class MeshCollectionDriver;
45 class ParaDomainSelector;
49 typedef enum{MedAscii, MedXml, Undefined} DriverType;
50 typedef std::multimap<std::pair<int,mcIdType>, std::pair<int,mcIdType> > NodeMapping ;
51 typedef std::vector<std::pair<int,int> > NodeList;
53 class MEDPARTITIONER_EXPORT 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);
66 bool isParallelMode() const { return _domain_selector; }
68 //writing to a distributed file
69 void write(const std::string& filename);
72 MeshCollectionDriver *retrieveDriver();
73 MeshCollectionDriver *getDriver() const;
74 void setDriverType(MEDPARTITIONER::DriverType type) { _driver_type=type; }
76 //creation of the cell graph
77 void buildCellGraph(MEDCoupling::MEDCouplingSkyLineArray* & array,int *& edgeweights );
78 //creation of the cell graph
79 void buildParallelCellGraph(MEDCoupling::MEDCouplingSkyLineArray* & array,int *& edgeweights );
81 //creation and partition of the associated graph
82 Topology* createPartition(int nbdomain, Graph::splitter_type type = Graph::METIS,
83 const std::string& ="", int* edgeweights=0, int* verticesweights=0);
85 //creation of a user specified partition
86 Topology* createPartition(const int* partition);
88 //getting mesh dimension
89 int getMeshDimension() const;
90 int getNbOfLocalMeshes() const;
91 int getNbOfGlobalMeshes() const { return (int)_mesh.size(); }
92 mcIdType getNbOfLocalCells() const;
93 mcIdType getNbOfLocalFaces() const;
95 //getting a reference to mesh vector
96 std::vector<MEDCoupling::MEDCouplingUMesh*>& getMesh();
97 std::vector<MEDCoupling::MEDCouplingUMesh*>& getFaceMesh();
98 std::vector<std::vector<MEDCoupling::MEDCouplingUMesh*> >& getGroupMeshes();
100 MEDCoupling::MEDCouplingUMesh* getMesh(int idomain) const;
101 MEDCoupling::MEDCouplingUMesh* getFaceMesh(int idomain);
102 std::vector<MEDCoupling::MEDCouplingUMesh*>& getGroupMeshes(int idomain);
104 std::vector<MEDCoupling::DataArrayIdType*>& getCellFamilyIds() { return _cell_family_ids; }
105 std::vector<MEDCoupling::DataArrayIdType*>& getFaceFamilyIds() { return _face_family_ids; }
107 std::map<std::string, MEDCoupling::DataArrayIdType*>& getMapDataArrayInt() { return _map_dataarray_int; }
108 std::map<std::string, MEDCoupling::DataArrayDouble*>& getMapDataArrayDouble() { return _map_dataarray_double; }
110 std::map<std::string,mcIdType>& getFamilyInfo() { return _family_info; }
111 std::map<std::string, std::vector<std::string> >& getGroupInfo() { return _group_info; }
113 MEDCoupling::DataArrayDouble* getField(std::string descriptionField, int iold);
114 std::vector<std::string>& getFieldDescriptions() { return _field_descriptions; }
115 void prepareFieldDescriptions();
116 void filterFaceOnCell();
118 //getting a reference to connect zones vector
119 std::vector<MEDPARTITIONER::ConnectZone*>& getCZ();
121 //getting a pointer to topology
122 Topology* getTopology() const ;
123 ParaDomainSelector* getParaDomainSelector() const { return _domain_selector; }
124 void setParaDomainSelector(ParaDomainSelector* pds) { _domain_selector = pds; }
125 //setting a new topology
126 void setTopology(Topology* topology, bool takeOwneship);
128 //getting/setting the name of the global mesh (as opposed
129 //to the name of a subdomain \a nn, which is name_nn)
130 std::string getName() const { return _name; }
131 void setName(const std::string& name) { _name=name; }
132 void setDomainNames(const std::string& name);
134 void setNonEmptyMesh(int number) { _i_non_empty_mesh=number;}
136 //getting/setting the description of the global mesh
137 std::string getDescription() const { return _description; }
138 void setDescription(const std::string& name) { _description=name; }
140 //creates the node mapping between an old collection and the present one
141 void createNodeMapping(MeshCollection& initialCollection,
142 std::multimap<std::pair<int,mcIdType>,std::pair<int,mcIdType> >& nodeMapping);
144 void castCellMeshes(MeshCollection& initialCollection,
145 std::vector<std::vector<std::vector<mcIdType> > >& new2oldIds,
146 std::vector<MEDCoupling::DataArrayIdType*> & o2nRenumber);
148 //creates faces on the new collection
149 void castFaceMeshes(MeshCollection& initialCollection,
150 const std::multimap<std::pair<int,mcIdType>, std::pair<int,mcIdType> >& nodeMapping,
151 std::vector<std::vector<std::vector<mcIdType> > >& new2oldIds);
153 //constructing connect zones
154 void buildConnectZones( const NodeMapping& nodeMapping,
155 const std::vector<MEDCoupling::DataArrayIdType*> & o2nRenumber,
156 int nbInitialDomains );
158 // Find faces common with neighbor domains and put them in groups
159 void buildBoundaryFaces();
162 void castIntField(std::vector<MEDCoupling::MEDCouplingUMesh*>& meshesCastFrom,
163 std::vector<MEDCoupling::MEDCouplingUMesh*>& meshesCastTo,
164 std::vector<MEDCoupling::DataArrayIdType*>& arrayFrom,
165 std::string nameArrayTo);
167 void castAllFields(MeshCollection& initialCollection,
168 std::string nameArrayTo);
170 void findCommonDistantNodes(std::vector<std::vector<std::multimap<int,mcIdType> > >& commonDistantNodes);
173 void remapIntField(int inew, int iold,
174 const MEDCoupling::MEDCouplingUMesh& sourceMesh,
175 const MEDCoupling::MEDCouplingUMesh& targetMesh,
176 const mcIdType* fromArray,
177 std::string nameArrayTo,
178 const BBTreeOfDim* tree);
180 void remapDoubleField(int inew, int iold,
181 MEDCoupling::DataArrayDouble* fromArray,
182 std::string nameArrayTo,
183 std::string descriptionField);
185 void createJointGroup( const std::vector< mcIdType >& faces,
191 //link to mesh_collection topology
194 //control over topology
197 //Driver for read/write operations
198 MeshCollectionDriver* _driver;
200 //Parallelizer - mark of parallel execution mode
201 ParaDomainSelector* _domain_selector;
204 std::vector<MEDCoupling::MEDCouplingUMesh*> _mesh;
205 std::vector<MEDCoupling::MEDCouplingUMesh*> _face_mesh;
207 //index of a non empty mesh within _mesh (in parallel mode all of meshes can be empty)
208 int _i_non_empty_mesh;
210 //family ids storages
211 std::vector<MEDCoupling::DataArrayIdType*> _cell_family_ids;
212 std::vector<MEDCoupling::DataArrayIdType*> _face_family_ids;
214 //DataArrayInt* storages
215 std::map<std::string, MEDCoupling::DataArrayIdType*> _map_dataarray_int;
216 //DataArrayDouble* storages
217 std::map<std::string, MEDCoupling::DataArrayDouble*> _map_dataarray_double;
219 //fields to be partitioned
220 std::vector<std::string> _field_descriptions;
222 //group family conversion
223 std::map<std::string, mcIdType> _family_info;
224 std::map<std::string, std::vector<std::string> > _group_info;
226 //list of groups that are not to be split
227 std::vector<std::string> _indivisible_regions;
229 //name of global mesh
232 //description of global mesh
233 std::string _description;
235 //specifies the driver associated to the collection
236 DriverType _driver_type;
238 //flag specifying that the splitter should create boundary constituent entity
239 //so that they are written in joints
240 bool _subdomain_boundary_creates;
242 //flag specifying that families must be preserved by the splitting
243 bool _family_splitting;
245 //flag specifying that groups must be created on all domains, even if they are empty
246 bool _create_empty_groups;
248 JointFinder* _joint_finder;