]> SALOME platform Git repositories - modules/med.git/blob - src/ParaMEDMEM/OverlapMapping.hxx
Salome HOME
58dab05c4b957d86891d11a69ad32a210154922e
[modules/med.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 #include "OverlapElementLocator.hxx"
26
27 #include <vector>
28 #include <map>
29 //#define DEC_DEBUG
30
31 namespace ParaMEDMEM
32 {
33   class ProcessorGroup;
34   class DataArrayInt;
35   class MEDCouplingFieldDouble;
36
37   typedef std::map<int,double> SparseDoubleVec;
38
39   /*!
40    * Internal class, not part of the public API.
41    *
42    * Used by the impl of OverlapInterpolationMatrix, plays an equivalent role than what the NxM_Mapping
43    * does for the InterpolationMatrix.
44    *
45    */
46   class OverlapMapping
47   {
48   public:
49
50     OverlapMapping(const ProcessorGroup& group, const OverlapElementLocator& locator);
51     void keepTracksOfSourceIds(int procId, DataArrayInt *ids);
52     void keepTracksOfTargetIds(int procId, DataArrayInt *ids);
53     void addContributionST(const std::vector< SparseDoubleVec >& matrixST, const DataArrayInt *srcIds, int srcProcId, const DataArrayInt *trgIds, int trgProcId);
54     void prepare(const std::vector< int >& procsToSendField, int nbOfTrgElems);
55     void computeDenoConservativeVolumic(int nbOfTuplesTrg);
56 //    void computeDenoIntegralGlobConstraint();
57 //    void computeDenoIntegral();
58     void computeDenoRevIntegral(const DataArrayDouble & targetAreas);
59     //
60     void multiply(const MEDCouplingFieldDouble *fieldInput, MEDCouplingFieldDouble *fieldOutput, double default_val) const;
61     void transposeMultiply(const MEDCouplingFieldDouble *fieldInput, MEDCouplingFieldDouble *fieldOutput);
62   private:
63 //    void fillProcToSendRcvForMultiply(const std::vector< int >& procsToSendField);
64     void serializeMatrixStep0ST(const int *nbOfElemsSrc, int *&bigArr, int *count, int *offsets,
65                                 int *countForRecv, int *offsetsForRecv) const;
66     int serializeMatrixStep1ST(const int *nbOfElemsSrc, const int *recvStep0, const int *countStep0, const int *offsStep0,
67                                int *&bigArrI, double *&bigArrD, int *count, int *offsets,
68                                int *countForRecv, int *offsForRecv) const;
69     void unserializationST(int nbOfTrgElems, const int *nbOfElemsSrcPerProc, const int *bigArrRecv, const int *bigArrRecvCounts, const int *bigArrRecvOffs,
70                            const int *bigArrRecv2, const double *bigArrDRecv2, const int *bigArrRecv2Count, const int *bigArrRecv2Offs);
71     void finishToFillFinalMatrixST();
72     void updateZipSourceIdsForMultiply();
73
74 #ifdef DEC_DEBUG
75     void printMatrixesST() const;
76     void printTheMatrix() const;
77     void printDenoMatrix() const;
78 #endif
79   private:
80     const ProcessorGroup &_group;
81     const OverlapElementLocator& _locator;
82
83     /**! Vector of DAInt of cell identifiers. The 2 following class members work in pair. For a proc ID i,
84      * first member gives an old2new map for the local part of the source mesh that has been sent to proc#i, just based on the
85      * bounding box computation (this is potentially a larger set than what is finally in the interp matrix).
86      * Second member gives proc ID.  */
87     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _sent_src_ids_st2;
88     //! see above _sent_src_ids_st2
89     std::vector< int > _sent_src_proc_st2;
90
91     //! See _src_ids_st2 and _sent_src_proc_st2. Same for target mesh.
92     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _sent_trg_ids_st2;
93     //! See _src_ids_st2 and _sent_src_proc_st2. Same for target mesh.
94     std::vector< int > _sent_trg_proc_st2;
95
96
97     /**! Vector of matrixes (partial interpolation ratios), result of the LOCAL interpolator run.
98      * Indexing shared with _source_proc_id_st, and _target_proc_id_st.   */
99     std::vector< std::vector< SparseDoubleVec > > _matrixes_st;
100     //! See _matrixes_st - vec of source proc IDs
101     std::vector< int > _source_proc_id_st;
102     //! See _matrixes_st - vec of target proc IDs
103     std::vector< int > _target_proc_id_st;
104
105     /**! Vector of remote proc IDs from which this proc received cell IDs of the source mesh.
106      * Indexing shared with _nb_of_rcv_src_ids_proc_st2 */
107     std::vector< int > _rcv_src_ids_proc_st2;
108     /**! Number of received source mesh IDs at mesh data exchange. See _src_ids_proc_st2 above.
109      Counting the number of IDs suffices, as we just need this to prepare the receive when doing the final vector matrix multiplication */
110     std::vector< int > _nb_of_rcv_src_ids_proc_st2;
111
112     /**! Specifies for each (target) remote proc ID (given in _src_ids_zip_proc_st2 below) the corresponding
113      * source cell IDs to use. Same indexing as _src_ids_zip_proc_st2. Sorted.
114      * On a given proc, and after updateZipSourceIdsForMultiply(), this member contains exactly the same set of source cell IDs as what is given
115      * in the locally held interpolation matrices.
116      * IMPORTANT: as a consequence cell IDs in _src_ids_zip_st2 are *remote* identifiers.   */
117     std::vector< std::vector<int> > _src_ids_zip_st2;
118     //! Vector of remote proc ID to which the local source mapping above corresponds. See _src_ids_zip_st2 above.
119     std::vector< int > _src_ids_zip_proc_st2;
120
121     /**! THE matrix for matrix-vector product. The first dimension is indexed in the set of target procs
122     * that interacts with local source mesh. The second dim is the target cell ID.
123     * Same indexing as _the_matrix_st_source_proc_id  */
124     std::vector< std::vector< SparseDoubleVec > > _the_matrix_st;
125     //! See _the_matrix_st above. List of source proc IDs contributing to _the_matrix_st
126     std::vector< int > _the_matrix_st_source_proc_id;
127
128     //! Proc IDs to which data will be sent (originating this current proc) for matrix-vector computation
129     std::vector< int > _proc_ids_to_send_vector_st;
130     //! Proc IDs from which data will be received (on this current proc) for matrix-vector computation
131     //std::vector< int > _proc_ids_to_recv_vector_st;  // directly equal to _the_matrix_st_source_proc_id
132
133     // Denominators (computed from the numerator matrix). As for _the_matrix_st it is paired with _the_matrix_st_source_proc_id
134     std::vector< std::vector< SparseDoubleVec > > _the_deno_st;
135   };
136 }
137
138 #endif