libMesh::Problem_Interface Class Reference
Inheritance diagram for libMesh::Problem_Interface:

Public Member Functions

 Problem_Interface (NoxNonlinearSolver< Number > *solver)
 
 ~Problem_Interface ()
 
bool computeF (const Epetra_Vector &x, Epetra_Vector &FVec, NOX::Epetra::Interface::Required::FillType fillType)
 Compute and return F. More...
 
bool computeJacobian (const Epetra_Vector &x, Epetra_Operator &Jac)
 Compute an explicit Jacobian. More...
 
bool computePrecMatrix (const Epetra_Vector &x, Epetra_RowMatrix &M)
 
bool computePreconditioner (const Epetra_Vector &x, Epetra_Operator &Prec, Teuchos::ParameterList *p)
 

Public Attributes

NoxNonlinearSolver< Number > * _solver
 

Detailed Description

Definition at line 45 of file trilinos_nox_nonlinear_solver.C.

Constructor & Destructor Documentation

◆ Problem_Interface()

libMesh::Problem_Interface::Problem_Interface ( NoxNonlinearSolver< Number > *  solver)
explicit

Definition at line 84 of file trilinos_nox_nonlinear_solver.C.

84  :
85  _solver(solver)
86 {}
NoxNonlinearSolver< Number > * _solver

◆ ~Problem_Interface()

libMesh::Problem_Interface::~Problem_Interface ( )

Definition at line 90 of file trilinos_nox_nonlinear_solver.C.

91 {}

Member Function Documentation

◆ computeF()

bool libMesh::Problem_Interface::computeF ( const Epetra_Vector &  x,
Epetra_Vector &  FVec,
NOX::Epetra::Interface::Required::FillType  fillType 
)

Compute and return F.

Definition at line 95 of file trilinos_nox_nonlinear_solver.C.

References _solver, libMesh::ParallelObject::comm(), libMesh::System::current_local_solution, libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_dof_map(), libMesh::NonlinearSolver< T >::matvec, libMesh::NonlinearImplicitSystem::ComputeResidual::residual(), libMesh::NonlinearSolver< T >::residual, libMesh::NonlinearImplicitSystem::ComputeResidualandJacobian::residual_and_jacobian(), libMesh::NonlinearSolver< T >::residual_and_jacobian_object, libMesh::NonlinearSolver< T >::residual_object, libMesh::ExplicitSystem::rhs, libMesh::System::solution, libMesh::EpetraVector< T >::swap(), libMesh::NonlinearSolver< T >::system(), and libMesh::System::update().

