<commit_before>//---------------------------------------------------------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 2009, 2010, 2012, 2013 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//---------------------------------------------------------------------------


// check ConstraintMatrix.distribute() for a petsc vector
//
// we do this by creating a vector where each processor has 100
// elements but no ghost elements. then we add constraints on each
// processor that constrain elements within each processor's local
// range to ones outside. these have to be added on all
// processors. then call distribute() and verify that the result is
// true.
//
// we use constraints of the form x_i = x_j with sequentially growing
// x_j's so that we can verify the correctness analytically
//
// compared to the _01 test, here the ConstraintMatrix object acts on an index
// set that only includes the locally owned vector elements, without any
// overlap. this verifies that we really only need to know about the *sources*
// of constraints locally, not the *targets*.


#include "../tests.h"
#include <deal.II/base/logstream.h>
#include <deal.II/lac/petsc_parallel_vector.h>
#include <deal.II/lac/constraint_matrix.h>

#include <fstream>
#include <sstream>



void test()
{
  const unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
  const unsigned int n_processes = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);

  // create a vector that consists of elements indexed from 0 to n
  PETScWrappers::MPI::Vector vec (MPI_COMM_WORLD, 100 * n_processes, 100);
  Assert (vec.local_size() == 100, ExcInternalError());
  Assert (vec.local_range().first == 100*myid, ExcInternalError());
  Assert (vec.local_range().second == 100*myid+100, ExcInternalError());
  for (unsigned int i=vec.local_range().first; i<vec.local_range().second; ++i)
    vec(i) = i;
  vec.compress();

  // verify correctness so far
  {
    double exact_l1 = 0;
    for (unsigned int i=0; i<vec.size(); ++i)
      exact_l1 += i;
    Assert (vec.l1_norm() == exact_l1, ExcInternalError());
  }


  // create a ConstraintMatrix with a range that only includes locally active
  // DoFs
  IndexSet locally_relevant_range (vec.size());
  locally_relevant_range.add_range (100*myid,
				    100*myid+100);
  ConstraintMatrix cm (locally_relevant_range);

  // add constraints that constrain an element in the middle of the
  // local range of each processor against an element outside, both in
  // the ghost range before and after
  //
  // note that we tell each processor about all constraints, but most
  // of them will throw away this information since it is not for a
  // DoF inside the locally relevant range
  for (unsigned int p=0; p<n_processes; ++p)
    {
      if ((p != 0) && locally_relevant_range.is_element (p*100+10))
	{
	  cm.add_line (p*100+10);
	  cm.add_entry (p*100+10,
			p*100-25,
			1);
	}

      if ((p != n_processes-1) && locally_relevant_range.is_element (p*100+90))
	{
	  cm.add_line (p*100+90);
	  cm.add_entry (p*100+90,
			p*100+105,
			1);
	}
    }
  cm.close ();
<commit_msg>Augment text.<commit_after>//---------------------------------------------------------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 2009, 2010, 2012, 2013 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//---------------------------------------------------------------------------


// check ConstraintMatrix.distribute() for a petsc vector
//
// we do this by creating a vector where each processor has 100
// elements but no ghost elements. then we add constraints on each
// processor that constrain elements within each processor's local
// range to ones outside. these have to be added on all
// processors. then call distribute() and verify that the result is
// true.
//
// we use constraints of the form x_i = x_j with sequentially growing
// x_j's so that we can verify the correctness analytically
//
// compared to the _01 test, here the ConstraintMatrix object acts on an index
// set that only includes the locally owned vector elements, without any
// overlap. this verifies that we really only need to know about the *targets*
// of constraints locally, not the *sources*. (at the time of writing this
// test, ConstraintMatrix::distribute for PETSc distributed vectors actively
// imported the source vector elements for those target elements we locally
// own.)


#include "../tests.h"
#include <deal.II/base/logstream.h>
#include <deal.II/lac/petsc_parallel_vector.h>
#include <deal.II/lac/constraint_matrix.h>

#include <fstream>
#include <sstream>



void test()
{
  const unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
  const unsigned int n_processes = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);

  // create a vector that consists of elements indexed from 0 to n
  PETScWrappers::MPI::Vector vec (MPI_COMM_WORLD, 100 * n_processes, 100);
  Assert (vec.local_size() == 100, ExcInternalError());
  Assert (vec.local_range().first == 100*myid, ExcInternalError());
  Assert (vec.local_range().second == 100*myid+100, ExcInternalError());
  for (unsigned int i=vec.local_range().first; i<vec.local_range().second; ++i)
    vec(i) = i;
  vec.compress();

  // verify correctness so far
  {
    double exact_l1 = 0;
    for (unsigned int i=0; i<vec.size(); ++i)
      exact_l1 += i;
    Assert (vec.l1_norm() == exact_l1, ExcInternalError());
  }


  // create a ConstraintMatrix with a range that only includes locally owned
  // DoFs
  IndexSet locally_owned_range (vec.size());
  locally_owned_range.add_range (100*myid,
				    100*myid+100);
  ConstraintMatrix cm (locally_owned_range);

  // add constraints that constrain an element in the middle of the
  // local range of each processor against an element outside, both in
  // the ghost range before and after
  //
  // note that we tell each processor about all constraints, but most
  // of them will throw away this information since it is not for a
  // DoF inside the locally relevant range
  for (unsigned int p=0; p<n_processes; ++p)
    {
      if ((p != 0) && locally_owned_range.is_element (p*100+10))
	{
	  cm.add_line (p*100+10);
	  cm.add_entry (p*100+10,
			p*100-25,
			1);
	}

      if ((p != n_processes-1) && locally_owned_range.is_element (p*100+90))
	{
	  cm.add_line (p*100+90);
	  cm.add_entry (p*100+90,
			p*100+105,
			1);
	}
    }
  cm.close ();

{'fraction_non_alphanumeric': 0.15314002622759726, 'fraction_numerical': 0.029433192481422118, 'mean_word_length': 2.856179775280899, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5084881', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2046, 'n_words': 744}