TrioCFD 1.9.9_beta
TrioCFD documentation
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 : This class is an OWN_PTR but the pointed object is shared among multiple
29 *
30 * instances of this class. The pointed object can only be accessed as "const"
31 * and is only accessible through MD_Vector instances. Therefore
32 * there is no way to access it as "non-const" other than with a cast.
33 * The attach() method and the copy constructor attach the pointer to an
34 * existing instance already attached to a pointer.
35 * The attach_detach() method takes ownership of the object pointed to by the OWN_PTR
36 * and detaches the object from the OWN_PTR. This is the only way to "construct" MD_Vector objects
37 * (avoids a copy and ensures that the MD_Vect can no longer be modified
38 * once it has been attached to an MD_Vector).
39 * WARNING: the safety of this method relies
40 * on the fact that the instance pointed to by MD_Vector is accessible nowhere
41 * else but through MD_Vector objects. DO NOT ADD a method
42 * attach(const MD_Vector_base &), as this breaks the class safety!!! (B.Mathieu)
43 * As many methods as possible are inlined to avoid penalising non-distributed arrays,
44 * while avoiding including 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 Copy constructor, attaches the pointer to the same object as the source.
94 */
96{
97 attach(src);
98}
99
100/*! @brief Detaches the pointer from the pointed object.
101 */
102inline void MD_Vector::detach()
103{
104#ifndef LATATOOLS
105 ptr_ = nullptr;
106#endif
107}
108
109/*! @brief Detaches the pointer and attaches to the same object as src.
110 */
111inline void MD_Vector::attach(const MD_Vector& src)
112{
113#ifndef LATATOOLS
114 if (this == &src)
115 return; // otherwise the next line would destroy the pointer?
116 ptr_ = src.ptr_;
117#endif
118}
119
120/*! @brief Same as attach(src).
121 */
123{
124 attach(src);
125 return *this;
126}
127
128#endif
Base class for distributed vectors parallel descriptors.
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
int non_nul() const
Definition MD_Vector.h:56
void copy(const MD_Vector_base &)
Constructs an MD_Vector object by copying an existing object.
Definition MD_Vector.cpp:26
const MD_Vector_base * operator->() const
Definition MD_Vector.h:83
MD_Vector & operator=(const MD_Vector &)
Same as attach(src).
Definition MD_Vector.h:122
const MD_Vector_base & valeur() const
Definition MD_Vector.h:77
void detach()
Detaches the pointer from the pointed object.
Definition MD_Vector.h:102
int operator!=(const MD_Vector &) const
Inverse of ==.
Definition MD_Vector.cpp:50
int operator==(const MD_Vector &) const
Returns 1 if the structures are identical, 0 otherwise.
Definition MD_Vector.cpp:37
void attach(const MD_Vector &)
Detaches the pointer and attaches to the same object as src.
Definition MD_Vector.h:111