From: Baerbel Jannsen Date: Fri, 27 Aug 2010 09:51:01 +0000 (+0000) Subject: new test for Newton's method X-Git-Tag: v8.0.0~5653 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2510effee2c62456794201e949d9de721bb0e641;p=dealii.git new test for Newton's method git-svn-id: https://svn.dealii.org/trunk@21745 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/deal.II/Makefile b/tests/deal.II/Makefile index 135a11efd6..7b36bd8a93 100644 --- a/tests/deal.II/Makefile +++ b/tests/deal.II/Makefile @@ -87,7 +87,8 @@ tests_x = block_info block_matrices \ number_cache_* \ kelly_crash_* \ recursively_set_material_id \ - point_value_history_* + point_value_history_* \ + newton_* # from above list of regular expressions, generate the real set of # tests diff --git a/tests/deal.II/newton_01.cc b/tests/deal.II/newton_01.cc new file mode 100644 index 0000000000..f14efdf6ce --- /dev/null +++ b/tests/deal.II/newton_01.cc @@ -0,0 +1,134 @@ +//----------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2008, 2009 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//----------------------------------------------------------------------------- + +#include +#include +#include +#include + + +//test computing square root of 2 with newton's method + +using namespace dealii; + +class SquareRoot : public Subscriptor +{ + public: + void start_vector (Vector& start) const; + void residual (NamedData*>& out, + const NamedData*>& in); + void solve (NamedData*>& out, + const NamedData*>& in); +}; + +class SquareRootResidual : public + Algorithms::Operator > +{ + SmartPointer + discretization; + public: + + SquareRootResidual(SquareRoot& problem) + : discretization(&problem) + {} + + virtual void operator ()( + NamedData*>& out, + const NamedData*>& in) + { + discretization->residual(out,in); + } +}; + +class SquareRootSolver : public + Algorithms::Operator > +{ + SmartPointer + solver; + public: + + SquareRootSolver(SquareRoot& problem) + : solver(&problem) + {} + + virtual void operator ()( + NamedData*>& out, + const NamedData*>& in) + { + solver->solve(out,in); + } +}; + +void SquareRoot::residual ( + NamedData*>& out, + const NamedData*>& in) +{ + //residuum = 0 + *out(0) = 0.; + const Vector &x = *in(in.find("Newton iterate")); + *out(0) = x*x - 2.; +} + +void SquareRoot::solve ( + NamedData*>& out, + const NamedData*>& in) +{ + *out(0) = 0; + const Vector &x = *in(in.find("Newton iterate")); + const Vector &r = *in(in.find("Newton residual")); + + (*out(0))(0) = 1./2./x(0)* r(0); +} + + + +void test () +{ + SquareRoot square_root; + SquareRootSolver sq_solver (square_root); + SquareRootResidual sq_residual (square_root); + + Algorithms::OutputOperator > output; + + Algorithms::Newton > newton( + sq_residual, + sq_solver); + newton.initialize(output); + + NamedData*> in_data; + NamedData*> out_data; + + Vector solution (1); + solution = 10.; + Vector* p = &solution; + out_data.add(p, "solution"); + + newton.control.set_reduction(1.e-20); + newton.control.log_history(true); + newton.debug_vectors = true; + newton(out_data, in_data); + deallog << " square root " << (*out_data(0))(0) << std::endl; +} + + + + +int main() +{ + std::ofstream logfile("newton_01/output"); + deallog.attach(logfile); + deallog.depth_console(10); + deallog.threshold_double(1.e-10); + + test (); +} diff --git a/tests/deal.II/newton_01/cmp/generic b/tests/deal.II/newton_01/cmp/generic new file mode 100644 index 0000000000..bc020eba5c --- /dev/null +++ b/tests/deal.II/newton_01/cmp/generic @@ -0,0 +1,21 @@ + +DEAL::0 +DEAL::2 +DEAL::4 +DEAL::6 +DEAL::8 +DEAL::10 +DEAL::12 +DEAL::14 +DEAL::16 +DEAL::18 +DEAL::20 +DEAL::22 +DEAL::24 +DEAL::26 +DEAL::28 +DEAL::30 +DEAL::32 +DEAL::34 +DEAL::36 +DEAL::38