<commit_before>// $Id: petsc_nonlinear_solver.C 2891 2008-06-25 15:25:47Z friedmud $

// The libMesh Finite Element Library.
// Copyright (C) 2002-2007  <NAME>, <NAME>
  
// This library 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 2.1 of the License, or (at your option) any later version.
  
// This library 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 this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



#include "libmesh_common.h"

#ifdef HAVE_NOX


// C++ includes

// Local Includes
#include "nonlinear_implicit_system.h"
#include "trilinos_nox_nonlinear_solver.h"
#include "system.h"
#include "trilinos_epetra_vector.h"

// ---------- Standard Includes ----------
#include <iostream>
#include "Epetra_Vector.h"
#include "Epetra_Operator.h"
#include "Epetra_RowMatrix.h"
#include "NOX_Epetra_Interface_Required.H" // base class
#include "NOX_Epetra_Interface_Jacobian.H" // base class
#include "NOX_Epetra_Interface_Preconditioner.H" // base class
#include "NOX_Epetra_MatrixFree.H"
#include "NOX_Epetra_LinearSystem_AztecOO.H"
#include "NOX_Epetra_Group.H"	// class definition

// ---------- Forward Declarations ----------

class Problem_Interface : public NOX::Epetra::Interface::Required,
			  public NOX::Epetra::Interface::Jacobian,
			  public NOX::Epetra::Interface::Preconditioner
{
public:
  Problem_Interface(NoxNonlinearSolver<Number> * solver);
  ~Problem_Interface();
  
  //! Compute and return F
  bool computeF(const Epetra_Vector& x, Epetra_Vector& FVec,
		NOX::Epetra::Interface::Required::FillType fillType);
	
  //! Compute an explicit Jacobian
  bool computeJacobian(const Epetra_Vector& x, Epetra_Operator& Jac);
  
  //! Compute the Epetra_RowMatrix M, that will be used by the Aztec preconditioner instead of the Jacobian.  This is used when there is no explicit Jacobian present (i.e. Matrix-Free Newton-Krylov).  This MUST BE an Epetra_RowMatrix since the Aztec preconditioners need to know the sparsity pattern of the matrix.  Returns true if computation was successful.
  bool computePrecMatrix(const Epetra_Vector& x, Epetra_RowMatrix& M);
  
  //! Computes a user supplied preconditioner based on input vector x.  Returns true if computation was successful.
  bool computePreconditioner(const Epetra_Vector& x, Epetra_Operator& Prec,
			     Teuchos::ParameterList* p);
  
  //! Application Operator: Object that points to the user's evaluation routines.
  /*! This is used to point to the actual routines and to store
   *  auxiliary data required by the user's application for function/Jacobian
   *  evaluations that NOX does not need to know about.  This is type of
   *  passdown class design by the application code.
   */ 
  NoxNonlinearSolver<Number> * _solver;
};

// ----------   Includes   ----------
//#include <iostream>
//#include "Problem_Interface.H"

// ----------   User Defined Includes   ----------
//#include "Brusselator.H"

//-----------------------------------------------------------------------------
Problem_Interface::Problem_Interface(NoxNonlinearSolver<Number> * solver) :
  _solver(solver)
{ }

Problem_Interface::~Problem_Interface()
{ }

bool Problem_Interface::computeF(const Epetra_Vector& x, Epetra_Vector& r,
                       NOX::Epetra::Interface::Required::FillType fillType)
{
  libmesh_assert(xfe != NULL);
  libmesh_assert(rfe != NULL);
  
  NonlinearImplicitSystem &sys = _solver->system();

  EpetraVector<Number> X_global(x), R(r);
  EpetraVector<Number>& X_sys = *dynamic_cast<EpetraVector<Number>*>(sys.solution.get());

  // Use the systems update() to get a good local version of the parallel solution
  X_global.swap(X_sys);
  sys.update();
  X_global.swap(X_sys);
  
  R.zero();
  
  if( _solver->residual == NULL )
    return false;
  _solver->residual (*sys.current_local_solution.get(), R);
  return true;
}

bool Problem_Interface::computeJacobian(const Epetra_Vector& x,
                                        Epetra_Operator& Jac)
{
  throw 1;
  
  // return problem.evaluate(NOX::Epetra::Interface::Required::Jac, &x, 0, 0);
}

bool Problem_Interface::computePrecMatrix(const Epetra_Vector& x, Epetra_RowMatrix& M)<commit_msg>quick fix for compile error in debug<commit_after>// $Id: petsc_nonlinear_solver.C 2891 2008-06-25 15:25:47Z friedmud $

