Loading...
Searching...
No Matches
TpetraVector.h
// Copyright (C) 2014
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef __TPETRA_VECTOR_H
#define __TPETRA_VECTOR_H
#ifdef HAS_TRILINOS
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <Teuchos_GlobalMPISession.hpp>
#include <Teuchos_oblackholestream.hpp>
#include <Tpetra_DefaultPlatform.hpp>
#include <Tpetra_MultiVector.hpp>
#include <Tpetra_Version.hpp>
#include <dolfin/common/types.h>
#include "GenericVector.h"
namespace dolfin
{
template<typename T> class Array;
class TpetraVector : public GenericVector
{
public:
typedef Tpetra::MultiVector<>::node_type node_type;
typedef Tpetra::Map<int, dolfin::la_index, node_type> map_type;
typedef Tpetra::MultiVector<double, int, dolfin::la_index, node_type>
vector_type;
TpetraVector(MPI_Comm comm=MPI_COMM_WORLD);
TpetraVector(MPI_Comm comm, std::size_t N);
TpetraVector(const TpetraVector& x);
//explicit TpetraVector(Teuchos::RCP<vector_type> x);
virtual ~TpetraVector();
//--- Implementation of the GenericTensor interface ---
virtual void zero();
virtual void apply(std::string mode);
virtual MPI_Comm mpi_comm() const;
virtual std::string str(bool verbose) const;
//--- Implementation of the GenericVector interface ---
virtual std::shared_ptr<GenericVector> copy() const;
virtual void init(std::size_t N);
virtual void init(std::pair<std::size_t, std::size_t> range);
virtual void init(std::pair<std::size_t, std::size_t> range,
const std::vector<std::size_t>& local_to_global_map,
const std::vector<la_index>& ghost_indices);
// Bring init function from GenericVector into scope
using GenericVector::init;
virtual bool empty() const;
virtual std::size_t size() const;
virtual std::size_t local_size() const;
virtual std::pair<std::int64_t, std::int64_t> local_range() const;
virtual bool owns_index(std::size_t i) const;
virtual void get(double* block, std::size_t m,
const dolfin::la_index* rows) const;
virtual void get_local(double* block, std::size_t m,
const dolfin::la_index* rows) const;
virtual void set(const double* block, std::size_t m,
const dolfin::la_index* rows);
virtual void set_local(const double* block, std::size_t m,
const dolfin::la_index* rows);
virtual void add(const double* block, std::size_t m,
const dolfin::la_index* rows);
virtual void add_local(const double* block, std::size_t m,
const dolfin::la_index* rows);
virtual void get_local(std::vector<double>& values) const;
virtual void set_local(const std::vector<double>& values);
virtual void add_local(const Array<double>& values);
virtual void gather(GenericVector& y,
const std::vector<dolfin::la_index>& indices) const;
virtual void gather(std::vector<double>& x,
const std::vector<dolfin::la_index>& indices) const;
virtual void gather_on_zero(std::vector<double>& x) const;
virtual void axpy(double a, const GenericVector& x);
virtual void abs();
virtual double inner(const GenericVector& v) const;
virtual double norm(std::string norm_type) const;
virtual double min() const;
virtual double max() const;
virtual double sum() const;
virtual double sum(const Array<std::size_t>& rows) const;
virtual const TpetraVector& operator*= (double a);
virtual const TpetraVector& operator*= (const GenericVector& x);
virtual const TpetraVector& operator/= (double a);
virtual const TpetraVector& operator+= (const GenericVector& x);
virtual const TpetraVector& operator+= (double a);
virtual const TpetraVector& operator-= (const GenericVector& x);
virtual const TpetraVector& operator-= (double a);
virtual const GenericVector& operator= (const GenericVector& x);
virtual const TpetraVector& operator= (double a);
virtual void update_ghost_values();
//--- Special functions ---
virtual GenericLinearAlgebraFactory& factory() const;
//--- Special Tpetra functions ---
Teuchos::RCP<vector_type> vec() const;
const TpetraVector& operator= (const TpetraVector& x);
static void mapdump(Teuchos::RCP<const map_type> xmap,
const std::string desc);
void mapdump(const std::string desc);
friend class TpetraMatrix;
private:
// Initialise Tpetra vector
void _init(std::pair<std::int64_t, std::int64_t> range,
const std::vector<dolfin::la_index>& local_to_global);
// Tpetra multivector - actually a view into the ghosted vector,
// below
Teuchos::RCP<vector_type> _x;
// Tpetra multivector with extra rows for ghost values
Teuchos::RCP<vector_type> _x_ghosted;
// MPI Communicator
Teuchos::RCP<const Teuchos::MpiComm<int>> _comm;
};
}
#endif
#endif
dolfin::Array
Definition Array.h:42
dolfin::GenericLinearAlgebraFactory
Base class for LinearAlgebra factories.
Definition GenericLinearAlgebraFactory.h:47
dolfin::GenericVector
This class defines a common interface for vectors.
Definition GenericVector.h:48
dolfin::GenericVector::init
virtual void init(const TensorLayout &tensor_layout)
Definition GenericVector.h:58
dolfin::TpetraVector::mapdump
static void mapdump(Teuchos::RCP< const map_type > xmap, const std::string desc)
output map for debugging
Definition TpetraVector.cpp:688
dolfin::TpetraVector::mpi_comm
virtual MPI_Comm mpi_comm() const
Return MPI communicator.
Definition TpetraVector.cpp:117
dolfin::TpetraVector::local_size
virtual std::size_t local_size() const
Return local size of vector.
Definition TpetraVector.cpp:184
dolfin::TpetraVector::operator+=
virtual const TpetraVector & operator+=(const GenericVector &x)
Add given vector.
Definition TpetraVector.cpp:557
dolfin::TpetraVector::init
virtual void init(std::size_t N)
Initialize vector to global size N.
Definition TpetraVector.cpp:148
dolfin::TpetraVector::abs
virtual void abs()
Replace all entries in the vector by their absolute values.
Definition TpetraVector.cpp:438
dolfin::TpetraVector::apply
virtual void apply(std::string mode)
Finalize assembly of tensor.
Definition TpetraVector.cpp:79
dolfin::TpetraVector::owns_index
virtual bool owns_index(std::size_t i) const
Determine whether global vector index is owned by this process.
Definition TpetraVector.cpp:199
dolfin::TpetraVector::str
virtual std::string str(bool verbose) const
Return informal string representation (pretty-print).
Definition TpetraVector.cpp:129
dolfin::TpetraVector::~TpetraVector
virtual ~TpetraVector()
Create vector wrapper of Tpetra Vec pointer.
Definition TpetraVector.cpp:68
dolfin::TpetraVector::min
virtual double min() const
Return minimum value of vector.
Definition TpetraVector.cpp:476
dolfin::TpetraVector::zero
virtual void zero()
Set all entries to zero and keep any sparse structure.
Definition TpetraVector.cpp:73
dolfin::TpetraVector::update_ghost_values
virtual void update_ghost_values()
Update ghost values in vector.
Definition TpetraVector.cpp:225
dolfin::TpetraVector::gather_on_zero
virtual void gather_on_zero(std::vector< double > &x) const
Definition TpetraVector.cpp:407
dolfin::TpetraVector::max
virtual double max() const
Return maximum value of vector.
Definition TpetraVector.cpp:485
dolfin::TpetraVector::operator-=
virtual const TpetraVector & operator-=(const GenericVector &x)
Subtract given vector.
Definition TpetraVector.cpp:574
dolfin::TpetraVector::add_local
virtual void add_local(const double *block, std::size_t m, const dolfin::la_index *rows)
Add block of values using local indices.
Definition TpetraVector.cpp:309
dolfin::TpetraVector::set
virtual void set(const double *block, std::size_t m, const dolfin::la_index *rows)
Set block of values using global indices.
Definition TpetraVector.cpp:264
dolfin::TpetraVector::size
virtual std::size_t size() const
Return size of vector.
Definition TpetraVector.cpp:176
dolfin::TpetraVector::empty
virtual bool empty() const
Return true if vector is empty.
Definition TpetraVector.cpp:171
dolfin::TpetraVector::axpy
virtual void axpy(double a, const GenericVector &x)
Add multiple of given vector (AXPY operation).
Definition TpetraVector.cpp:430
dolfin::TpetraVector::local_range
virtual std::pair< std::int64_t, std::int64_t > local_range() const
Return ownership range of a vector.
Definition TpetraVector.cpp:192
dolfin::TpetraVector::gather
virtual void gather(GenericVector &y, const std::vector< dolfin::la_index > &indices) const
Definition TpetraVector.cpp:369
dolfin::TpetraVector::vector_type
Tpetra::MultiVector< double, int, dolfin::la_index, node_type > vector_type
TpetraVector vector type (scalar, local index, global index, node).
Definition TpetraVector.h:63
dolfin::TpetraVector::TpetraVector
TpetraVector(MPI_Comm comm=MPI_COMM_WORLD)
Create empty vector.
Definition TpetraVector.cpp:37
dolfin::TpetraVector::set_local
virtual void set_local(const double *block, std::size_t m, const dolfin::la_index *rows)
Set block of values using local indices.
Definition TpetraVector.cpp:280
dolfin::TpetraVector::operator=
virtual const GenericVector & operator=(const GenericVector &x)
Assignment operator.
Definition TpetraVector.cpp:588
dolfin::TpetraVector::factory
virtual GenericLinearAlgebraFactory & factory() const
Return linear algebra backend factory.
Definition TpetraVector.cpp:634
dolfin::TpetraVector::operator/=
virtual const TpetraVector & operator/=(double a)
Divide vector by given number.
Definition TpetraVector.cpp:548
dolfin::TpetraVector::add
virtual void add(const double *block, std::size_t m, const dolfin::la_index *rows)
Add block of values using global indices.
Definition TpetraVector.cpp:293
dolfin::TpetraVector::get
virtual void get(double *block, std::size_t m, const dolfin::la_index *rows) const
Definition TpetraVector.cpp:206
dolfin::TpetraVector::get_local
virtual void get_local(double *block, std::size_t m, const dolfin::la_index *rows) const
Get block of values using local indices.
Definition TpetraVector.cpp:245
dolfin::TpetraVector::node_type
Tpetra::MultiVector ::node_type node_type
Node type.
Definition TpetraVector.h:58
dolfin::TpetraVector::copy
virtual std::shared_ptr< GenericVector > copy() const
Return copy of vector.
Definition TpetraVector.cpp:143
dolfin::TpetraVector::norm
virtual double norm(std::string norm_type) const
Return norm of vector.
Definition TpetraVector.cpp:459
dolfin::TpetraVector::inner
virtual double inner(const GenericVector &v) const
Return inner product with given vector.
Definition TpetraVector.cpp:445
dolfin::TpetraVector::operator*=
virtual const TpetraVector & operator*=(double a)
Multiply vector by given number.
Definition TpetraVector.cpp:533
dolfin::TpetraVector::vec
Teuchos::RCP< vector_type > vec() const
Return pointer to Tpetra vector object.
Definition TpetraVector.cpp:678
dolfin::TpetraVector::map_type
Tpetra::Map< int, dolfin::la_index, node_type > map_type
TpetraVector map type (local index, global index).
Definition TpetraVector.h:60
dolfin::TpetraVector::sum
virtual double sum() const
Return sum of values of vector.
Definition TpetraVector.cpp:494
dolfin
Definition adapt.h:30
dolfin::la_index
PetscInt la_index
Index type for compatibility with linear algebra backend(s).
Definition types.h:32