TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Matrice_SuperMorse.cpp
1/****************************************************************************
2* Copyright (c) 2026, 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#include <Matrice_SuperMorse.h>
16
17/*! @brief Calcul de "resu += MATRICE * x" et d'un produit scalaire (c'est une brique de base pour le gradient conjugue, voir class Solv_GCP)
18 *
19 * Valeur de retour:
20 * partie locale a ce processeur de "(MATRICE * x) scalaire x"
21 * (attention: le produit scalaire compte toutes les lignes de la matrice
22 * les items communs ne sont pas supprimes !)
23 * (attention: c'est different de resu scalaire x !)
24 *
25 */
26double Matrice_SuperMorse::ajouter_mult_vect_et_prodscal(const DoubleVect& x, DoubleVect& resu) const
27{
28 assert(resu.size() == x.size());
29
30 const int nb_lignes = lignes_non_vides_.size_array();
31 const int *tab_lignes = lignes_non_vides_.addr();
32 // Le premier indice de tab1_ qui va nous interesser est le deuxieme du tableau
33 // (le premier du tableau est forcement 1)
34 assert(tab1_[0] == 1);
35 const auto *tab1_ptr = tab1_.addr() + 1;
36 assert(tab1_.size_array() == nb_lignes + 1);
37 const int *tab2_ptr = tab2_.addr();
38 const double *coeff_ptr = coeff_.addr();
39 const double *x_ptr = x.addr() - 1; // decalage de 1 car on va indexer par des indices fortran
40 double *resu_ptr = resu.addr() - 1; // idem
41 int n = 1; // indice du coeff courant dans tab2 et coeff
42
43 double prod_scal_local = 0;
44
45 for (int i = 0; i < nb_lignes; i++)
46 {
47 // Numero de la ligne de la matrice:
48 const int i_ligne = *(tab_lignes++);
49 assert(i_ligne >= 1 && i_ligne <= resu.size_array());
50 double r = 0.;
51 // Indice de fin des coeffs de cette ligne dans tab2 et coeff
52 const auto n_fin = *(tab1_ptr++);
53 for (; n < n_fin; n++)
54 {
55 const int colonne = *(tab2_ptr++);
56 assert(colonne >= 1 && colonne <= x.size_array());
57 const double coef = *(coeff_ptr++);
58 const double xb = x_ptr[colonne];
59 r += coef * xb;
60 }
61 resu_ptr[i_ligne] += r;
62 // attention: on ne veut calculer que le produit scalaire entre x et la partie ajoutee a resu
63 // (pas avec les valeurs existantes de resu avant l'appel)
64 prod_scal_local += r * x_ptr[i_ligne];
65 }
66 return prod_scal_local;
67}
double ajouter_mult_vect_et_prodscal(const DoubleVect &x, DoubleVect &resu) const
Calcul de "resu += MATRICE * x" et d'un produit scalaire (c'est une brique de base pour le gradient c...
_SIZE_ size_array() const
_TYPE_ * addr()
_SIZE_ size() const
Definition TRUSTVect.tpp:45