<commit_before>/*
 * Copyright (C) 2011 Scientific Computation Research Center
 *
 * This work is open source software, licensed under the terms of the
 * BSD license as described in the LICENSE file in the top-level directory.
 */

#include "awrLinearSystem.h"
#include <AztecOO.h>
#include <Epetra_MpiComm.h>
#include <Epetra_Map.h>
#include <Epetra_MultiVector.h>
#include <Epetra_CrsMatrix.h>

namespace awr
{

LinearSystem::LinearSystem(GO n, Epetra_Map* map) :
  numGlobalEqs_(n),
  map_(map)
{
  numLocalEqs_ = map_->NumMyElements();
  A_ = new Epetra_CrsMatrix(Copy,*map_,n);
  x_ = new Epetra_MultiVector(*map_,/*num vectors=*/1);
  b_ = new Epetra_MultiVector(*map_,/*num vectors=*/1);
}

LinearSystem::~LinearSystem()
{
  delete map_;
  delete A_;
  delete x_;
  delete b_;
}

GO LinearSystem::mapLIDtoGID(LO lid)
{
  GO* myGlobalElements = NULL;
  myGlobalElements = map_->MyGlobalElements64();
  return myGlobalElements[lid];
}

void LinearSystem::sumToVector(double v, GO i)
{
  b_->SumIntoGlobalValue(i,/*vec idx=*/0,v);
}

void LinearSystem::replaceToVector(double v, GO i)
{
  b_->ReplaceGlobalValue(i,/*vec idx=*/0,v);
}

void LinearSystem::sumToMatrix(double v, GO i, GO j)
{
  double val[1]; val[0] = v;
  GO col[1]; col[0] = j;
  A_->InsertGlobalValues(i,1,val,col);
}

void LinearSystem::diagonalizeMatrixRow(GO i)
{
  int n;
  double* v;
  GO* j;
  A_->ExtractGlobalRowView(i,n,v,j);
  for (int i=0; i < n; ++i)
    v[i] = 0.0;
  this->sumToMatrix(1.0,i,i);
}

void LinearSystem::completeMatrixFill()
{
  A_->FillComplete();
}

double* LinearSystem::getSolution()
{
  double** sol;
  x_->ExtractView(&sol);
  return sol[0];
}

void LinearSystem::solve()<commit_msg>silence shadow warning<commit_after>/*
 * Copyright (C) 2011 Scientific Computation Research Center
 *
 * This work is open source software, licensed under the terms of the
 * BSD license as described in the LICENSE file in the top-level directory.
 */

#include "awrLinearSystem.h"
#include <AztecOO.h>
#include <Epetra_MpiComm.h>
#include <Epetra_Map.h>
#include <Epetra_MultiVector.h>
#include <Epetra_CrsMatrix.h>

namespace awr
{

LinearSystem::LinearSystem(GO n, Epetra_Map* map) :
  numGlobalEqs_(n),
  map_(map)
{
  numLocalEqs_ = map_->NumMyElements();
  A_ = new Epetra_CrsMatrix(Copy,*map_,n);
  x_ = new Epetra_MultiVector(*map_,/*num vectors=*/1);
  b_ = new Epetra_MultiVector(*map_,/*num vectors=*/1);
}

LinearSystem::~LinearSystem()
{
  delete map_;
  delete A_;
  delete x_;
  delete b_;
}

GO LinearSystem::mapLIDtoGID(LO lid)
{
  GO* myGlobalElements = NULL;
  myGlobalElements = map_->MyGlobalElements64();
  return myGlobalElements[lid];
}

void LinearSystem::sumToVector(double v, GO i)
{
  b_->SumIntoGlobalValue(i,/*vec idx=*/0,v);
}

void LinearSystem::replaceToVector(double v, GO i)
{
  b_->ReplaceGlobalValue(i,/*vec idx=*/0,v);
}

void LinearSystem::sumToMatrix(double v, GO i, GO j)
{
  double val[1]; val[0] = v;
  GO col[1]; col[0] = j;
  A_->InsertGlobalValues(i,1,val,col);
}

void LinearSystem::diagonalizeMatrixRow(GO i)
{
  int n;
  double* v;
  GO* j;
  A_->ExtractGlobalRowView(i,n,v,j);
  for (int k=0; k < n; ++k)
    v[k] = 0.0;
  this->sumToMatrix(1.0,i,i);
}

void LinearSystem::completeMatrixFill()
{
  A_->FillComplete();
}

double* LinearSystem::getSolution()
{
  double** sol;
  x_->ExtractView(&sol);
  return sol[0];
}

void LinearSystem::solve()
{'fraction_non_alphanumeric': 0.15420974889217134, 'fraction_numerical': 0.012407680945347119, 'mean_word_length': 4.9092495636998255, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, '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': '6306361', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1305, 'n_words': 291}