Example #1
0
//-----------------------------------------------------------------------------
void TpetraVector::gather(GenericVector& y,
                          const std::vector<dolfin::la_index>& indices) const
{
  dolfin_assert(!_x.is_null());

  // FIXME: not working?

  TpetraVector& _y = as_type<TpetraVector>(y);

  const std::pair<std::size_t, std::size_t> range(0, indices.size());

  if (_y._x.is_null())
    _y._init(MPI_COMM_SELF, range, indices);
  else if (y.size() != indices.size() || MPI::size(y.mpi_comm()) != 0)
  {
    dolfin_error("TpetraVector.cpp",
                 "gather vector entries",
                 "Cannot re-initialize gather vector. Must be empty, or have correct size and be a local vector");
  }


  Tpetra::Export<vector_type::local_ordinal_type,
                 vector_type::global_ordinal_type, vector_type::node_type>
    exporter(_x->getMap(), _y._x->getMap());

  _y._x->doExport(*_x, exporter, Tpetra::INSERT);
}
Example #2
0
//-----------------------------------------------------------------------------
void EpetraVector::gather(GenericVector& y,
                          const std::vector<dolfin::la_index>& indices) const
{
  dolfin_assert(_x);

  // Down cast to an EpetraVector
  EpetraVector& _y = as_type<EpetraVector>(y);

  // Create serial communicator
  Epetra_SerialComm epetra_serial_comm;

  // Create map for y
  Epetra_BlockMap target_map(indices.size(), indices.size(), indices.data(),
                             1, 0, epetra_serial_comm);

  // Initialise vector y
  if (y.empty())
    _y.init(target_map);
  else if (_y.size() != indices.size() ||  MPI::size(y.mpi_comm()))
  {
    // FIXME: also check that vector is local
    dolfin_error("EpetraVector.cpp",
                 "gather vector entries",
                 "Cannot re-initialize gather vector. Must be empty, or have correct size and be a local vector");
  }

  dolfin_assert(_y.vec());

  // Create importer
  Epetra_Import importer(target_map, _x->Map());

  // Import values into y
  _y.vec()->Import(*_x, importer, Insert);
}
Example #3
0
//-----------------------------------------------------------------------------
double dolfin::residual(const GenericLinearOperator& A,
                        const GenericVector& x,
                        const GenericVector& b)
{
  std::shared_ptr<GenericVector> y = x.factory().create_vector(x.mpi_comm());
  A.mult(x, *y);
  *y -= b;
  return y->norm("l2");
}
Example #4
0
//-----------------------------------------------------------------------------
std::size_t dolfin::solve(const GenericLinearOperator& A,
                          GenericVector& x,
                          const GenericVector& b,
                          std::string method,
                          std::string preconditioner)
{
  Timer timer("Solving linear system");
  LinearSolver solver(x.mpi_comm(), method, preconditioner);
  return solver.solve(A, x, b);
}