1 #include "../include/newton_solver.h"
2 #include "../include/newton_argument.h"
19 map((int)solver.n_dofs(), 0, comm)
74 const unsigned int max_steps)
84 using Teuchos::ParameterList;
85 using Teuchos::parameterList;
92 Epetra_Vector sol(
map);
93 Epetra_Vector init_guess(
map);
98 init_guess[i] = solution(i);
110 Teuchos::RCP<ProblemInterface>
interface =
113 RCP<Epetra_Operator> preconditioner(preconditioner_operator);
139 RCP<ParameterList> params = parameterList (
"NOX");
142 params->set (
"Nonlinear Solver",
"Line Search Based");
147 ParameterList &printParams = params->sublist (
"Printing");
148 printParams.set (
"MyPID",
comm.MyPID ());
149 printParams.set (
"Output Precision", 3);
150 printParams.set (
"Output Processor", 0);
154 const bool verbose =
false;
157 printParams.set (
"Output Information",
158 NOX::Utils::OuterIteration +
159 NOX::Utils::OuterIterationStatusTest +
160 NOX::Utils::InnerIteration +
161 NOX::Utils::Parameters +
162 NOX::Utils::Details +
163 NOX::Utils::Warning);
167 printParams.set (
"Output Information", NOX::Utils::Warning);
175 ParameterList &searchParams = params->sublist (
"Line Search");
176 searchParams.set (
"Method",
"Full Step");
179 ParameterList &dirParams = params->sublist (
"Direction");
181 dirParams.set (
"Method",
"Newton");
184 ParameterList &newtonParams = dirParams.sublist (
"Newton");
185 newtonParams.set (
"Forcing Term Method",
"Constant");
191 ParameterList &lsParams = newtonParams.sublist (
"Linear Solver");
197 lsParams.set (
"Max Iterations", 800);
199 lsParams.set (
"Output Frequency", 1);
200 lsParams.set (
"Preconditioner Operator",
"Finite Difference");
201 lsParams.set (
"Aztec Preconditioner",
"ilu");
203 lsParams.set(
"Preconditioner",
"User Defined");
209 RCP<NOX::Epetra::Interface::Required> iReq = interface;
210 RCP<NOX::Epetra::Interface::Jacobian> iJac = interface;
211 RCP<NOX::Epetra::Interface::Preconditioner> iPrec = interface;
214 RCP<NOX::Epetra::LinearSystemAztecOO> linSys;
217 linSys = rcp (
new NOX::Epetra::LinearSystemAztecOO (printParams, lsParams,
220 linSys = rcp (
new NOX::Epetra::LinearSystemAztecOO (printParams, lsParams,
221 iReq, iJac, jacobian, init_guess));
223 linSys = rcp (
new NOX::Epetra::LinearSystemAztecOO (printParams, lsParams,
224 iReq, iPrec, preconditioner, init_guess));
227 linSys = rcp (
new NOX::Epetra::LinearSystemAztecOO (printParams, lsParams,
228 iJac, jacobian, iPrec, preconditioner, init_guess));
232 NOX::Epetra::Vector noxInitGuess (init_guess, NOX::DeepCopy);
235 RCP<NOX::Epetra::Group> group =
236 rcp (
new NOX::Epetra::Group (printParams, iReq, noxInitGuess, linSys));
248 RCP<NOX::StatusTest::NormF> testNormF =
249 rcp (
new NOX::StatusTest::NormF (
rel_tol));
252 RCP<NOX::StatusTest::MaxIters> testMaxIters =
253 rcp (
new NOX::StatusTest::MaxIters (max_steps));
259 RCP<NOX::StatusTest::Combo> combo =
260 rcp (
new NOX::StatusTest::Combo (NOX::StatusTest::Combo::OR,
261 testNormF, testMaxIters));
264 RCP<NOX::Solver::Generic> solver =
265 NOX::Solver::buildSolver (group, combo, params);
268 NOX::StatusTest::StatusType status = solver->solve();
277 if (
comm.MyPID() == 0)
279 cout << endl <<
"-- Parameter List From Solver --" << endl;
280 solver->getList ().print (cout);
284 const NOX::Epetra::Group &finalGroup =
285 dynamic_cast<const NOX::Epetra::Group &
>(solver->getSolutionGroup());
287 const Epetra_Vector &finalSolution =
288 dynamic_cast<const NOX::Epetra::Vector &
> (finalGroup.getX ()).getEpetraVector ();
290 for (
unsigned int i=0; i<solution.
size(); ++i)
292 solution(i) = finalSolution[i];
void parse_parameters(ParameterHandler &prm)
Parse a parameter handler.
static void declare_parameters(ParameterHandler ¶m)
virtual unsigned int n_dofs() const =0
Returns the number of degrees of freedom.
#define AssertThrow(cond, exc)
NewtonArgument & solver
The bubble membrane poperties.
std::string get(const std::string &entry_string) const
void enter_subsection(const std::string &subsection)
NewtonSolver(NewtonArgument &solver)
Constructor for the NewtonSolver class.
std::string linear_solver_name
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
SolverControl solver_control
bool get_bool(const std::string &entry_name) const
Base class that needs to be inherited by any function that wants to use the newton solver class...
unsigned int solve(Vector< double > &solution, const unsigned int max_steps)
Solve.
PreconditionerOperator * preconditioner_operator
double get_double(const std::string &entry_name) const
static void declare_parameters(ParameterHandler &prm)
Declare parameters for this class to function properly.
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
void parse_parameters(ParameterHandler ¶m)
~NewtonSolver()
House cleaning.
JacobianOperator * jacobian_operator