Back to index

salome-med  6.5.0
MEDPARTITIONER_MeshCollection.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __MEDPARTITIONER_MESHCOLLECTION_HXX__
00021 #define __MEDPARTITIONER_MESHCOLLECTION_HXX__
00022 
00023 #include "MEDPARTITIONER.hxx"
00024 #include "MEDPARTITIONER_Graph.hxx"
00025 
00026 #include "MEDCouplingUMesh.hxx"
00027 
00028 #include <map>
00029 #include <vector>
00030 #include <string>
00031 
00032 namespace ParaMEDMEM
00033 {
00034   class MEDCouplingUMesh;
00035   class DataArrayInt;
00036 }
00037 
00038 namespace MEDPARTITIONER
00039 {
00040   class Topology;
00041   class MeshCollectionDriver;
00042   class ParaDomainSelector;
00043   class SkyLineArray;
00044   class ConnectZone;
00045   class JointFinder;
00046   
00047   typedef enum{MedAscii, MedXml, Undefined} DriverType;
00048   typedef std::multimap<std::pair<int,int>, std::pair<int,int> > NodeMapping ;
00049   typedef std::vector<std::pair<int,int> >  NodeList;
00050   
00051   class MEDPARTITIONER_EXPORT MeshCollection
00052   {
00053   public:
00054     MeshCollection();
00055     //Constructing from an existing mesh and a new topology
00056     MeshCollection(MeshCollection&, Topology*, bool family_splitting=false, bool create_empty_groups=false);
00057     //Constructing the mesh collection from a file
00058     MeshCollection(const std::string& filename);
00059     //Constructing the mesh collection from a file
00060     MeshCollection(const std::string& filename, ParaDomainSelector& domainSelector);
00061     //Constructing the mesh collection from a file
00062     MeshCollection(const std::string& filename, const std::string& meshname);
00063     ~MeshCollection();
00064     bool isParallelMode() const { return _domain_selector; }
00065     
00066     //writing to a distributed file
00067     void write(const std::string& filename);
00068     
00069     //getting the driver
00070     MeshCollectionDriver *retrieveDriver();
00071     MeshCollectionDriver *getDriver() const;
00072     void setDriverType(MEDPARTITIONER::DriverType type) { _driver_type=type; }
00073 
00074     //creation of the cell graph
00075     void buildCellGraph(MEDPARTITIONER::SkyLineArray* & array,int *& edgeweights );
00076     //creation and partition of the associated graph
00077     Topology* createPartition(int nbdomain, Graph::splitter_type type = Graph::METIS,
00078                               const std::string& ="", int* edgeweights=0, int* verticesweights=0);
00079 
00080     //creation of a user specified partition
00081     Topology* createPartition(const int* partition);
00082 
00083     //getting mesh dimension
00084     int getMeshDimension() const;
00085     int getNbOfLocalMeshes() const;
00086     int getNbOfGlobalMeshes() const { return _mesh.size(); }
00087     int getNbOfLocalCells() const;
00088     int getNbOfLocalFaces() const;
00089     
00090     //getting a reference to mesh vector
00091     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getMesh();
00092     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getFaceMesh();
00093     std::vector<std::vector<ParaMEDMEM::MEDCouplingUMesh*> >& getGroupMeshes();
00094 
00095     ParaMEDMEM::MEDCouplingUMesh* getMesh(int idomain) const;
00096     ParaMEDMEM::MEDCouplingUMesh* getFaceMesh(int idomain);
00097     std::vector<ParaMEDMEM::MEDCouplingUMesh*>& getGroupMeshes(int idomain);
00098 
00099     std::vector<ParaMEDMEM::DataArrayInt*>& getCellFamilyIds() { return _cell_family_ids; }
00100     std::vector<ParaMEDMEM::DataArrayInt*>& getFaceFamilyIds() { return _face_family_ids; }
00101     
00102     std::map<std::string, ParaMEDMEM::DataArrayInt*>& getMapDataArrayInt() { return _map_dataarray_int; }
00103     std::map<std::string, ParaMEDMEM::DataArrayDouble*>& getMapDataArrayDouble() { return _map_dataarray_double; }
00104 
00105     std::map<std::string,int>& getFamilyInfo() { return _family_info; }
00106     std::map<std::string, std::vector<std::string> >& getGroupInfo() { return _group_info; }
00107 
00108     ParaMEDMEM::DataArrayDouble* getField(std::string descriptionField, int iold);
00109     std::vector<std::string>&  getFieldDescriptions() { return _field_descriptions; }
00110     void prepareFieldDescriptions();
00111     void filterFaceOnCell();
00112      
00113     //getting a reference to connect zones vector
00114     std::vector<MEDPARTITIONER::ConnectZone*>& getCZ();
00115 
00116     //getting a pointer to topology
00117     Topology* getTopology() const ;
00118     ParaDomainSelector* getParaDomainSelector() const { return _domain_selector; }
00119     //setting a new topology
00120     void setTopology(Topology* topology);
00121 
00122     //getting/setting the name of the global mesh (as opposed 
00123     //to the name of a subdomain \a nn, which is name_nn) 
00124     std::string getName() const { return _name; }
00125     void setName(const std::string& name) { _name=name; }
00126     void setDomainNames(const std::string& name);
00127 
00128     //getting/setting the description of the global mesh
00129     std::string getDescription() const { return _description; }
00130     void setDescription(const std::string& name) { _description=name; }
00131 
00132     //creates the node mapping between an old collection and the present one
00133     void createNodeMapping(MeshCollection& initialCollection, 
00134                            std::multimap<std::pair<int,int>,std::pair<int,int> >& nodeMapping);
00135     
00136     void castCellMeshes(MeshCollection& initialCollection, 
00137                         std::vector<std::vector<std::vector<int> > >& new2oldIds);
00138     
00139     //creates faces on the new collection
00140     void castFaceMeshes(MeshCollection& initialCollection,
00141                         const std::multimap<std::pair<int,int>, std::pair<int,int> >& nodeMapping,
00142                         std::vector<std::vector<std::vector<int> > >& new2oldIds);
00143 
00144   private:
00145     void castIntField2(std::vector<ParaMEDMEM::MEDCouplingUMesh*>& meshesCastFrom,
00146                        std::vector<ParaMEDMEM::MEDCouplingUMesh*>& meshesCastTo,
00147                        std::vector<ParaMEDMEM::DataArrayInt*>& arrayFrom,
00148                        std::string nameArrayTo);
00149 
00150     void castAllFields(MeshCollection& initialCollection,
00151                        std::string nameArrayTo);
00152 
00153     void findCommonDistantNodes(std::vector<std::vector<std::multimap<int,int> > >& commonDistantNodes);
00154 
00155     void remapIntField(const ParaMEDMEM::MEDCouplingUMesh& sourceMesh,
00156                        const ParaMEDMEM::MEDCouplingUMesh& targetMesh,
00157                        const int* fromArray,
00158                        int* toArray);
00159     
00160     void remapIntField2(int inew, int iold, 
00161                         const ParaMEDMEM::MEDCouplingUMesh& sourceMesh,
00162                         const ParaMEDMEM::MEDCouplingUMesh& targetMesh,
00163                         const int* fromArray,
00164                         std::string nameArrayTo);
00165 
00166     void remapDoubleField3(int inew, int iold,
00167                            ParaMEDMEM::DataArrayDouble* fromArray,
00168                            std::string nameArrayTo,
00169                            std::string descriptionField);
00170   private:
00171 
00172     //link to mesh_collection topology
00173     Topology* _topology;
00174     
00175     //control over topology
00176     bool _owns_topology;
00177     
00178     //Driver for read/write operations
00179     MeshCollectionDriver* _driver;
00180     
00181     //Parallelizer - mark of parallel execution mode
00182     ParaDomainSelector* _domain_selector;
00183     
00184     //links to meshes
00185     std::vector<ParaMEDMEM::MEDCouplingUMesh*> _mesh;
00186     std::vector<ParaMEDMEM::MEDCouplingUMesh*> _face_mesh;
00187     
00188     //index of a non empty mesh within _mesh (in parallel mode all of meshes can be empty)
00189     int _i_non_empty_mesh;
00190     
00191     //links to connectzones
00192     std::vector<MEDPARTITIONER::ConnectZone*> _connect_zones;
00193 
00194     //family ids storages
00195     std::vector<ParaMEDMEM::DataArrayInt*> _cell_family_ids;
00196     std::vector<ParaMEDMEM::DataArrayInt*> _face_family_ids;
00197     
00198     //DataArrayInt* storages
00199     std::map<std::string, ParaMEDMEM::DataArrayInt*> _map_dataarray_int;
00200     //DataArrayDouble* storages
00201     std::map<std::string, ParaMEDMEM::DataArrayDouble*> _map_dataarray_double;
00202     
00203     //fields to be partitioned
00204     std::vector<std::string> _field_descriptions;
00205     
00206     //group family conversion
00207     std::map<std::string, int> _family_info;
00208     std::map<std::string, std::vector<std::string> > _group_info;
00209   
00210     //list of groups that are not to be splitted
00211     std::vector<std::string> _indivisible_regions;
00212 
00213     //name of global mesh
00214     std::string _name;
00215 
00216     //description of global mesh
00217     std::string _description;
00218 
00219     //specifies the driver associated to the collection
00220     DriverType _driver_type;
00221 
00222     //flag specifying that the splitter should create boundary constituent entity
00223     //so that they are written in joints
00224     bool _subdomain_boundary_creates;
00225 
00226     //flag specifying that families must be preserved by the splitting
00227     bool _family_splitting;
00228 
00229     //flag specifying that groups must be created on all domains, even if they are empty
00230     bool _create_empty_groups;
00231 
00232     JointFinder* _joint_finder;
00233   };
00234 }
00235 #endif