From: Patrick Esser Date: Thu, 21 Apr 2016 15:16:17 +0000 (+0200) Subject: add test for newton debug vector sizes and astyle X-Git-Tag: v8.5.0-rc1~1088^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69f785e70be5c96b4c0fd5126769bc816f8fe5ff;p=dealii.git add test for newton debug vector sizes and astyle --- diff --git a/tests/algorithms/newton_02.cc b/tests/algorithms/newton_02.cc new file mode 100644 index 0000000000..140fd3325b --- /dev/null +++ b/tests/algorithms/newton_02.cc @@ -0,0 +1,122 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 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 + + +// verify that all debug vectors have the correct size + +using namespace dealii; +using namespace Algorithms; + +template +class TestOutputOperator : public OutputOperator +{ +public: + void initialize(const DoFHandler &dof_handler) + { + dof = &dof_handler; + } + + virtual OutputOperator &operator<<(const AnyData &vectors) + { + for (unsigned int i=0; i(i); + if (p!=0) + { + // this should be equal to dof->n_dofs() otherwise + // DoFOutputOperator will complain + deallog << p->size() << std::endl; + } + } + return *this; + } + +private: + SmartPointer, + TestOutputOperator > dof; +}; + +class ZeroResidual : public Algorithms::OperatorBase +{ +public: + virtual void operator ()(AnyData &out, const AnyData &in) + { + const Vector &in_vector = *in.entry*>( + "Newton iterate"); + Vector &out_vector = *out.entry*>(0); + out_vector.reinit(in_vector.size()); + } +}; + +class IdentitySolver : public Algorithms::OperatorBase +{ +public: + virtual void operator ()(AnyData &out, const AnyData &in) + { + const Vector &in_vector = *in.entry*>( + "Newton residual"); + Vector &out_vector = *out.entry*>(0); + out_vector = in_vector; + } +}; + + +template +void test() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, -1, 1); + tria.refine_global(1); + + FE_Q fe(1); + DoFHandler dofh(tria); + dofh.distribute_dofs(fe); + + TestOutputOperator, dim> output_operator; + output_operator.initialize(dofh); + + IdentitySolver solver; + ZeroResidual residual; + + Algorithms::Newton > newton(residual, solver); + newton.initialize(output_operator); + + AnyData in_data; + AnyData out_data; + + Vector solution(dofh.n_dofs()); + out_data.add*>(&solution, "solution"); + + newton.debug_vectors = true; + newton(out_data, in_data); +} + + +int main() +{ + std::string logname = "output"; + std::ofstream logfile(logname.c_str()); + deallog.attach(logfile); + deallog.threshold_double(1.e-10); + + test<2>(); +} diff --git a/tests/algorithms/newton_02.output b/tests/algorithms/newton_02.output new file mode 100644 index 0000000000..ec965057fe --- /dev/null +++ b/tests/algorithms/newton_02.output @@ -0,0 +1,5 @@ + +DEAL:Newton::9 +DEAL:Newton::9 +DEAL:Newton::9 +DEAL:Newton::Convergence step 0 value 0