Salome HOME
[ParaMEDMEM] Adding SWIG interface for OverlapDEC + py tests of DEC
[tools/medcoupling.git] / src / ParaMEDMEM / BlockTopology.hxx
1 // Copyright (C) 2007-2020  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, or (at your option) any later version.
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
20 #ifndef __BLOCKTOPOLOGY_HXX__
21 #define __BLOCKTOPOLOGY_HXX__
22
23 #include "Topology.hxx"
24 #include "ProcessorGroup.hxx"
25
26 #include <vector>
27
28 namespace MEDCoupling
29 {
30   class ComponentTopology;
31   class MEDCouplingCMesh;
32
33   typedef enum{Block,Cycle} CYCLE_TYPE; 
34
35   /*!
36    * \anchor BlockTopology-det
37    *
38    * A BlockTopology typically represents the split of a *structured* mesh among the processors of
39    * a common ProcessorGroup. Each processor gets a contiguous part of the cells in the mesh (a block).
40    *
41    * A BlockTopology can also be used to split a structured domain among the various components of a field.
42    *
43    * \sa ExplicitTopology
44    */
45   class BlockTopology : public Topology
46   {
47   public:
48     BlockTopology();
49     BlockTopology(const ProcessorGroup& group, MEDCouplingCMesh *grid); 
50     BlockTopology(const BlockTopology& geom_topo, const ComponentTopology& comp_topo);
51     BlockTopology(const ProcessorGroup& group, mcIdType nb_elem);
52     virtual ~BlockTopology();
53     void release();
54
55     //!Retrieves the number of elements for a given topology
56     mcIdType getNbElements()const { return _nb_elems; }
57     mcIdType getNbLocalElements() const;
58     const ProcessorGroup* getProcGroup()const { return _proc_group; }
59     std::pair<int,mcIdType> globalToLocal (const mcIdType) const ;
60     mcIdType localToGlobal (const std::pair<int,mcIdType>) const;
61     std::vector<std::pair<int,mcIdType> > getLocalArrayMinMax() const ;
62     int getDimension() const { return _dimension; }
63     void serialize(mcIdType* & serializer, mcIdType& size) const ;
64     void unserialize(const mcIdType* serializer, const CommInterface& comm_interface);
65   private:
66     //dimension : 2 or 3
67     int _dimension;
68     //proc array
69     std::vector<int> _nb_procs_per_dim;
70     //stores the offsets vector  
71     std::vector<std::vector<mcIdType> > _local_array_indices;
72     //stores the cycle type (block or cyclic)
73     std::vector<CYCLE_TYPE> _cycle_type;
74     //Processor group
75     const ProcessorGroup* _proc_group;
76     //nb of elements
77     mcIdType _nb_elems;
78     bool _owns_processor_group;
79   };
80 }
81
82 #endif