Skip to content
Snippets Groups Projects
Forked from agnumpde / dune-tectonic
673 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
test-minimise2.cc 1.60 KiB
/* Check that minimise2 always produces better results than minimise
   when the latter starts from 0 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <cassert>

#include <boost/format.hpp>

#include <dune/common/shared_ptr.hh>

#include <dune/tectonic/ellipticenergy.hh>

#include "test-gradient-method-nicefunction.hh"
#include "test-gradient-method-helper.hh"

int main() {
  int const dim = 2;
  typedef Dune::EllipticEnergy<dim> Functional;
  typedef Functional::SmallMatrix SmallMatrix;
  typedef Functional::SmallVector SmallVector;

  SmallMatrix const A = { { 4, 1.5 }, { 1.5, 3 } };

  std::vector<SmallVector> const bs = {
    { 1, 2 }, { -8, -14 }, { -16, -28 }, { -24, -42 }, { -32, -56 },
  };

  auto const f = Dune::make_shared<Dune::ThreeKinkFunction const>();
  auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);

  std::vector<Functional> const Js = { Functional(A, bs[0], phi),
                                       Functional(A, bs[1], phi),
                                       Functional(A, bs[2], phi),
                                       Functional(A, bs[3], phi),
                                       Functional(A, bs[4], phi) };

  Bisection const bisection(0.0, 1.0, 1e-12, false, 0);

  size_t const runs = 5;

  SmallVector x;

  for (auto const &J : Js) {
    x = { 0, 0 };
    Dune::minimise(J, x, runs, bisection);
    double const xmin = J(x);

    x = { 0, 0 };
    Dune::minimise2(J, x, runs, bisection);
    double const xmin2 = J(x);
    std::cout << xmin << std::endl;
    std::cout << xmin2 << std::endl << std::endl;
    assert(xmin2 <= xmin);
  }
}