Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Vector.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Vector.cc (C) 2000-2014 */
9/* */
10/* Vecteur d'algèbre linéraire. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/Array.h"
17#include "arcane/utils/String.h"
18
19#include "arcane/matvec/Vector.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24ARCANE_BEGIN_NAMESPACE
25namespace MatVec
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
32{
33 public:
34 VectorImpl(Integer size)
35 : m_values(size), m_nb_reference(0)
36 {
37 }
38 VectorImpl(Integer size,Real init_value)
39 : m_values(size,init_value), m_nb_reference(0)
40 {
41 m_values.fill(init_value);
42 }
43 VectorImpl() : m_nb_reference(0)
44 {
45 }
47 : m_values(v), m_nb_reference(0)
48 {
49 }
51 : m_values(rhs.m_values), m_nb_reference()
52 {
53 }
54 private:
55 void operator=(const VectorImpl& rhs);
56 public:
57 Integer size() const { return m_values.size(); }
58 RealArrayView values() { return m_values; }
59 RealConstArrayView values() const { return m_values; }
60 void dump(std::ostream& o) const
61 {
62 Integer size = m_values.size();
63 o << "(Vector ptr=" << this << " size=" << size << ")\n";
64 for( Integer i=0; i<size; ++i )
65 o << "[" << i << "]=" << m_values[i] << '\n';
66 //o << ")";
67 }
68 VectorImpl* clone()
69 {
70 return new VectorImpl(m_values);
71 }
72 void copy(const VectorImpl& rhs)
73 {
74 m_values.copy(rhs.m_values);
75 }
76 Real normInf();
77 static Vector readHypre(const String& file_name);
78 public:
79 void addReference()
80 {
81 ++m_nb_reference;
82 }
83 void removeReference()
84 {
85 --m_nb_reference;
86 if (m_nb_reference==0)
87 delete this;
88 }
89 private:
90 UniqueArray<Real> m_values;
91 Integer m_nb_reference;
92};
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
97Vector::
98Vector(Integer size)
99: m_impl(new VectorImpl(size))
100{
101 m_impl->addReference();
102}
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
108Vector(const Vector& v)
109: m_impl(v.m_impl)
110{
111 m_impl->addReference();
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
118operator=(const Vector& rhs)
119{
120 VectorImpl* vi = rhs.m_impl;
121 vi->addReference();
122 m_impl->removeReference();
123 m_impl = vi;
124 return (*this);
125}
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
131~Vector()
132{
133 m_impl->removeReference();
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139Integer Vector::
140size() const
141{
142 return m_impl->size();
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
149values()
150{
151 return m_impl->values();
152}
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
156
158values() const
159{
160 return m_impl->values();
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
167copy(const Vector& rhs)
168{
169 return m_impl->copy(*rhs.m_impl);
170}
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
176dump(std::ostream& o) const
177{
178 m_impl->dump(o);
179}
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184Real VectorImpl::
185normInf()
186{
187 Real v = 0.0;
188 Integer size = m_values.size();
189 for( Integer i=0; i<size; ++i ){
190 Real v2 = math::abs(m_values[i]);
191 if (v2>v)
192 v = v2;
193 }
194 return v;
195}
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
200Real Vector::
201normInf()
202{
203 return m_impl->normInf();
204}
205
206/*---------------------------------------------------------------------------*/
207/*---------------------------------------------------------------------------*/
208
211{
212 std::ifstream ifile(file_name.localstr());
213 Integer xmin = 0;
214 Integer xmax = 0;
215 ifile >> ws >> xmin >> ws >> xmax;
216 Integer nb = (xmax-xmin)+1;
217 Vector vec(nb);
218 RealArrayView values = vec.values();
219 for( Integer i=0; i<nb; ++i ){
220 Integer column_id = 0;
221 Real v = 0.0;
222 ifile >> ws >> column_id >> ws >> v;
223 values[column_id] = v;
224 }
225 return vec;
226}
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231}
232ARCANE_END_NAMESPACE
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Vecteur d'algèbre linéraire.
void dump(std::ostream &o) const
Imprime les valeurs du vecteur.
Definition Vector.cc:176
static Vector readHypre(const String &file_name)
Initialise un vecteur en utilisant un fichier au format Hypre.
Definition Vector.cc:210
const Vector & operator=(const Vector &rhs)
Change la référence du vecteur.
Definition Vector.cc:118
Integer size() const
Nombre d'éléments du vecteur.
Definition Vector.cc:140
~Vector()
Supprime la référence.
Definition Vector.cc:131
VectorImpl * m_impl
Représentation interne du groupe.
RealArrayView values()
Valeurs du vecteur.
Definition Vector.cc:149
Vector()
Créé un vecteur vide.
void copy(const Vector &rhs)
Copie les éléments de rhs dans ce vecteur.
Definition Vector.cc:167
Integer size() const
Nombre d'éléments du vecteur.
Vue modifiable d'un tableau d'un type T.
Vue constante d'un tableau de type T.
Chaîne de caractères unicode.