1 // Copyright (C) 2007-2012 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.
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
19 #ifndef __MEDSPLITTER_MESHCOLLECTION_HXX__
20 #define __MEDSPLITTER_MESHCOLLECTION_HXX__
22 #include "MEDSPLITTER.hxx"
24 #include "MEDSPLITTER_Graph.hxx"
25 #include "MEDSPLITTER_FaceModel.hxx"
26 #include "boost/shared_ptr.hpp"
43 class MESHCollectionDriver;
44 class ParaDomainSelector;
46 typedef enum{MedAscii, MedXML, Undefined} DriverType;
48 class MEDSPLITTER_EXPORT MESHCollection
56 //Constructing from an existing mesh and a new topology
57 MESHCollection(const 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);
62 //Constructing the mesh collection from a file
63 MESHCollection(const std::string& filename, ParaDomainSelector& domainSelector);
65 //Constructing the mesh collection from a file
66 MESHCollection(const std::string& filename, const std::string& meshname);
70 bool isParallelMode() const { return _domain_selector; }
72 //writing to a distributed file
73 void write(const std::string& filename);
76 MESHCollectionDriver* retrieveDriver();
77 MESHCollectionDriver* getDriver() const;
78 void setDriverType(MEDSPLITTER::DriverType type) {_driver_type=type;}
80 //creation of the cell graph
81 void buildCellGraph(MEDMEM::MEDSKYLINEARRAY* & array,int *& edgeweights );
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);
87 //creation of a user specified partition
88 Topology* createPartition(const int* partition);
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 ;
94 //getting list of coordinates
95 void getCoordinates(int* node_list,int nb_nodes, double* coordinates) const ;
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;
104 void getFaceConnectivity( const int* cell_list,int nb_cells,MED_EN::medEntityMesh,MED_EN::medGeometryElement type, int* type_connectivity) const ;
106 //void getFaceConnectivity( const int* cell_list,int nb_cells,MED_EN::medGeometryElement type, int* type_connectivity) const ;
108 //getting mesh dimension
109 int getMeshDimension() const ;
111 //getting space dimension
112 int getSpaceDimension() const ;
114 //getting system of coordinates
115 std::string getSystem() const;
117 //getting name of the mesh
118 std::string getMeshName() const;
120 //return constituent entity
121 MED_EN::medEntityMesh getSubEntity() const;
123 //getting a reference to mesh vector
124 std::vector<MEDMEM::MESH*>& getMesh() ;
126 //getting a reference to a domain mesh
127 MEDMEM::MESH* getMesh(int) const;
129 //getting a reference to connect zones vector
130 std::vector<MEDMEM::CONNECTZONE*>& getCZ();
132 //getting a pointer to topology
133 Topology* getTopology() const ;
136 //settig a new topology
137 void setTopology(Topology* topology);
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;}
144 //getting/setting the description of the global mesh
145 string getDescription() const {return _description;}
146 void setDescription(const string& name) { _description=name;}
148 //!transfers families from an old MESHCollection to new mesh
149 void castFamilies(const MESHCollection& old_collection);
151 void castSupport(const MESHCollection& old_collection, std::vector<const MEDMEM::SUPPORT*>& old_support, std::vector<MEDMEM::SUPPORT*>& new_support);
153 //!casts all the fields to the new mesh collection
154 void castAllFields(const MESHCollection& old_collection);
156 //!casts one specific field to the new mesh collection
157 void castField(const MESHCollection& old_collection, const string& fieldname, int itnumber, int ordernumber);
159 //choosing a group to be indivisible
160 void setIndivisibleGroup(const string& a);
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);
167 void addJointGroup(const std::vector<int>&, int idomain, int idistant);
169 static bool isDimensionOK(MED_EN::medGeometryElement type, int dim)
171 return ((type/100 == dim) || (dim==2 && type == MED_EN::MED_POLYGON) || (dim==3 && type == MED_EN::MED_POLYHEDRA));
173 void setSubdomainBoundaryCreates(bool flag) { _subdomain_boundary_creates=flag;}
174 bool getSubdomainBoundaryCreates(){return _subdomain_boundary_creates;}
176 void setFamilySplitting(bool flag){_family_splitting=flag;}
177 bool getFamilySplitting(){return _family_splitting;}
179 void setCreateEmptyGroups(bool flag){_create_empty_groups=flag;}
180 bool getCreateEmptyGroups(){return _create_empty_groups;}
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);
188 //!creates the tags for indivisible groups
189 void treatIndivisibleRegions(int* tag);
191 //!projects a field from an old collection to the present one
192 //!field is identified by (name, dt, it)
194 void castFields(const MESHCollection& old_collection, const string& fieldname, int itnumber, int ordernumber);
196 void getFaces(int idomain, std::map<MED_EN::medGeometryElement, std::vector<MEDSPLITTER_FaceModel*> >&);
198 MEDSPLITTER_FaceModel* getCommonFace(int ip1,int ilocal1,int ip2,int ilocal2,int face_index);
200 template<class TID2CONN>
201 void fillGlobalConnectivity(TID2CONN & node2cell, TID2CONN & cell2node );
203 //!link to mesh_collection topology
206 //!control over topology
210 boost::shared_ptr<Graph> _cell_graph;
212 //! Driver for read/write operations
213 MESHCollectionDriver* _driver;
215 //! Parallelizer - mark of parallel execution mode
216 ParaDomainSelector* _domain_selector;
219 std::vector<MEDMEM::MESH*> _mesh;
221 //!index of a non empty mesh within _mesh (in parallel mode all of meshes can be empty)
222 int _i_non_empty_mesh;
224 //!links to connectzones
225 std::vector<MEDMEM::CONNECTZONE*> _connect_zones;
227 //!list of groups that are not to be splitted
228 std::vector<std::string> _indivisible_regions;
230 //!name of global mesh
233 //!description of global mesh
236 //! specifies the driver associated to the collection
237 DriverType _driver_type;
239 /*! flag specifying that the splitter should create boundary constituent entity
240 so that they are written in joints*/
241 bool _subdomain_boundary_creates;
243 /*! flag specifying that families must be preserved by the
245 bool _family_splitting;
247 /*! flag specifying that groups must be created on all domains,
248 even if they are empty*/
249 bool _create_empty_groups;
254 #endif /*MESHCOLLECTION_*/