Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
test-gradient-sample-steep.cc 1.07 KiB
/* Checks if the algorithm converges regardless of where it starts */

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

#include <cassert>

#include <dune/common/shared_ptr.hh>

#include <dune/tectonic/samplefunctional.hh>

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

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

  Functional::SmallMatrix A;
  A[0][0] = 1;
  A[0][1] = A[1][0] = 0;
  A[1][1] = 1;
  Functional::SmallVector b;
  b[0] = 1;
  b[1] = 2;

  auto f = Dune::make_shared<Dune::SampleFunction<2> const>();
  auto phi = Dune::make_shared<Functional::NonlinearityType const>(f);
  Functional J(A, b, phi);

  Functional::SmallVector start;

  start[0] = 0;
  start[1] = 1;

  double const ret1 = functionTester(J, start, 5);

  // Something random
  start[0] = 279;
  start[1] = -96;

  double const ret2 = functionTester(J, start, 5);
  assert(std::abs(ret1 - ret2) < 1e-7);

  start[0] = 0;
  start[1] = 0;

  double const ret3 = functionTester(J, start, 1);
  assert(std::abs(ret1 - ret3) < 1e-7);
}