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-gradient-sample-3d.cc 1.17 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/ellipticenergy.hh>

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

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

  SmallMatrix const A = { { 3, 1.5, 0 }, { 1.5, 4, 1.5 }, { 0, 1.5, 5 } };
  SmallVector const b = { 1, 2, 3 };

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

  double ret1;
  {
    SmallVector start = { 17, 34, 51 };
    ret1 = functionTester(J, start, 9);
  }

  double ret2;
  {
    // Something random
    SmallVector start = { 279, -96, -15 };
    ret2 = functionTester(J, start, 15);
  }
  assert(std::abs(ret1 - ret2) < 1e-5);

  double ret3;
  {
    SmallVector start = { 0, 0, 0 };
    ret3 = functionTester(J, start, 5);
  }
  assert(std::abs(ret1 - ret3) < 1e-5);
}