TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
TRUSTTab_parts.tpp
1/****************************************************************************
2* Copyright (c) 2025, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef TRUSTTab_parts_TPP_included
17#define TRUSTTab_parts_TPP_included
18
19template<typename _TYPE_>
20inline void init_parts(TRUSTVect<_TYPE_>& vect, TRUST_Vector<TRUSTTab<_TYPE_>>& parts, TRUSTTab<_TYPE_> *dummy_type_ptr)
21{
22 const MD_Vector& md = vect.get_md_vector();
23 TRUSTTab<_TYPE_>* tab_ptr = dynamic_cast<TRUSTTab<_TYPE_>*>(&vect);
24 if (! md.non_nul() || !sub_type(MD_Vector_composite, md.valeur()))
25 {
26 // Ce n'est pas un tableau a plusieurs sous-parties, on cree juste une partie qui pointe sur vect.
27 parts.dimensionner(1);
28 TRUSTTab<_TYPE_>& part = parts[0];
29 // On preserve le 'shape' du tableau de depart, si c'est un TRUSTTab<_TYPE_>...
30 if (tab_ptr) part.ref(*tab_ptr);
31 else part.ref(vect);
32 }
33 else
34 {
35 ArrOfInt shape;
36 const int line_size = vect.line_size();
37 if (tab_ptr)
38 {
39 const TRUSTTab<_TYPE_>& tab = *tab_ptr;
40 const int n = tab.nb_dim();
41 shape.resize_array(n);
42 for (int i = 0; i < n; i++) shape[i] = tab.dimension_tot(i);
43 }
44 else
45 {
46 if (line_size == 1)
47 {
48 shape.resize_array(1);
49 shape[0] = vect.size_totale();
50 }
51 else
52 {
53 shape.resize_array(2);
54 shape[0] = vect.size_totale() / line_size;
55 shape[1] = line_size;
56 }
57 }
58
59 const MD_Vector_composite& mdata = ref_cast(MD_Vector_composite, md.valeur());
60 const int n = mdata.nb_parts();
61 parts.dimensionner(n);
62 for (int i = 0, j; i < n; i++)
63 {
64 ArrOfInt shape_i;
65 if (mdata.get_shape(i) == 0)
66 shape_i = shape; //si mdata.shapes_[i] > 0, alors la sous-partie a une dimension mineure en plus
67 else
68 {
69 shape_i.resize(shape.size_array() + 1);
70 shape_i[1] = mdata.get_shape(i);
71 for (j = 1; j < shape.size_array(); j++)
72 shape_i[j + 1] = shape[j];
73 }
74 const int offset = mdata.get_part_offset(i);
75 const MD_Vector& md_part = mdata.get_desc_part(i);
76 shape_i[0] = md_part->get_nb_items_tot();
77 TRUSTTab<_TYPE_>& part = parts[i];
78 // Fait pointer le domaine de memoire sur le sous-tableau (pour l'instant tableau monodimensionnel)
79 part.ref_array(vect, offset * line_size, shape_i[0] * line_size * std::max(mdata.get_shape(i), (int)1)); // int cast necessary for 64b transcription
80 // Change le "shape" du tableau pour mettre le nombre de lignes et de colonnes
81 // (nombre total d'items inchange, donc resize autorise)
82 part.resize(shape_i);
83 // Associe le md_vector
84 part.set_md_vector(md_part);
85 }
86 }
87}
88
89template <typename _TYPE_>
91{
92 init_parts<_TYPE_>(vect, parts_, static_cast<TRUSTTab<_TYPE_>*>(0));
93}
94
95template <typename _TYPE_>
97{
98 reset();
99 init_parts<_TYPE_>(vect, parts_, static_cast<TRUSTTab<_TYPE_>*>(0));
100}
101
102// Pour ConstTRUSTTab_parts, on const_cast pour remplir les ref dans parts_.
103// Pas grave, ensuite les sous parties ne seront accessibles qu'en const de l'exterieur.
104template <typename _TYPE_>
106{
107 TRUSTVect<_TYPE_>& vect2 = const_cast<TRUSTVect<_TYPE_>&>(vect);
108 init_parts<_TYPE_>(vect2, parts_, static_cast<TRUSTTab<_TYPE_>*>(0));
109}
110
111template <typename _TYPE_>
113{
114 reset();
115 TRUSTVect<_TYPE_>& vect2 = const_cast<TRUSTVect<_TYPE_>&>(vect);
116 init_parts<_TYPE_>(vect2, parts_, static_cast<TRUSTTab<_TYPE_>*>(0));
117}
118
119#endif /* TRUSTTab_parts_TPP_included */
void initialize(const TRUSTVect< _TYPE_ > &)
virtual int get_nb_items_tot() const
Metadata for a distributed composite vector.
int get_part_offset(int i) const
int get_shape(int i) const
const MD_Vector & get_desc_part(int i) const
: Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
Definition MD_Vector.h:48
int non_nul() const
Definition MD_Vector.h:56
const MD_Vector_base & valeur() const
Definition MD_Vector.h:77
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void resize(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTArray.h:156
void initialize(TRUSTVect< _TYPE_ > &)
: Tableau a n entrees pour n<= 4.
Definition TRUSTTab.h:31
virtual void ref(const TRUSTTab &)
Definition TRUSTTab.tpp:308
void set_md_vector(const MD_Vector &) override
Definition TRUSTTab.tpp:673
void ref_array(TRUSTArray< _TYPE_, _SIZE_ > &, _SIZE_ start=0, _SIZE_ sz=-1) override
Definition TRUSTTab.tpp:332
int nb_dim() const
Definition TRUSTTab.h:199
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
int line_size() const
Definition TRUSTVect.tpp:67
virtual const MD_Vector & get_md_vector() const
Definition TRUSTVect.h:123
classe TRUST_Vector