[Trilinos-Users] Solving a trivial nonlinear system with pytrilinos nox with an exact Jacobian.

Mon Jan 25 13:42:34 MST 2010

```How do I pass in the formula for the analytical jacobian to NOX?  Following the template for the 1DFEM and the doc strings are a bit vague on this point.

V/R

Scott

The problem is taken from didasko/examples/nox/ex1.cpp
F=[x1**2+x2**2-1, x2-x1**2]...find the roots.

The error is:
ValueError: invalid null reference in method 'new_LinearSystemAztecOO', argument 5 of type 'Teuchos::RCP< Epetra_Operator > const &'

My 30 line attemp follows:

from PyTrilinos import Epetra, NOX

class MyProblem(NOX.Epetra.Interface.Required):
def __init__(self):
NOX.Epetra.Interface.Required.__init__(self)
self.__comm              = Epetra.SerialComm()
def computeF(self,x,F,flag):
try:
F[:]=[x[0]*x[0]+x[1]*x[1]-1,x[1]-x[0]*x[0]]
except Exception, e:
print "Expeption in computeF method "
print e
return False
return True

class MyJacobian(NOX.Epetra.Interface.Jacobian):
def __init__(self):
NOX.Epetra.Interface.Jacobian.__init__(self)
self.__comm              = Epetra.SerialComm()
def computeJacobian(self,x,Jac,flag):
try:
Jac=[[2*x[0],2*x[1]],[-2*x[0],1]]
except Exception, e:
print "Expeption in computeJacobian"
print e
return False
return True

def main():
soln =Epetra.Vector([.5,.5])
initGuess=Epetra.Vector([.5,.5])

problem=MyProblem()
myJac=MyJacobian()

NOX.defaultSolver(initGuess,problem,jacInterface=myJac,jacobian=None\
, precInterface=None, preconditioner=None, nlParams=None)
finalGroup = solver.getSolutionGroup()
finalSoln  = finalGroup.getX()

```