From: Guido Kanschat Date: Mon, 10 Mar 2014 11:36:32 +0000 (+0000) Subject: move Newton test and add test in compatibility mode X-Git-Tag: v8.2.0-rc1~709 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a612b6c68a783930ab4e5eea9c33b135ea3f191e;p=dealii.git move Newton test and add test in compatibility mode git-svn-id: https://svn.dealii.org/trunk@32638 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/algorithms/newton_01.cc b/tests/algorithms/newton_01.cc new file mode 100644 index 0000000000..e665a58556 --- /dev/null +++ b/tests/algorithms/newton_01.cc @@ -0,0 +1,132 @@ +// --------------------------------------------------------------------- +// $Id$ +// +// Copyright (C) 2008 - 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +#include "../tests.h" +#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 (AnyData &out, const AnyData &in); + void solve (AnyData &out, const AnyData &in); +}; + +class SquareRootResidual : public + Algorithms::Operator > +{ + SmartPointer + discretization; +public: + + SquareRootResidual(SquareRoot &problem) + : discretization(&problem) + {} + + virtual void operator ()(AnyData &out, const AnyData &in) + { + discretization->residual(out,in); + } +}; + +class SquareRootSolver : public + Algorithms::Operator > +{ + SmartPointer + solver; +public: + + SquareRootSolver(SquareRoot &problem) + : solver(&problem) + {} + + virtual void operator ()(AnyData &out, const AnyData &in) + { + solver->solve(out,in); + } +}; + +void SquareRoot::residual (AnyData &out, const AnyData &in) +{ + Vector& v = *out.entry*>(0); + //residuum = 0 + v(0) = 0.; + const Vector &x = *in.entry*>("Newton iterate"); + v(0) = x*x - 2.; +} + +void SquareRoot::solve (AnyData &out, const AnyData &in) +{ + Vector& v = *out.entry*>(0); + v(0) = 0; + const Vector &x = *in.entry*>("Newton iterate"); + const Vector &r = *in.entry*>("Newton residual"); + + v(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::string logname = "output"; + std::ofstream logfile(logname.c_str()); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + test (); +} diff --git a/tests/deal.II/newton_01.output b/tests/algorithms/newton_01.output similarity index 100% rename from tests/deal.II/newton_01.output rename to tests/algorithms/newton_01.output diff --git a/tests/deal.II/newton_01.cc b/tests/algorithms/newton_01_compat.cc similarity index 100% rename from tests/deal.II/newton_01.cc rename to tests/algorithms/newton_01_compat.cc diff --git a/tests/algorithms/newton_01_compat.output b/tests/algorithms/newton_01_compat.output new file mode 100644 index 0000000000..38c1c23723 --- /dev/null +++ b/tests/algorithms/newton_01_compat.output @@ -0,0 +1,12 @@ + +DEAL:Newton::Check 0 98.0000 +DEAL:Newton::Starting value 98.0000 +DEAL:Newton::Check 1 24.0100 +DEAL:Newton::Check 2 5.54095 +DEAL:Newton::Check 3 1.01785 +DEAL:Newton::Check 4 0.0858237 +DEAL:Newton::Check 5 0.000882829 +DEAL:Newton::Check 6 9.73804e-08 +DEAL:Newton::Check 7 0 +DEAL:Newton::Convergence step 7 value 0 +DEAL:: square root 1.41421