1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __OVERLAPMAPPING_HXX__
22 #define __OVERLAPMAPPING_HXX__
24 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
25 #include "OverlapElementLocator.hxx"
34 class MEDCouplingFieldDouble;
36 typedef std::map<int,double> SparseDoubleVec;
39 * Internal class, not part of the public API.
41 * Used by the impl of OverlapInterpolationMatrix, plays an equivalent role than what the NxM_Mapping
42 * does for the InterpolationMatrix.
49 OverlapMapping(const ProcessorGroup& group, const OverlapElementLocator& locator);
50 void keepTracksOfSourceIds(int procId, DataArrayInt *ids);
51 void keepTracksOfTargetIds(int procId, DataArrayInt *ids);
52 void addContributionST(const std::vector< SparseDoubleVec >& matrixST, const DataArrayInt *srcIds, int srcProcId, const DataArrayInt *trgIds, int trgProcId);
53 void prepare(const std::vector< int >& procsToSendField, int nbOfTrgElems);
54 void computeDenoConservativeVolumic(int nbOfTuplesTrg);
55 void computeDenoGlobConstraint();
57 void multiply(const MEDCouplingFieldDouble *fieldInput, MEDCouplingFieldDouble *fieldOutput, double default_val) const;
58 void transposeMultiply(const MEDCouplingFieldDouble *fieldInput, MEDCouplingFieldDouble *fieldOutput);
60 // void fillProcToSendRcvForMultiply(const std::vector< int >& procsToSendField);
61 void serializeMatrixStep0ST(const int *nbOfElemsSrc, int *&bigArr, int *count, int *offsets,
62 int *countForRecv, int *offsetsForRecv) const;
63 int serializeMatrixStep1ST(const int *nbOfElemsSrc, const int *recvStep0, const int *countStep0, const int *offsStep0,
64 int *&bigArrI, double *&bigArrD, int *count, int *offsets,
65 int *countForRecv, int *offsForRecv) const;
66 void unserializationST(int nbOfTrgElems, const int *nbOfElemsSrcPerProc, const int *bigArrRecv, const int *bigArrRecvCounts, const int *bigArrRecvOffs,
67 const int *bigArrRecv2, const double *bigArrDRecv2, const int *bigArrRecv2Count, const int *bigArrRecv2Offs);
68 void finishToFillFinalMatrixST();
69 void updateZipSourceIdsForMultiply();
72 void printMatrixesST() const;
73 void printTheMatrix() const;
74 void printDenoMatrix() const;
77 const ProcessorGroup &_group;
78 const OverlapElementLocator& _locator;
80 /**! Vector of DAInt of cell identifiers. The 2 following class members work in pair. For a proc ID i,
81 * 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
82 * bounding box computation (this is potentially a larger set than what is finally in the interp matrix).
83 * Second member gives proc ID. */
84 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _sent_src_ids_st2;
85 //! see above _sent_src_ids_st2
86 std::vector< int > _sent_src_proc_st2;
88 //! See _src_ids_st2 and _sent_src_proc_st2. Same for target mesh.
89 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _sent_trg_ids_st2;
90 //! See _src_ids_st2 and _sent_src_proc_st2. Same for target mesh.
91 std::vector< int > _sent_trg_proc_st2;
94 /**! Vector of matrixes (partial interpolation ratios), result of the LOCAL interpolator run.
95 * Indexing shared with _source_proc_id_st, and _target_proc_id_st. */
96 std::vector< std::vector< SparseDoubleVec > > _matrixes_st;
97 //! See _matrixes_st - vec of source proc IDs
98 std::vector< int > _source_proc_id_st;
99 //! See _matrixes_st - vec of target proc IDs
100 std::vector< int > _target_proc_id_st;
102 /**! Vector of remote proc IDs from which this proc received cell IDs of the source mesh.
103 * Indexing shared with _nb_of_rcv_src_ids_proc_st2 */
104 std::vector< int > _rcv_src_ids_proc_st2;
105 /**! Number of received source mesh IDs at mesh data exchange. See _src_ids_proc_st2 above.
106 Counting the number of IDs suffices, as we just need this to prepare the receive when doing the final vector matrix multiplication */
107 std::vector< int > _nb_of_rcv_src_ids_proc_st2;
109 /**! Specifies for each (target) remote proc ID (given in _src_ids_zip_proc_st2 below) the corresponding
110 * source cell IDs to use. Same indexing as _src_ids_zip_proc_st2. Sorted.
111 * On a given proc, and after updateZipSourceIdsForMultiply(), this member contains exactly the same set of source cell IDs as what is given
112 * in the locally held interpolation matrices.
113 * IMPORTANT: as a consequence cell IDs in _src_ids_zip_st2 are *remote* identifiers. */
114 std::vector< std::vector<int> > _src_ids_zip_st2;
115 //! Vector of remote proc ID to which the local source mapping above corresponds. See _src_ids_zip_st2 above.
116 std::vector< int > _src_ids_zip_proc_st2;
118 /**! THE matrix for matrix-vector product. The first dimension is indexed in the set of target procs
119 * that interacts with local source mesh. The second dim is the target cell ID.
120 * Same indexing as _the_matrix_st_source_proc_id */
121 std::vector< std::vector< SparseDoubleVec > > _the_matrix_st;
122 //! See _the_matrix_st above. List of source proc IDs contributing to _the_matrix_st
123 std::vector< int > _the_matrix_st_source_proc_id;
125 //! Proc IDs to which data will be sent (originating this current proc) for matrix-vector computation
126 std::vector< int > _proc_ids_to_send_vector_st;
127 //! Proc IDs from which data will be received (on this current proc) for matrix-vector computation
128 std::vector< int > _proc_ids_to_recv_vector_st;
130 // Denominators (computed from the numerator matrix). As for _the_matrix_st it is paired with _the_matrix_st_source_proc_id
131 std::vector< std::vector< SparseDoubleVec > > _the_deno_st;