<commit_before>/*-----------------   precondition_block.templates.h     ----------------------*/
/*      $Id$                 */
/*           <NAME>, University of Heidelberg                           */


#include <lac/precondition_block.h>
#include <lac/vector.h>
#include <lac/fullmatrix.h>
#include <lac/sparsematrix.h>


template <typename number, typename inverse_type>
PreconditionBlock<number, inverse_type>::PreconditionBlock ():
		blocksize(0),
		A(0)  {};


template <typename number, typename inverse_type>
PreconditionBlock<number, inverse_type>::~PreconditionBlock ()
{
  if (inverse.size()!=0)
    inverse.erase(inverse.begin(), inverse.end());
}

template <typename number, typename inverse_type>
void PreconditionBlock<number, inverse_type>::clear ()
{
  if (inverse.size()!=0)
    inverse.erase(inverse.begin(), inverse.end());
  blocksize=0;
}

template <typename number, typename inverse_type>
void PreconditionBlock<number, inverse_type>::use_matrix(
  const SparseMatrix<number> &M)
{
  A = &M;
}


template <typename number, typename inverse_type>
void PreconditionBlock<number, inverse_type>::set_block_size(unsigned int bsize) {
  blocksize=bsize;
}


template <typename number, typename inverse_type>
unsigned int PreconditionBlock<number, inverse_type>::block_size() const {
  return blocksize;
}


template <typename number, typename inverse_type>
void PreconditionBlock<number, inverse_type>::invert_diagblocks()
{
  Assert (A!=0, ExcNoMatrixGivenToUse());
  const SparseMatrix<number> &M=*A;
  Assert (M.m() == M.n(), ExcMatrixNotSquare());
  Assert (inverse.size()==0, ExcInverseMatricesAlreadyExist());

  Assert (blocksize!=0, ExcBlockSizeNotSet());
  Assert (M.m()%blocksize==0, ExcWrongBlockSize(blocksize, M.m()));

  const unsigned int n_cells = M.m()/blocksize;

				   // cell_row, cell_column are the
				   // numbering of the blocks (cells).
				   // row_cell, column_cell are the local
				   // numbering of the unknowns in the
				   // blocks.
				   // row, column are the global numbering
				   // of the unkowns.

				   // set the #inverse# array to the right
				   // size. we could do it like this:
				   // inverse = vector<>(n_cells,FullMatrix<>())
				   // but this would involve copying many
				   // FullMatrix objects.
				   //
				   // the following is a neat trick which
				   // avoids copying
  if (true)
    {
      vector<FullMatrix<inverse_type> > tmp(n_cells,
					    FullMatrix<inverse_type>(blocksize));
      inverse.swap (tmp);
    };
  
  FullMatrix<inverse_type> M_cell(blocksize);
  
  for (unsigned int cell=0, row=0; cell<n_cells; ++cell)
    {
      for (unsigned int row_cell=0; row_cell<blocksize; ++row_cell, ++row)
	for (unsigned int column_cell=0, column=cell*blocksize;
	     column_cell<blocksize; ++column_cell, ++column)
	  M_cell(row_cell,column_cell)=M(row,column);
//      try
//	{
      if (blocksize <=4)
	{  
	  inverse[cell].invert(M_cell);
	}
      else
	{
	  M_cell.gauss_jordan();
	  inverse[cell]=M_cell;
	}
//      }
//      catch (ExcNotImplemented &)
    }
				   // release the lock on A
  A=0;
}



/*--------------------- PreconditionBlockSOR -----------------------*/

template<typename number, typename inverse_type>
PreconditionBlockSOR<number, inverse_type>::PreconditionBlockSOR(const number omega):
		omega(omega)  {}


template<typename number, typename inverse_type>
PreconditionBlockSOR<number, inverse_type>::~PreconditionBlockSOR(){}


