From: Martin Kronbichler Date: Tue, 5 Mar 2019 17:41:56 +0000 (+0100) Subject: Add test for EllipticalManifold::push_forward_gradient X-Git-Tag: v9.1.0-rc1~303^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b65307e98f613676fad3935851ee89743d6a7d37;p=dealii.git Add test for EllipticalManifold::push_forward_gradient --- diff --git a/tests/manifold/elliptical_manifold_03.cc b/tests/manifold/elliptical_manifold_03.cc new file mode 100644 index 0000000000..ad72999421 --- /dev/null +++ b/tests/manifold/elliptical_manifold_03.cc @@ -0,0 +1,78 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Check gradient of elliptical manifold + +#include "../tests.h" + + +// all include files you need here +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + + + +int +main() +{ + initlog(); + + deallog << std::setprecision(10); + + // setup elliptical manifold + const Tensor<1, 2> major_axis({2.0, 1.0}); + const Point<2> center(7.0, 6.0); + const double eccentricity = 0.1; + + const EllipticalManifold<2> ellipse(center, major_axis, eccentricity); + + // reference point for computing gradient + const Point<2> chart_point(1.0, 0.25 * numbers::PI); + + // compute gradient by central finite differences + const double h = 1e-6; + const Point<2> chart_point_plusc(chart_point[0] + h, chart_point[1]); + const Point<2> chart_point_minusc(chart_point[0] - h, chart_point[1]); + const Point<2> chart_point_plusphi(chart_point[0], chart_point[1] + h); + const Point<2> chart_point_minusphi(chart_point[0], chart_point[1] - h); + + const Point<2> space_point_plusc = ellipse.push_forward(chart_point_plusc); + const Point<2> space_point_minusc = ellipse.push_forward(chart_point_minusc); + const Point<2> space_point_plusphi = + ellipse.push_forward(chart_point_plusphi); + const Point<2> space_point_minusphi = + ellipse.push_forward(chart_point_minusphi); + + deallog << "Gradient by finite differences: " + << (space_point_plusc - space_point_minusc) / (2.0 * h) << " " + << (space_point_plusphi - space_point_minusphi) / (2.0 * h) + << std::endl; + deallog << "Analytic gradient: " + << transpose(Tensor<2, 2>(ellipse.push_forward_gradient(chart_point))) + << std::endl; + + return 0; +} diff --git a/tests/manifold/elliptical_manifold_03.output b/tests/manifold/elliptical_manifold_03.output new file mode 100644 index 0000000000..602c91bbc8 --- /dev/null +++ b/tests/manifold/elliptical_manifold_03.output @@ -0,0 +1,3 @@ + +DEAL::Gradient by finite differences: 3.178128775 9.455130749 -9.470981865 3.130575430 +DEAL::Analytic gradient: 3.178128776 9.455130749 -9.470981865 3.130575429