// The libMesh Finite Element Library.
// Copyright (C) 2002-2007  <NAME>, <NAME>
  
// This library 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 2.1 of the License, or (at your option) any later version.
  
// This library 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 this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



#include "libmesh_common.h"

#ifdef HAVE_NOX


// C++ includes

// Local Includes
#include "nonlinear_implicit_system.h"
#include "trilinos_nox_nonlinear_solver.h"
#include "system.h"
#include "trilinos_epetra_vector.h"

// ---------- Standard Includes ----------
#include <iostream>
#include "Epetra_Vector.h"
#include "Epetra_Operator.h"
#include "Epetra_RowMatrix.h"
#include "NOX_Epetra_Interface_Required.H" // base class
#include "NOX_Epetra_Interface_Jacobian.H" // base class
#include "NOX_Epetra_Interface_Preconditioner.H" // base class
#include "NOX_Epetra_MatrixFree.H"
#include "NOX_Epetra_LinearSystem_AztecOO.H"
#include "NOX_Epetra_Group.H"	// class definition

// ---------- Forward Declarations ----------

class Problem_Interface : public NOX::Epetra::Interface::Required,
			  public NOX::Epetra::Interface::Jacobian,
			  public NOX::Epetra::Interface::Preconditioner
{
public:
  Problem_Interface(NoxNonlinearSolver<Number> * solver);
  ~Problem_Interface();
  
  //! Compute and return F
  bool computeF(const Epetra_Vector& x, Epetra_Vector& FVec,
		NOX::Epetra::Interface::Required::FillType fillType);
	
  //! Compute an explicit Jacobian
  bool computeJacobian(const Epetra_Vector& x, Epetra_Operator& Jac);
  
  //! Compute the Epetra_RowMatrix M, that will be used by the Aztec preconditioner instead of the Jacobian.  This is used when there is no explicit Jacobian present (i.e. Matrix-Free Newton-Krylov).  This MUST BE an Epetra_RowMatrix since the Aztec preconditioners need to know the sparsity pattern of the matrix.  Returns true if computation was successful.
  bool computePrecMatrix(const Epetra_Vector& x, Epetra_RowMatrix& M);
  
  //! Computes a user supplied preconditioner based on input vector x.  Returns true if computation was successful.
  bool computePreconditioner(const Epetra_Vector& x, Epetra_Operator& Prec,
			     Teuchos::ParameterList* p);
  
  //! Application Operator: Object that points to the user's evaluation routines.
  /*! This is used to point to the actual routines and to store
   *  auxiliary data required by the user's application for function/Jacobian
   *  evaluations that NOX does not need to know about.  This is type of
   *  passdown class design by the application code.
   */ 
  NoxNonlinearSolver<Number> * _solver;
};

// ----------   Includes   ----------
//#include <iostream>
//#include "Problem_Interface.H"

// ----------   User Defined Includes   ----------
//#include "Brusselator.H"

//-----------------------------------------------------------------------------
Problem_Interface::Problem_Interface(NoxNonlinearSolver<Number> * solver) :
  _solver(solver)
{ }

Problem_Interface::~Problem_Interface()
{ }

bool Problem_Interface::computeF(const Epetra_Vector& x, Epetra_Vector& r,
                       NOX::Epetra::Interface::Required::FillType fillType)
{
  NonlinearImplicitSystem &sys = _solver->system();

  EpetraVector<Number> X_global(x), R(r);
  EpetraVector<Number>& X_sys = *dynamic_cast<EpetraVector<Number>*>(sys.solution.get());

  // Use the systems update() to get a good local version of the parallel solution
  X_global.swap(X_sys);
  sys.update();
  X_global.swap(X_sys);
  
  R.zero();
  
  if( _solver->residual == NULL )
    return false;
  _solver->residual (*sys.current_local_solution.get(), R);
  return true;
}

bool Problem_Interface::computeJacobian(const Epetra_Vector& x,
                                        Epetra_Operator& Jac)
{
  throw 1;
  
  // return problem.evaluate(NOX::Epetra::Interface::Required::Jac, &x, 0, 0);
}

bool Problem_Interface::computePrecMatrix(const Epetra_Vector& x, Epetra_RowMatrix& M)
{'fraction_non_alphanumeric': 0.12882238126219908, 'fraction_numerical': 0.009759271307742356, 'mean_word_length': 3.5613254203758653, 'pattern_counts': {'":': 0, '<': 25, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5002430', 'n_tokens_mistral': 2970, 'n_tokens_neox': 2787, 'n_words': 867}