template <typename number, typename inverse_type>
template <typename number2>
void PreconditionBlockSOR<number, inverse_type>::operator() (Vector<number2> &dst,<commit_msg>do not release the lock on A as it is still needed<commit_after>/*-----------------   precondition_block.templates.h     ----------------------*/
/*      $Id$                 */
/*           <NAME>, University of Heidelberg                           */


#include <lac/precondition_block.h>
#include <lac/vector.h>
#include <lac/fullmatrix.h>
#include <lac/sparsematrix.h>


template <typename number, typename inverse_type>
PreconditionBlock<number, inverse_type>::PreconditionBlock ():
		blocksize(0),
		A(0)  {};


template <typename number, typename inverse_type>
PreconditionBlock<number, inverse_type>::~PreconditionBlock ()
{
  if (inverse.size()!=0)
    inverse.erase(inverse.begin(), inverse.end());
}

template <typename number, typename inverse_type>
void PreconditionBlock<number, inverse_type>::clear ()
{
  if (inverse.size()!=0)
    inverse.erase(inverse.begin(), inverse.end());
  blocksize=0;
}

template <typename number, typename inverse_type>
void PreconditionBlock<number, inverse_type>::use_matrix(
  const SparseMatrix<number> &M)
{
  A = &M;
}


template <typename number, typename inverse_type>
void PreconditionBlock<number, inverse_type>::set_block_size(unsigned int bsize) {
  blocksize=bsize;
}


template <typename number, typename inverse_type>
unsigned int PreconditionBlock<number, inverse_type>::block_size() const {
  return blocksize;
}


template <typename number, typename inverse_type>
void PreconditionBlock<number, inverse_type>::invert_diagblocks()
{
  Assert (A!=0, ExcNoMatrixGivenToUse());
  const SparseMatrix<number> &M=*A;
  Assert (M.m() == M.n(), ExcMatrixNotSquare());
  Assert (inverse.size()==0, ExcInverseMatricesAlreadyExist());

  Assert (blocksize!=0, ExcBlockSizeNotSet());
  Assert (M.m()%blocksize==0, ExcWrongBlockSize(blocksize, M.m()));

  const unsigned int n_cells = M.m()/blocksize;

				   // cell_row, cell_column are the
				   // numbering of the blocks (cells).
				   // row_cell, column_cell are the local
				   // numbering of the unknowns in the
				   // blocks.
				   // row, column are the global numbering
				   // of the unkowns.

				   // set the #inverse# array to the right
				   // size. we could do it like this:
				   // inverse = vector<>(n_cells,FullMatrix<>())
				   // but this would involve copying many
				   // FullMatrix objects.
				   //
				   // the following is a neat trick which
				   // avoids copying
  if (true)
    {
      vector<FullMatrix<inverse_type> > tmp(n_cells,
					    FullMatrix<inverse_type>(blocksize));
      inverse.swap (tmp);
    };
  
  FullMatrix<inverse_type> M_cell(blocksize);
  
  for (unsigned int cell=0, row=0; cell<n_cells; ++cell)
    {
      for (unsigned int row_cell=0; row_cell<blocksize; ++row_cell, ++row)
	for (unsigned int column_cell=0, column=cell*blocksize;
	     column_cell<blocksize; ++column_cell, ++column)
	  M_cell(row_cell,column_cell)=M(row,column);
//      try
//	{
      if (blocksize <=4)
	{  
	  inverse[cell].invert(M_cell);
	}
      else
	{
	  M_cell.gauss_jordan();
	  inverse[cell]=M_cell;
	}
//      }
//      catch (ExcNotImplemented &)
    }
}



/*--------------------- PreconditionBlockSOR -----------------------*/

template<typename number, typename inverse_type>
PreconditionBlockSOR<number, inverse_type>::PreconditionBlockSOR(const number omega):
		omega(omega)  {}


template<typename number, typename inverse_type>
PreconditionBlockSOR<number, inverse_type>::~PreconditionBlockSOR(){}


template <typename number, typename inverse_type>
template <typename number2>
void PreconditionBlockSOR<number, inverse_type>::operator() (Vector<number2> &dst,
{'fraction_non_alphanumeric': 0.14958677685950414, 'fraction_numerical': 0.004545454545454545, 'mean_word_length': 3.368832731648616, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 73, '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': '1884953', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2227, 'n_words': 518}