98 {
99  LOG_SCOPE("residual()", "TrilinosNoxNonlinearSolver");
100 
101  NonlinearImplicitSystem & sys = _solver->system();
102 
103  EpetraVector<Number> X_global(*const_cast<Epetra_Vector *>(&x), sys.comm()), R(r, sys.comm());
104  EpetraVector<Number> & X_sys = *cast_ptr<EpetraVector<Number> *>(sys.solution.get());
105  EpetraVector<Number> & R_sys = *cast_ptr<EpetraVector<Number> *>(sys.rhs);
106 
107  // Use the systems update() to get a good local version of the parallel solution
108  X_global.swap(X_sys);
109  R.swap(R_sys);
110 
112  sys.update();
113 
114  // Swap back
115  X_global.swap(X_sys);
116  R.swap(R_sys);
117 
118  R.zero();
119 
120  //-----------------------------------------------------------------------------
121  // if the user has provided both function pointers and objects only the pointer
122  // will be used, so catch that as an error
123 
125  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the Residual!");
126 
128  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the combined Residual & Jacobian!");
129 
130  if (_solver->residual != nullptr)
131  _solver->residual(*sys.current_local_solution.get(), R, sys);
132 
133  else if (_solver->residual_object != nullptr)
134  _solver->residual_object->residual(*sys.current_local_solution.get(), R, sys);
135 
136  else if (_solver->matvec != nullptr)
137  _solver->matvec(*sys.current_local_solution.get(), &R, nullptr, sys);
138 
139  else if (_solver->residual_and_jacobian_object != nullptr)
140  _solver->residual_and_jacobian_object->residual_and_jacobian (*sys.current_local_solution.get(), &R, nullptr, sys);
141 
142  else
143  return false;
144 
145  R.close();
146  X_global.close();
147 
148  return true;
149 }
void(* residual)(const NumericVector< Number > &X, NumericVector< Number > &R, sys_type &S)
NonlinearImplicitSystem::ComputeResidualandJacobian * residual_and_jacobian_object
virtual void residual(const NumericVector< Number > &X, NumericVector< Number > &R, sys_type &S)=0
NoxNonlinearSolver< Number > * _solver
NonlinearImplicitSystem::ComputeResidual * residual_object
const sys_type & system() const
const DofMap & get_dof_map() const
Definition: system.h:2049
virtual void residual_and_jacobian(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)=0
void(* matvec)(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const

◆ computeJacobian()

bool libMesh::Problem_Interface::computeJacobian ( const Epetra_Vector &  x,
Epetra_Operator &  Jac 
)

Compute an explicit Jacobian.

Definition at line 153 of file trilinos_nox_nonlinear_solver.C.

References _solver, libMesh::ParallelObject::comm(), libMesh::System::current_local_solution, libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_dof_map(), libMesh::NonlinearImplicitSystem::ComputeJacobian::jacobian(), libMesh::NonlinearSolver< T >::jacobian, libMesh::NonlinearSolver< T >::jacobian_object, libMesh::NonlinearSolver< T >::matvec, libMesh::NonlinearImplicitSystem::ComputeResidualandJacobian::residual_and_jacobian(), libMesh::NonlinearSolver< T >::residual_and_jacobian_object, libMesh::System::solution, libMesh::EpetraVector< T >::swap(), libMesh::NonlinearSolver< T >::system(), and libMesh::System::update().

155 {
156  LOG_SCOPE("jacobian()", "TrilinosNoxNonlinearSolver");
157 
158  NonlinearImplicitSystem & sys = _solver->system();
159 
160  EpetraMatrix<Number> J(&dynamic_cast<Epetra_FECrsMatrix &>(jac), sys.comm());
161  EpetraVector<Number> & X_sys = *cast_ptr<EpetraVector<Number> *>(sys.solution.get());
162  EpetraVector<Number> X_global(*const_cast<Epetra_Vector *>(&x), sys.comm());
163 
164  // Set the dof maps
165  J.attach_dof_map(sys.get_dof_map());
166 
167  // Use the systems update() to get a good local version of the parallel solution
168  X_global.swap(X_sys);
169 
171  sys.update();
172 
173  X_global.swap(X_sys);
174 
175  //-----------------------------------------------------------------------------
176  // if the user has provided both function pointers and objects only the pointer
177  // will be used, so catch that as an error
179  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the Jacobian!");
180 
182  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the combined Residual & Jacobian!");
183 
184  if (_solver->jacobian != nullptr)
185  _solver->jacobian(*sys.current_local_solution.get(), J, sys);
186 
187  else if (_solver->jacobian_object != nullptr)
188  _solver->jacobian_object->jacobian(*sys.current_local_solution.get(), J, sys);
189 
190  else if (_solver->matvec != nullptr)
191  _solver->matvec(*sys.current_local_solution.get(), nullptr, &J, sys);
192 
193  else if (_solver->residual_and_jacobian_object != nullptr)
194  _solver->residual_and_jacobian_object->residual_and_jacobian (*sys.current_local_solution.get(), nullptr, &J, sys);
195 
196  else
197  libmesh_error_msg("Error! Unable to compute residual and/or Jacobian!");
198 
199  J.close();
200  X_global.close();
201 
202  return true;
203 }
NonlinearImplicitSystem::ComputeResidualandJacobian * residual_and_jacobian_object
NoxNonlinearSolver< Number > * _solver
void(* jacobian)(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)
const sys_type & system() const
NonlinearImplicitSystem::ComputeJacobian * jacobian_object
virtual void jacobian(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)=0
const DofMap & get_dof_map() const
Definition: system.h:2049
virtual void residual_and_jacobian(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)=0
void(* matvec)(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const

◆ computePrecMatrix()

bool libMesh::Problem_Interface::computePrecMatrix ( const Epetra_Vector &  x,
Epetra_RowMatrix &  M 
)

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.

Definition at line 207 of file trilinos_nox_nonlinear_solver.C.

208 {
209  // libMesh::out << "ERROR: Problem_Interface::preconditionVector() - Use Explicit Jacobian only for this test problem!" << endl;
210  throw 1;
211 }

◆ computePreconditioner()

bool libMesh::Problem_Interface::computePreconditioner ( const Epetra_Vector &  x,
Epetra_Operator &  Prec,
Teuchos::ParameterList *  p 
)

Computes a user supplied preconditioner based on input vector x. Returns true if computation was successful.

Definition at line 215 of file trilinos_nox_nonlinear_solver.C.

References _solver, libMesh::ParallelObject::comm(), libMesh::TrilinosPreconditioner< T >::compute(), libMesh::System::current_local_solution, libMesh::DofMap::enforce_constraints_exactly(), libMesh::System::get_dof_map(), libMesh::NonlinearImplicitSystem::ComputeJacobian::jacobian(), libMesh::NonlinearSolver< T >::jacobian, libMesh::NonlinearSolver< T >::jacobian_object, libMesh::TrilinosPreconditioner< T >::mat(), libMesh::NonlinearSolver< T >::matvec, libMesh::NonlinearImplicitSystem::ComputeResidualandJacobian::residual_and_jacobian(), libMesh::NonlinearSolver< T >::residual_and_jacobian_object, libMesh::System::solution, libMesh::EpetraVector< T >::swap(), libMesh::NonlinearSolver< T >::system(), and libMesh::System::update().

218 {
219  LOG_SCOPE("preconditioner()", "TrilinosNoxNonlinearSolver");
220 
221  NonlinearImplicitSystem & sys = _solver->system();
222  TrilinosPreconditioner<Number> & tpc = dynamic_cast<TrilinosPreconditioner<Number> &>(prec);
223 
224  EpetraMatrix<Number> J(dynamic_cast<Epetra_FECrsMatrix *>(tpc.mat()),sys.comm());
225  EpetraVector<Number> & X_sys = *cast_ptr<EpetraVector<Number> *>(sys.solution.get());
226  EpetraVector<Number> X_global(*const_cast<Epetra_Vector *>(&x), sys.comm());
227 
228  // Set the dof maps
229  J.attach_dof_map(sys.get_dof_map());
230 
231  // Use the systems update() to get a good local version of the parallel solution
232  X_global.swap(X_sys);
233 
235  sys.update();
236 
237  X_global.swap(X_sys);
238 
239  //-----------------------------------------------------------------------------
240  // if the user has provided both function pointers and objects only the pointer
241  // will be used, so catch that as an error
243  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the Jacobian!");
244 
246  libmesh_error_msg("ERROR: cannot specify both a function and object to compute the combined Residual & Jacobian!");
247 
248  if (_solver->jacobian != nullptr)
249  _solver->jacobian(*sys.current_local_solution.get(), J, sys);
250 
251  else if (_solver->jacobian_object != nullptr)
252  _solver->jacobian_object->jacobian(*sys.current_local_solution.get(), J, sys);
253 
254  else if (_solver->matvec != nullptr)
255  _solver->matvec(*sys.current_local_solution.get(), nullptr, &J, sys);
256 
257  else if (_solver->residual_and_jacobian_object != nullptr)
258  _solver->residual_and_jacobian_object->residual_and_jacobian (*sys.current_local_solution.get(), nullptr, &J, sys);
259 
260  else
261  libmesh_error_msg("Error! Unable to compute residual and/or Jacobian!");
262 
263  J.close();
264  X_global.close();
265 
266  tpc.compute();
267 
268  return true;
269 }
NonlinearImplicitSystem::ComputeResidualandJacobian * residual_and_jacobian_object
NoxNonlinearSolver< Number > * _solver
void(* jacobian)(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)
const sys_type & system() const
NonlinearImplicitSystem::ComputeJacobian * jacobian_object
virtual void jacobian(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)=0
const DofMap & get_dof_map() const
Definition: system.h:2049
virtual void residual_and_jacobian(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)=0
void(* matvec)(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const

Member Data Documentation

◆ _solver

NoxNonlinearSolver<Number>* libMesh::Problem_Interface::_solver

The documentation for this class was generated from the following file: