TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
MD_Vector.h
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#ifndef MD_Vector_included
16#define MD_Vector_included
17
18#include <MD_Vector_base.h>
19#include <memory>
20
21// Options for arithmetic operations on vectors (mp_min_vect_local, apply_operator, etc...)
22// VECT_SEQUENTIAL_ITEMS: compute requested operation only on sequential items (real items that are not received from another processor)
23// (this is generally slower than VECT_REAL_ITEMS)
24// VECT_REAL_ITEMS: compute requested operation on real items if size_reelle_ok(), otherwise on all items
25// VECT_ALL_ITEMS: compute requested operation on all items (this is equivalent to a call to the Array class operator)
26enum Mp_vect_options { VECT_SEQUENTIAL_ITEMS, VECT_REAL_ITEMS, VECT_ALL_ITEMS };
27
28/*! @brief : Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
29 *
30 * instances de cette classe. L'objet pointe ne peut etre accede qu'en "const"
31 * et n'est accessible que par des instances de MD_Vector. Donc
32 * il n'existe pas de moyen d'y acceder en "non const" autrement qu'avec un cast.
33 * La methode attach() et le constructeur par copie rattachent le pointeur a une
34 * instance existante deja attachee a un pointeur.
35 * La methode attach_detach() s'approprie l'objet pointe par le OWN_PTR et detache
36 * l'objet du OWN_PTR. C'est la seule facon de "construire" les objets MD_Vector
37 * (evite une copie, et permet d'assurer que le MD_Vect ne peut plus etre modifie
38 * une fois que qu'il a ete attache a un MD_Vector)
39 * ATTENTION: la securite de la methode repose
40 * sur le fait que l'instance pointee par MD_Vector n'est accessible nulle part
41 * ailleurs que par des objets MD_Vector. NE PAS AJOUTER de methode
42 * attach(const MD_Vector_base &), cela casse la securite de la classe !!! (B.Mathieu)
43 * inline d'un maximum de methodes pour ne pas penaliser les tableaux non distribues,
44 * tout en evitant d'inclure MD_Vector_base.h
45 *
46 */
48{
49public:
51 inline MD_Vector(const MD_Vector&);
52 inline MD_Vector& operator=(const MD_Vector&);
53 inline void attach(const MD_Vector&);
54 inline void detach();
55
56 int non_nul() const
57 {
58#ifndef LATATOOLS
59 return (ptr_ != 0);
60#else
61 return 0;
62#endif
63 }
64
65 explicit operator bool() const noexcept
66 {
67#ifndef LATATOOLS
68 return (ptr_ != nullptr);
69#else
70 return false;
71#endif
72 }
73
74#ifndef LATATOOLS
75 void copy(const MD_Vector_base&);
76
77 const MD_Vector_base& valeur() const
78 {
79 assert(ptr_);
80 return *ptr_;
81 }
82
83 inline const MD_Vector_base* operator ->() const { assert(ptr_); return ptr_.get(); }
84
85 int operator==(const MD_Vector&) const;
86 int operator!=(const MD_Vector&) const;
87
88private:
89 std::shared_ptr<MD_Vector_base> ptr_;
90#endif
91};
92
93/*! @brief constructeur par copie, associe le pointeur au meme objet que la source
94 */
96{
97 attach(src);
98}
99
100/*! @brief Detache le pointeur de l'objet pointe
101 */
102inline void MD_Vector::detach()
103{
104#ifndef LATATOOLS
105 ptr_ = nullptr;
106#endif
107}
108
109/*! @brief Detache le pointeur et attache au meme objet que src.
110 */
111inline void MD_Vector::attach(const MD_Vector& src)
112{
113#ifndef LATATOOLS
114 if (this == &src)
115 return; // sinon ligne suivante detruit le pointeur ?
116 ptr_ = src.ptr_;
117#endif
118}
119
120/*! @brief idem que attach(src)
121 */
123{
124 attach(src);
125 return *this;
126}
127
128#endif
Base class for distributed vectors parallel descriptors.
: 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
void copy(const MD_Vector_base &)
construction d'un objet MD_Vector par copie d'un objet existant.
Definition MD_Vector.cpp:26
const MD_Vector_base * operator->() const
Definition MD_Vector.h:83
MD_Vector & operator=(const MD_Vector &)
idem que attach(src)
Definition MD_Vector.h:122
const MD_Vector_base & valeur() const
Definition MD_Vector.h:77
void detach()
Detache le pointeur de l'objet pointe.
Definition MD_Vector.h:102
int operator!=(const MD_Vector &) const
reponse inverse de == ...
Definition MD_Vector.cpp:50
int operator==(const MD_Vector &) const
renvoie 1 si les structures sont identiques, 0 sinon
Definition MD_Vector.cpp:37
void attach(const MD_Vector &)
Detache le pointeur et attache au meme objet que src.
Definition MD_Vector.h:111