TrioCFD 1.9.9_beta
TrioCFD documentation
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 Computes "resu += MATRICE * x" and a dot product (this is a building block for the conjugate gradient, see class Solv_GCP)
18 *
19 * Return value:
20 * local contribution of this processor to "(MATRICE * x) dot x"
21 * (note: the dot product counts all rows of the matrix;
22 * shared items are not removed!)
23 * (note: this is different from resu dot 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 // The first index of tab1_ we care about is the second element of the array
33 // (the first element is always 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; // offset by 1 because we index with Fortran indices
40 double *resu_ptr = resu.addr() - 1; // same
41 int n = 1; // index of the current coefficient in tab2 and coeff
42
43 double prod_scal_local = 0;
44
45 for (int i = 0; i < nb_lignes; i++)
46 {
47 // Row index in the matrix:
48 const int i_ligne = *(tab_lignes++);
49 assert(i_ligne >= 1 && i_ligne <= resu.size_array());
50 double r = 0.;
51 // End index of the coefficients for this row in tab2 and 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 // note: we only want to compute the dot product between x and the part added to resu
63 // (not with the existing values of resu before the call)
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
Computes "resu += MATRICE * x" and a dot product (this is a building block for the conjugate gradient...
_SIZE_ size_array() const
_TYPE_ * addr()
_SIZE_ size() const
Definition TRUSTVect.tpp:45