Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDSPLITTER / MEDSPLITTER_MESHCollection.hxx
1 // Copyright (C) 2007-2013  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 #ifndef __MEDSPLITTER_MESHCOLLECTION_HXX__
20 #define __MEDSPLITTER_MESHCOLLECTION_HXX__
21
22 #include "MEDSPLITTER.hxx"
23
24 #include "MEDSPLITTER_Graph.hxx"
25 #include "MEDSPLITTER_FaceModel.hxx"
26 #include "boost/shared_ptr.hpp"
27 #include <vector>
28 #include <map>
29
30
31 namespace MEDMEM
32 {
33   class MESH;
34   class CONNECTZONE;
35   class MEDSKYLINEARAY;
36   class SUPPORT;
37 }
38
39 namespace MEDSPLITTER
40 {
41
42   class Topology;
43   class MESHCollectionDriver;
44   class ParaDomainSelector;
45
46   typedef enum{MedAscii, MedXML, Undefined} DriverType;
47
48   class MEDSPLITTER_EXPORT MESHCollection
49   {
50
51   public:
52
53     //Default constructor
54     MESHCollection();
55
56     //Constructing from an existing mesh and a new topology
57     MESHCollection(const MESHCollection&, Topology*, bool family_splitting=false, bool create_empty_groups=false);
58
59     //Constructing the mesh collection from a file
60     MESHCollection(const std::string& filename);
61
62     //Constructing the mesh collection from a file
63     MESHCollection(const std::string& filename, ParaDomainSelector& domainSelector);
64
65     //Constructing the mesh collection from a file
66     MESHCollection(const std::string& filename, const std::string& meshname);
67
68     ~MESHCollection();
69         
70     bool isParallelMode() const { return _domain_selector; }
71         
72     //writing to a distributed file
73     void write(const std::string& filename);
74
75     //getting the driver
76     MESHCollectionDriver* retrieveDriver();
77     MESHCollectionDriver* getDriver() const;
78     void setDriverType(MEDSPLITTER::DriverType type) {_driver_type=type;}
79
80     //creation of the cell graph
81     void buildCellGraph(MEDMEM::MEDSKYLINEARRAY* & array,int *& edgeweights );
82
83     //creation and partition of the associated graph
84     Topology* createPartition(int nbdomain, Graph::splitter_type type = Graph::METIS,
85                               const string& ="", int* edgeweights=0, int* verticesweights=0);
86
87     //creation of a user specified partition
88     Topology* createPartition(const int* partition);
89
90     //retrieving list of types
91     void getTypeList(int* cell_list,int nb_cells,MED_EN::medEntityMesh entity,
92                      MED_EN::medGeometryElement* type_list) const ;
93
94     //getting list of coordinates
95     void getCoordinates(int* node_list,int nb_nodes, double* coordinates) const ;
96
97     //getting connectivities
98     void getNodeConnectivity( const int*  cell_list,int nb_cells,MED_EN::medEntityMesh,MED_EN::medGeometryElement type, int* type_connectivity) const ;
99     void getPolygonNodeConnectivity(const int* cell_list,int nb_cells,MED_EN::medEntityMesh entity,
100                                     vector<int>& type_connectivity, vector<int>& connectivity_index) const;
101     void getPolyhedraNodeConnectivity(const int* cell_list,int nb_cells,MED_EN::medEntityMesh entity,
102                                       vector<int>& type_connectivity, vector<int>& connectivity_index/*, vector<int>& face_connectivity_index*/) const;
103
104     void getFaceConnectivity( const int*  cell_list,int nb_cells,MED_EN::medEntityMesh,MED_EN::medGeometryElement type, int* type_connectivity) const ;
105
106     //void getFaceConnectivity( const int*  cell_list,int nb_cells,MED_EN::medGeometryElement type, int* type_connectivity) const ;
107
108     //getting mesh dimension
109     int getMeshDimension() const ;
110
111     //getting space dimension
112     int getSpaceDimension() const ;
113
114     //getting system of coordinates
115     std::string getSystem() const;
116
117     //getting name of the mesh
118     std::string getMeshName() const;
119
120     //return constituent entity
121     MED_EN::medEntityMesh getSubEntity() const;
122
123     //getting a reference to mesh vector
124     std::vector<MEDMEM::MESH*>& getMesh() ;
125
126     //getting a reference to a domain mesh
127     MEDMEM::MESH* getMesh(int) const;
128
129     //getting a reference to connect zones vector
130     std::vector<MEDMEM::CONNECTZONE*>& getCZ();
131
132     //getting a pointer to topology
133     Topology* getTopology() const ;
134
135
136     //settig a new topology
137     void setTopology(Topology* topology);
138
139     //getting/setting the name of the global mesh (as opposed 
140     //to the name of a subdomain \a nn, which is name_nn) 
141     string getName() const {return _name;}
142     void setName(const string& name) {_name=name;}
143
144     //getting/setting the description of the global mesh
145     string getDescription() const {return _description;}
146     void setDescription(const string& name) { _description=name;}
147
148     //!transfers families from an old MESHCollection to new mesh
149     void castFamilies(const MESHCollection& old_collection);
150
151     void castSupport(const MESHCollection& old_collection, std::vector<const MEDMEM::SUPPORT*>& old_support, std::vector<MEDMEM::SUPPORT*>& new_support);
152
153     //!casts all the fields to the new mesh collection
154     void castAllFields(const MESHCollection& old_collection);
155
156     //!casts one specific field to the new mesh collection
157     void castField(const MESHCollection& old_collection, const string& fieldname, int itnumber, int ordernumber);
158
159     //choosing a group to be indivisible
160     void setIndivisibleGroup(const string& a);
161
162     //!constructing connect zones
163     // void buildConnectZones(int idomain);
164     void buildConnectZones();
165     void buildConnectZonesBetweenProcs(std::vector <std::map <MED_EN::medGeometryElement, std::vector<MEDSPLITTER_FaceModel*> > > &, map< pair<int,int>, MEDMEM::MEDSKYLINEARRAY*> & local_cell_cell_correspondency);
166
167     void addJointGroup(const std::vector<int>&, int idomain, int idistant);
168
169     static bool isDimensionOK(MED_EN::medGeometryElement type, int dim)
170     {
171       return ((type/100 == dim) || (dim==2 && type == MED_EN::MED_POLYGON) || (dim==3 && type == MED_EN::MED_POLYHEDRA));
172     }
173     void setSubdomainBoundaryCreates(bool flag) {  _subdomain_boundary_creates=flag;}
174     bool getSubdomainBoundaryCreates(){return _subdomain_boundary_creates;}
175
176     void setFamilySplitting(bool flag){_family_splitting=flag;}
177     bool getFamilySplitting(){return _family_splitting;}
178
179     void setCreateEmptyGroups(bool flag){_create_empty_groups=flag;}
180     bool getCreateEmptyGroups(){return _create_empty_groups;}
181
182
183   private:
184
185     //!creates connectivities for a domain and an entity (face or cell)
186     void createNodalConnectivity(const MESHCollection & initial_collection, int idomain, MED_EN::medEntityMesh entity);
187
188     //!creates the tags for indivisible groups
189     void treatIndivisibleRegions(int* tag);
190
191     //!projects a field from an old collection to the present one
192     //!field is identified by (name, dt, it)
193     template <class T>
194     void castFields(const MESHCollection& old_collection, const string& fieldname, int itnumber, int ordernumber);
195
196     void getFaces(int idomain, std::map<MED_EN::medGeometryElement, std::vector<MEDSPLITTER_FaceModel*> >&);
197
198     MEDSPLITTER_FaceModel* getCommonFace(int ip1,int ilocal1,int ip2,int ilocal2,int face_index);
199
200     template<class TID2CONN>
201     void fillGlobalConnectivity(TID2CONN & node2cell, TID2CONN & cell2node );
202
203     //!link to mesh_collection topology
204     Topology*                         _topology;
205
206     //!control over topology
207     bool                              _owns_topology;
208
209     //!link to graph
210     boost::shared_ptr<Graph>          _cell_graph;
211
212     //! Driver for read/write operations
213     MESHCollectionDriver*             _driver;
214
215     //! Parallelizer - mark of parallel execution mode
216     ParaDomainSelector*               _domain_selector;
217
218     //!links to meshes
219     std::vector<MEDMEM::MESH*>        _mesh;
220
221     //!index of a non empty mesh within _mesh (in parallel mode all of meshes can be empty)
222     int                               _i_non_empty_mesh;
223
224     //!links to connectzones
225     std::vector<MEDMEM::CONNECTZONE*> _connect_zones;
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     string                            _name;
232
233     //!description of global mesh
234     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
244       splitting*/
245     bool                              _family_splitting;
246
247     /*! flag specifying that groups must be created on all domains, 
248       even if they are empty*/
249     bool                              _create_empty_groups;
250   };
251
252 }//of namespace
253
254 #endif /*MESHCOLLECTION_*/