Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
LinearAlgebra.h
Go to the documentation of this file.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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//-----------------------------------------------------------------------------
11#pragma once
12
13#include <alien/utils/Precomp.h>
14
15#include <memory>
16#include <string>
17
18#include <alien/core/backend/BackEnd.h>
19#include <alien/core/backend/IInternalLinearAlgebraT.h>
20
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Alien
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32class Space;
33class IVector;
34class IMatrix;
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
48template <class Tag, class TagV = Tag>
50{
51 public:
60 template <typename... T>
61 LinearAlgebra(T... args)
62 : m_algebra(AlgebraTraits<Tag>::algebra_factory(args...))
63 {}
64
66 virtual ~LinearAlgebra();
67
73 Real norm0(const IVector& x) const;
74
80 Real norm1(const IVector& x) const;
81
87 Real norm2(const IVector& x) const;
88
94 Real normInf(const IVector& x) const;
95
105 void mult(const IMatrix& a, const IVector& x, IVector& r) const;
106
117 void axpy(Real alpha, const IVector& x, IVector& y) const;
118
128 void aypx(Real alpha, IVector& y, const IVector& x) const;
129
136 void copy(const IVector& x, IVector& r) const;
137
144 Real dot(const IVector& x, const IVector& y) const;
145
151 void scal(Real alpha, IVector& x) const;
152
158 void diagonal(const IMatrix& a, IVector& x) const;
159
164 void reciprocal(IVector& x) const;
165
173 void pointwiseMult(const IVector& x, const IVector& y, IVector& w) const;
174
184 void mult(const IMatrix& a, const UniqueArray<Real>& x, UniqueArray<Real>& r) const;
185
196 void axpy(const Real& alpha, const UniqueArray<Real>& x, UniqueArray<Real>& r) const;
197
207 void aypx(Real alpha, UniqueArray<Real>& y, const UniqueArray<Real>& x) const;
208
215 void copy(const UniqueArray<Real>& x, UniqueArray<Real>& r) const;
216
224 Real dot(
225 Integer local_size, const UniqueArray<Real>& x, const UniqueArray<Real>& y) const;
226
232 void scal(Real alpha, UniqueArray<Real>& x) const;
233
239 void dump(IMatrix const& a, std::string const& filename) const;
240
246 void dump(IVector const& x, std::string const& filename) const;
247
248 private:
252 std::unique_ptr<KernelAlgebra> m_algebra;
253};
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258} // namespace Alien
259
260/*---------------------------------------------------------------------------*/
261/*---------------------------------------------------------------------------*/
ILinearAlgebra.h.
Interface for linear algebra.
Interface for all matrices.
Definition IMatrix.h:51
Interface for all vectors.
Definition IVector.h:51
void mult(const IMatrix &a, const UniqueArray< Real > &x, UniqueArray< Real > &r) const
Compute a matrix vector product.
virtual ~LinearAlgebra()
Free resources.
void copy(const UniqueArray< Real > &x, UniqueArray< Real > &r) const
Copy a vector in another one.
void dump(IVector const &x, std::string const &filename) const
Dumps a vector to a file.
Real normInf(const IVector &x) const
Compute LInf norm of a vector.
LinearAlgebra(T... args)
Creates a linear algebra.
void reciprocal(IVector &x) const
Compute the reciprocal of a vector.
Real norm2(const IVector &x) const
Compute L2 norm of a vector.
void scal(Real alpha, IVector &x) const
Scale a vector by a factor.
void axpy(const Real &alpha, const UniqueArray< Real > &x, UniqueArray< Real > &r) const
Scale a vector by a factor and adds the result to another vector.
void aypx(Real alpha, UniqueArray< Real > &y, const UniqueArray< Real > &x) const
Scale a vector by a factor and adds the result to another vector.
void diagonal(const IMatrix &a, IVector &x) const
Extract the diagonal of a matrix in a vector.
AlgebraTraits< Tag >::algebra_type KernelAlgebra
The type of the linear algebra.
Real dot(const IVector &x, const IVector &y) const
Compute the dot product of two vectors.
void axpy(Real alpha, const IVector &x, IVector &y) const
Scale a vector by a factor and adds the result to another vector.
void scal(Real alpha, UniqueArray< Real > &x) const
Scale a vector by a factor.
void copy(const IVector &x, IVector &r) const
Copy a vector in another one.
Real norm1(const IVector &x) const
Compute L1 norm of a vector.
std::unique_ptr< KernelAlgebra > m_algebra
Real dot(Integer local_size, const UniqueArray< Real > &x, const UniqueArray< Real > &y) const
Compute the dot product of two vectors.
void dump(IMatrix const &a, std::string const &filename) const
Dumps a matrix to a file.
Real norm0(const IVector &x) const
Compute L0 norm of a vector.
void mult(const IMatrix &a, const IVector &x, IVector &r) const
Compute a matrix vector product.
void pointwiseMult(const IVector &x, const IVector &y, IVector &w) const
Compute the point wise multiplication of two vectors and store the result in another one.
void aypx(Real alpha, IVector &y, const IVector &x) const
Scale a vector by a factor and adds the result to another vector.
Implementation of an algebraic space.
Definition Space.h:47
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17