Salome HOME
f5ef3ce90b75961cc8d60fdcb04bac09b0180009
[tools/medcoupling.git] / src / ParaMEDMEM / OverlapMapping.hxx
1 // Copyright (C) 2007-2014  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 // Author : Anthony Geay (CEA/DEN)
20
21 #ifndef __OVERLAPMAPPING_HXX__
22 #define __OVERLAPMAPPING_HXX__
23
24 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
25
26 #include <vector>
27 #include <map>
28
29 namespace ParaMEDMEM
30 {
31   class ProcessorGroup;
32   class DataArrayInt;
33   class MEDCouplingFieldDouble;
34
35   class OverlapMapping
36   {
37   public:
38     OverlapMapping(const ProcessorGroup& group);
39     void keepTracksOfSourceIds(int procId, DataArrayInt *ids);
40     void keepTracksOfTargetIds(int procId, DataArrayInt *ids);
41     void addContributionST(const std::vector< std::map<int,double> >& matrixST, const DataArrayInt *srcIds, int srcProcId, const DataArrayInt *trgIds, int trgProcId);
42     void prepare(const std::vector< std::vector<int> >& procsInInteraction, int nbOfTrgElems);
43     void computeDenoConservativeVolumic(int nbOfTuplesTrg);
44     void computeDenoGlobConstraint();
45     //
46     void multiply(const MEDCouplingFieldDouble *fieldInput, MEDCouplingFieldDouble *fieldOutput) const;
47     void transposeMultiply(const MEDCouplingFieldDouble *fieldInput, MEDCouplingFieldDouble *fieldOutput);
48   private:
49     void serializeMatrixStep0ST(const int *nbOfElemsSrc, int *&bigArr, int *count, int *offsets,
50                                 int *countForRecv, int *offsetsForRecv) const;
51     int serializeMatrixStep1ST(const int *nbOfElemsSrc, const int *recvStep0, const int *countStep0, const int *offsStep0,
52                                int *&bigArrI, double *&bigArrD, int *count, int *offsets,
53                                int *countForRecv, int *offsForRecv) const;
54     void unserializationST(int nbOfTrgElems, const int *nbOfElemsSrcPerProc, const int *bigArrRecv, const int *bigArrRecvCounts, const int *bigArrRecvOffs,
55                            const int *bigArrRecv2, const double *bigArrDRecv2, const int *bigArrRecv2Count, const int *bigArrRecv2Offs);
56     void finishToFillFinalMatrixST();
57     void prepareIdsToSendST();
58     void updateZipSourceIdsForFuture();
59     //void printTheMatrix() const;
60   private:
61     const ProcessorGroup &_group;
62     //! vector of ids
63     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _src_ids_st2;//item #1
64     std::vector< int > _src_proc_st2;//item #1
65     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _trg_ids_st2;//item #0
66     std::vector< int > _trg_proc_st2;//item #0
67     std::vector< int > _nb_of_src_ids_proc_st2;//item #1
68     std::vector< int > _src_ids_proc_st2;//item #1
69     std::vector< std::vector<int> > _src_ids_zip_st2;//same size as _src_ids_zip_proc_st2. Sorted. specifies for each id the corresponding ids to send. This is for item0 of Step2 of main algorithm
70     std::vector< int > _src_ids_zip_proc_st2;
71     //! vector of matrixes the first entry correspond to source proc id in _source_ids_st
72     std::vector< std::vector< std::map<int,double> > > _matrixes_st;
73     std::vector< std::vector<int> > _source_ids_st;
74     std::vector< int > _source_proc_id_st;
75     std::vector< std::vector<int> > _target_ids_st;
76     std::vector< int > _target_proc_id_st;
77     //! the matrix for matrix-vector product. The first dimension the set of target procs that interacts with local source mesh. The second dimension correspond to nb of local source ids. 
78     std::vector< std::vector< std::map<int,double> > > _the_matrix_st;
79     std::vector< int > _the_matrix_st_source_proc_id;
80     std::vector< std::vector<int> > _the_matrix_st_source_ids;
81     std::vector< std::vector< std::map<int,double> > > _the_deno_st;
82     //! this attribute stores the proc ids that wait for data from this proc ids for matrix-vector computation
83     std::vector< int > _proc_ids_to_send_vector_st;
84     std::vector< int > _proc_ids_to_recv_vector_st;
85     //! this attribute is of size _group.size(); for each procId in _group _source_ids_to_send_st[procId] contains tupleId to send abroad
86     std::vector< std::vector<int> > _source_ids_to_send_st;
87   };
88 }
89
90 #endif