[Trilinos-Users] NOX warnings

Mohammad Reza Sharif sharif1133 at gmail.com
Thu Dec 3 10:40:17 MST 2009


Hi,

I tried the method suggested by Roger. But there's a problem yet.
I think it is the linear solver (here AztecOO) that prints the warning
messages.
I don't know how to disable these warnings.
I have attached the file that prints the warnings. In this file I
have deliberately
tried to solve a set of equations that does not have any answers.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://software.sandia.gov/pipermail/trilinos-users/attachments/20091203/5895e918/attachment-0001.html 
-------------- next part --------------
#include <iostream>
#include <cmath>
#ifdef HAVE_MPI
#include "mpi.h"
#include "Epetra_MpiComm.h"
#else
#include "Epetra_SerialComm.h"
#endif
#include "Epetra_Map.h"
#include "Epetra_Vector.h"
#include "NOX.H"
#include "NOX_Epetra_FiniteDifference.H"
#include "NOX_Epetra_Interface_Required.H"
#include "NOX_Epetra_LinearSystem_AztecOO.H"
#include "NOX_Epetra_Group.H"

double func1(double x);

const int N=4;
class SimpleProblemInterface : public NOX::Epetra::Interface::Required,
     						   public NOX::Epetra::Interface::Jacobian
{
public:
	SimpleProblemInterface( Epetra_Vector & InitialGuess ){
		InitialGuess_ = new Epetra_Vector(InitialGuess);
	};
	~SimpleProblemInterface(){};
	bool computeF(const Epetra_Vector & x, Epetra_Vector & f,
		NOX::Epetra::Interface::Required::FillType F ){
		f[0]=(x[1])-(x[2]*x[3]);
		f[1]=(pow(x[0],2))-(abs(x[0])-1);
		f[2]=(x[3])-(x[1]-1);
		f[3]=(x[2])-(func1(x[0]));
		return true;
	};
	bool computeJacobian(const Epetra_Vector & x, Epetra_Operator & Jac){
		cout << "*ERR* SimpleProblem::computeJacobian()\n";
		cout << "*ERR* don't use explicit Jacobian" << endl;
		exit(0);
		throw 1;
	};
	bool computePrecMatrix(const Epetra_Vector & x, Epetra_RowMatrix & M){
		cout << "*ERR* SimpleProblem::preconditionVector()\n";
		cout << "*ERR* don't use explicit preconditioning" << endl;
		exit(0);
		throw 1;
	};
	bool computePreconditioner(const Epetra_Vector & x, Epetra_Operator & O){
		cout << "*ERR* SimpleProblem::preconditionVector()\n";
		cout << "*ERR* don't use explicit preconditioning" << endl;
		exit(0);
		throw 1;
	};
private:
	Epetra_Vector * InitialGuess_;
};
int main( int argc, char **argv ){
#ifdef HAVE_MPI
	MPI_Init(&argc, &argv);
	Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
	Epetra_SerialComm Comm;
#endif
	if (Comm.NumProc() != 1) {
		if (Comm.MyPID() == 0)
			cerr << "Please run this test with one process only!" << endl;
#ifdef HAVE_MPI
	MPI_Finalize();
#endif
		exit(EXIT_SUCCESS);
	}
	Epetra_Map Map(N,0,Comm);
	Epetra_Vector InitialGuess(Map);
		
	InitialGuess[0]=1;
	InitialGuess[1]=1;
	InitialGuess[2]=1;
	InitialGuess[3]=1;

	Teuchos::RCP<SimpleProblemInterface> interface =
		Teuchos::rcp(new SimpleProblemInterface(InitialGuess));
	Teuchos::RCP<Teuchos::ParameterList> nlParamsPtr =
		Teuchos::rcp(new Teuchos::ParameterList);
	Teuchos::ParameterList& nlParams = *(nlParamsPtr.get());
	Teuchos::ParameterList& printParams = nlParams.sublist("Printing");
	Teuchos::ParameterList& searchParams = nlParams.sublist("Line Search");
	Teuchos::ParameterList& dirParams = nlParams.sublist("Direction");
	Teuchos::ParameterList& newtonParams = dirParams.sublist("Newton");
	Teuchos::ParameterList& lsParams = newtonParams.sublist("Linear Solver");
	nlParams.set("Nonlinear Solver", "Line Search Based");
	printParams.set("MyPID", Comm.MyPID());
	printParams.set("Output Precision",3);
	printParams.set("Output Processor", 0);
	printParams.set("Output Information",0);
	searchParams.set("Method", "Full Step");
	dirParams.set("Method", "Newton");
	newtonParams.set("Forcing Term Method", "Constant");
	lsParams.set("Aztec Solver", "GMRES");
	lsParams.set("Max Iterations", 800);
	lsParams.set("Tolerance", 1e-5);
	lsParams.set("Output Frequency", 50);
	NOX::Epetra::Vector noxInitGuess(InitialGuess, NOX::DeepCopy);
	Teuchos::RCP<NOX::Epetra::FiniteDifference> FD =
		Teuchos::rcp(new NOX::Epetra::FiniteDifference(
			printParams,
			interface,
			noxInitGuess));
	Teuchos::RCP<NOX::Epetra::Interface::Required> iReq = interface;
	Teuchos::RCP<NOX::Epetra::Interface::Jacobian> iJac=FD;
	Teuchos::RCP<Epetra_Operator> A=FD;
	Teuchos::RCP<NOX::Epetra::LinearSystemAztecOO> linSys =
		Teuchos::rcp(new NOX::Epetra::LinearSystemAztecOO(printParams, lsParams,
			iReq,
			iJac, A,
			noxInitGuess));
	Teuchos::RCP<NOX::Epetra::Group> grpPtr =
		Teuchos::rcp(new NOX::Epetra::Group(printParams,
			iReq,
			noxInitGuess,
			linSys));
	Teuchos::RCP<NOX::StatusTest::NormF> testNormF =
		Teuchos::rcp(new NOX::StatusTest::NormF(1e-6));
	Teuchos::RCP<NOX::StatusTest::MaxIters> testMaxIters =
		Teuchos::rcp(new NOX::StatusTest::MaxIters(200));
	Teuchos::RCP<NOX::StatusTest::Combo> combo =
		Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR,
			testNormF, testMaxIters));
	Teuchos::RCP<NOX::Solver::Generic> solver =
		NOX::Solver::buildSolver(grpPtr, combo, nlParamsPtr);
	NOX::StatusTest::StatusType status = solver->solve();
	if( NOX::StatusTest::Converged  == status )
		cout << "\n" << "-- NOX solver converged --" << "\n";
	else
		cout << "\n" << "-- NOX solver did not converge --" << "\n";
	cout << "-- Parameter List From Solver --" << "\n";
	solver->getList().print(cout);
	const NOX::Epetra::Group & finalGroup =
		dynamic_cast<const NOX::Epetra::Group&>(solver->getSolutionGroup());
	const Epetra_Vector & finalSolution =
		(dynamic_cast<const NOX::Epetra::Vector&>(finalGroup.getX())).getEpetraVector();
	if( Comm.MyPID() == 0 ) cout << "Computed solution : " << endl;
	cout<<finalSolution;
#ifdef HAVE_MPI
	MPI_Finalize();
#endif
	return(EXIT_SUCCESS);
}
double func1(double x){return x*x;}


More information about the Trilinos-Users mailing list