Salome HOME
OverlapDEC: bug fix. Bounding box adjustment was negative.
[tools/medcoupling.git] / src / ParaMEDMEM / OverlapMapping.hxx
1 // Copyright (C) 2007-2015  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   typedef std::map<int,double> SparseDoubleVec;
36
37   /*!
38    * Internal class, not part of the public API.
39    *
40    * Used by the impl of OverlapInterpolationMatrix, plays an equivalent role than what the NxM_Mapping
41    * does for the InterpolationMatrix.
42    *
43    */
44   class OverlapMapping
45   {
46   public:
47
48     OverlapMapping(const ProcessorGroup& group);
49     void keepTracksOfSourceIds(int procId, DataArrayInt *ids);
50     void keepTracksOfTargetIds(int procId, DataArrayInt *ids);
51     void addContributionST(const std::vector< SparseDoubleVec >& matrixST, const DataArrayInt *srcIds, int srcProcId, const DataArrayInt *trgIds, int trgProcId);
52     void prepare(const std::vector< int >& procsToSendField, int nbOfTrgElems);
53     void computeDenoConservativeVolumic(int nbOfTuplesTrg);
54     void computeDenoGlobConstraint();
55     //
56     void multiply(const MEDCouplingFieldDouble *fieldInput, MEDCouplingFieldDouble *fieldOutput) const;
57     void transposeMultiply(const MEDCouplingFieldDouble *fieldInput, MEDCouplingFieldDouble *fieldOutput);
58   private:
59     void fillProcToSendRcvForMultiply(const std::vector< int >& procsToSendField);
60     void serializeMatrixStep0ST(const int *nbOfElemsSrc, int *&bigArr, int *count, int *offsets,
61                                 int *countForRecv, int *offsetsForRecv) const;
62     int serializeMatrixStep1ST(const int *nbOfElemsSrc, const int *recvStep0, const int *countStep0, const int *offsStep0,
63                                int *&bigArrI, double *&bigArrD, int *count, int *offsets,
64                                int *countForRecv, int *offsForRecv) const;
65     void unserializationST(int nbOfTrgElems, const int *nbOfElemsSrcPerProc, const int *bigArrRecv, const int *bigArrRecvCounts, const int *bigArrRecvOffs,
66                            const int *bigArrRecv2, const double *bigArrDRecv2, const int *bigArrRecv2Count, const int *bigArrRecv2Offs);
67     void finishToFillFinalMatrixST();
68     void updateZipSourceIdsForFuture();
69
70     // Debug
71 //    void printMatrixesST() const;
72 //    void printTheMatrix() const;
73   private:
74     const ProcessorGroup &_group;
75     /**! Vector of DAInt of cell identifiers. The 2 following class members work in pair. For a proc ID i,
76      * first member gives an old2new map for the local part of the source mesh that has been sent.
77      * Second member gives proc ID.  */
78     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _sent_src_ids_st2;
79     //! see above _sent_src_ids_st2
80     std::vector< int > _sent_src_proc_st2;
81
82     //! See _src_ids_st2 and _sent_src_proc_st2. Same for target mesh.
83     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _sent_trg_ids_st2;
84     //! See _src_ids_st2 and _sent_src_proc_st2. Same for target mesh.
85     std::vector< int > _sent_trg_proc_st2;
86
87
88     /**! Vector of matrixes (partial interpolation ratios), result of the local interpolator run.
89      * Indexing shared with _source_proc_id_st, and _target_proc_id_st.   */
90     std::vector< std::vector< SparseDoubleVec > > _matrixes_st;
91     //! See _matrixes_st - vec of source proc IDs
92     std::vector< int > _source_proc_id_st;
93     //! See _matrixes_st - vec of target proc IDs
94     std::vector< int > _target_proc_id_st;
95
96     //! Vector of remote remote proc IDs for source mesh. Indexing shared with _nb_of_src_ids_proc_st2
97     std::vector< int > _src_ids_proc_st2;
98     //! Number of cells in the mesh/mapping received from the remote proc i for source mesh. See _src_ids_proc_st2 above
99     std::vector< int > _nb_of_src_ids_proc_st2;
100
101     /**! Specifies for each remote proc ID (given in _src_ids_zip_proc_st2 below) the corresponding local
102      * source cell IDs to use/send. Same indexing as _src_ids_zip_proc_st2. Sorted.
103      * On a given proc, those two members contain exactly the same set of cell identifiers as what is given
104      * in the locally held interpolation matrices.   */
105     std::vector< std::vector<int> > _src_ids_zip_st2;
106     //! Vector of remote proc ID to which the local source mapping above corresponds. See _src_ids_zip_st2 above.
107     std::vector< int > _src_ids_zip_proc_st2;
108
109     /**! THE matrix for matrix-vector product. The first dimension is indexed in the set of target procs
110     * that interacts with local source mesh. The second dim is the pseudo id of source proc.
111     * Same indexing as _the_matrix_st_source_proc_id  */
112     std::vector< std::vector< SparseDoubleVec > > _the_matrix_st;
113     //! See _the_matrix_st above. List of source proc IDs contributing to _the_matrix_st
114     std::vector< int > _the_matrix_st_source_proc_id;
115
116     //! Proc IDs to which data will be sent (originating this current proc) for matrix-vector computation
117     std::vector< int > _proc_ids_to_send_vector_st;
118     //! Proc IDs from which data will be received (on this current proc) for matrix-vector computation
119     std::vector< int > _proc_ids_to_recv_vector_st;
120
121     // Denominators (computed from the numerator matrix)
122     std::vector< std::vector< SparseDoubleVec > > _the_deno_st;
123
124 //    std::vector< std::vector<int> > _the_matrix_st_source_ids;
125 //    //! this attribute is of size _group.size(); for each procId in _group _source_ids_to_send_st[procId] contains tupleId to send abroad
126 //    std::vector< std::vector<int> > _source_ids_to_send_st;
127   };
128 }
129
130 #endif