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