From: Daniel Arndt Date: Thu, 4 Jan 2018 17:07:09 +0000 (+0100) Subject: Simplify computation of normal vector in 2D X-Git-Tag: v9.0.0-rc1~602^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af62d180d7ad0fb5b6e6d51a1d7ec654ddc87edb;p=dealii.git Simplify computation of normal vector in 2D --- diff --git a/source/grid/manifold.cc b/source/grid/manifold.cc index b8bbbd2b3c..66bbb73ea4 100644 --- a/source/grid/manifold.cc +++ b/source/grid/manifold.cc @@ -821,6 +821,19 @@ normal_vector (const Triangulation<1,3>::face_iterator &, +template <> +Tensor<1,2> +FlatManifold<2,2>:: +normal_vector (const Triangulation<2,2>::face_iterator &face, + const Point<2> &p) const +{ + // In 2d, a face is just a straight line and + // we can use the 'standard' implementation. + return Manifold<2,2>::normal_vector(face, p); +} + + + template Tensor<1, spacedim> FlatManifold< dim, spacedim >:: diff --git a/tests/grid/normal_vector_03_2d.cc b/tests/grid/normal_vector_03_2d.cc index cef8054509..36ff98ccf5 100644 --- a/tests/grid/normal_vector_03_2d.cc +++ b/tests/grid/normal_vector_03_2d.cc @@ -63,7 +63,7 @@ int main () deallog << std::fixed; deallog.attach(logfile); - FE_Q<2> linear_interpolator(1); + FE_Q<1> linear_interpolator(1); Triangulation<2> tria; FlatManifold<2> boundary; @@ -80,30 +80,29 @@ int main () boundary.get_normals_at_vertices(face, normals); for (double xi=0; xi<=1; xi+=0.234) - for (double eta=0; eta<=1; eta+=0.234) - { - Point<2> p; - Tensor<1,2> normal; - - for (unsigned int v=0; v::vertices_per_face; ++v) - { - p += face->vertex(v) * linear_interpolator.shape_value(v,Point<2>(xi,eta)); - normal += normals[v] * - linear_interpolator.shape_value(v,Point<2>(xi,eta)); - } - normal /= normal.norm(); - - deallog << "p=" << p - << ", n=" << boundary.normal_vector (face, p) - << std::endl; - - Assert ((boundary.normal_vector (face, p) - - - normal).norm() - < - 1e-10, - ExcInternalError()); - } + { + Point<2> p; + Tensor<1,2> normal; + + for (unsigned int v=0; v::vertices_per_face; ++v) + { + p += face->vertex(v) * linear_interpolator.shape_value(v,Point<1>(xi)); + normal += normals[v] * + linear_interpolator.shape_value(v,Point<1>(xi)); + } + normal /= normal.norm(); + + deallog << "p=" << p + << ", n=" << boundary.normal_vector (face, p) + << std::endl; + + Assert ((boundary.normal_vector (face, p) + - + normal).norm() + < + 1e-10, + ExcInternalError()); + } } tria.clear(); diff --git a/tests/grid/normal_vector_03_2d.output b/tests/grid/normal_vector_03_2d.output index 08b58f8008..36a95b3286 100644 --- a/tests/grid/normal_vector_03_2d.output +++ b/tests/grid/normal_vector_03_2d.output @@ -1,204 +1,44 @@ DEAL::Case0 DEAL::p=1.000 1.000, n=1.000 0.000 -DEAL::p=0.766 0.766, n=1.000 0.000 -DEAL::p=0.532 0.532, n=1.000 0.000 -DEAL::p=0.298 0.298, n=1.000 0.000 -DEAL::p=0.064 0.064, n=1.000 0.000 DEAL::p=1.000 1.468, n=1.000 0.000 -DEAL::p=0.766 1.124, n=1.000 0.000 -DEAL::p=0.532 0.781, n=1.000 0.000 -DEAL::p=0.298 0.437, n=1.000 0.000 -DEAL::p=0.064 0.094, n=1.000 0.000 DEAL::p=1.000 1.936, n=1.000 0.000 -DEAL::p=0.766 1.483, n=1.000 0.000 -DEAL::p=0.532 1.030, n=1.000 0.000 -DEAL::p=0.298 0.577, n=1.000 0.000 -DEAL::p=0.064 0.124, n=1.000 0.000 DEAL::p=1.000 2.404, n=1.000 0.000 -DEAL::p=0.766 1.841, n=1.000 0.000 -DEAL::p=0.532 1.279, n=1.000 0.000 -DEAL::p=0.298 0.716, n=1.000 0.000 -DEAL::p=0.064 0.154, n=1.000 0.000 DEAL::p=1.000 2.872, n=1.000 0.000 -DEAL::p=0.766 2.200, n=1.000 0.000 -DEAL::p=0.532 1.528, n=1.000 0.000 -DEAL::p=0.298 0.856, n=1.000 0.000 -DEAL::p=0.064 0.184, n=1.000 0.000 DEAL::p=3.000 1.000, n=1.000 0.000 -DEAL::p=2.298 0.766, n=1.000 0.000 -DEAL::p=1.596 0.532, n=1.000 0.000 -DEAL::p=0.894 0.298, n=1.000 0.000 -DEAL::p=0.192 0.064, n=1.000 0.000 DEAL::p=3.000 1.468, n=1.000 0.000 -DEAL::p=2.298 1.124, n=1.000 0.000 -DEAL::p=1.596 0.781, n=1.000 0.000 -DEAL::p=0.894 0.437, n=1.000 0.000 -DEAL::p=0.192 0.094, n=1.000 0.000 DEAL::p=3.000 1.936, n=1.000 0.000 -DEAL::p=2.298 1.483, n=1.000 0.000 -DEAL::p=1.596 1.030, n=1.000 0.000 -DEAL::p=0.894 0.577, n=1.000 0.000 -DEAL::p=0.192 0.124, n=1.000 0.000 DEAL::p=3.000 2.404, n=1.000 0.000 -DEAL::p=2.298 1.841, n=1.000 0.000 -DEAL::p=1.596 1.279, n=1.000 0.000 -DEAL::p=0.894 0.716, n=1.000 0.000 -DEAL::p=0.192 0.154, n=1.000 0.000 DEAL::p=3.000 2.872, n=1.000 0.000 -DEAL::p=2.298 2.200, n=1.000 0.000 -DEAL::p=1.596 1.528, n=1.000 0.000 -DEAL::p=0.894 0.856, n=1.000 0.000 -DEAL::p=0.192 0.184, n=1.000 0.000 DEAL::p=1.000 1.000, n=0.000 -1.000 -DEAL::p=0.766 0.766, n=0.000 -1.000 -DEAL::p=0.532 0.532, n=0.000 -1.000 -DEAL::p=0.298 0.298, n=0.000 -1.000 -DEAL::p=0.064 0.064, n=0.000 -1.000 DEAL::p=1.468 1.000, n=0.000 -1.000 -DEAL::p=1.124 0.766, n=0.000 -1.000 -DEAL::p=0.781 0.532, n=0.000 -1.000 -DEAL::p=0.437 0.298, n=0.000 -1.000 -DEAL::p=0.094 0.064, n=0.000 -1.000 DEAL::p=1.936 1.000, n=0.000 -1.000 -DEAL::p=1.483 0.766, n=0.000 -1.000 -DEAL::p=1.030 0.532, n=0.000 -1.000 -DEAL::p=0.577 0.298, n=0.000 -1.000 -DEAL::p=0.124 0.064, n=0.000 -1.000 DEAL::p=2.404 1.000, n=0.000 -1.000 -DEAL::p=1.841 0.766, n=0.000 -1.000 -DEAL::p=1.279 0.532, n=0.000 -1.000 -DEAL::p=0.716 0.298, n=0.000 -1.000 -DEAL::p=0.154 0.064, n=0.000 -1.000 DEAL::p=2.872 1.000, n=0.000 -1.000 -DEAL::p=2.200 0.766, n=0.000 -1.000 -DEAL::p=1.528 0.532, n=0.000 -1.000 -DEAL::p=0.856 0.298, n=0.000 -1.000 -DEAL::p=0.184 0.064, n=0.000 -1.000 DEAL::p=1.000 3.000, n=0.000 -1.000 -DEAL::p=0.766 2.298, n=0.000 -1.000 -DEAL::p=0.532 1.596, n=0.000 -1.000 -DEAL::p=0.298 0.894, n=0.000 -1.000 -DEAL::p=0.064 0.192, n=0.000 -1.000 DEAL::p=1.468 3.000, n=0.000 -1.000 -DEAL::p=1.124 2.298, n=0.000 -1.000 -DEAL::p=0.781 1.596, n=0.000 -1.000 -DEAL::p=0.437 0.894, n=0.000 -1.000 -DEAL::p=0.094 0.192, n=0.000 -1.000 DEAL::p=1.936 3.000, n=0.000 -1.000 -DEAL::p=1.483 2.298, n=0.000 -1.000 -DEAL::p=1.030 1.596, n=0.000 -1.000 -DEAL::p=0.577 0.894, n=0.000 -1.000 -DEAL::p=0.124 0.192, n=0.000 -1.000 DEAL::p=2.404 3.000, n=0.000 -1.000 -DEAL::p=1.841 2.298, n=0.000 -1.000 -DEAL::p=1.279 1.596, n=0.000 -1.000 -DEAL::p=0.716 0.894, n=0.000 -1.000 -DEAL::p=0.154 0.192, n=0.000 -1.000 DEAL::p=2.872 3.000, n=0.000 -1.000 -DEAL::p=2.200 2.298, n=0.000 -1.000 -DEAL::p=1.528 1.596, n=0.000 -1.000 -DEAL::p=0.856 0.894, n=0.000 -1.000 -DEAL::p=0.184 0.192, n=0.000 -1.000 DEAL::Case1 DEAL::p=-0.500 -1.000, n=0.936 -0.351 -DEAL::p=-0.383 -0.766, n=0.936 -0.351 -DEAL::p=-0.266 -0.532, n=0.936 -0.351 -DEAL::p=-0.149 -0.298, n=0.936 -0.351 -DEAL::p=-0.032 -0.064, n=0.936 -0.351 DEAL::p=-0.149 -0.064, n=0.936 -0.351 -DEAL::p=-0.114 -0.049, n=0.936 -0.351 -DEAL::p=-0.079 -0.034, n=0.936 -0.351 -DEAL::p=-0.044 -0.019, n=0.936 -0.351 -DEAL::p=-0.010 -0.004, n=0.936 -0.351 DEAL::p=0.202 0.872, n=0.936 -0.351 -DEAL::p=0.155 0.668, n=0.936 -0.351 -DEAL::p=0.107 0.464, n=0.936 -0.351 -DEAL::p=0.060 0.260, n=0.936 -0.351 -DEAL::p=0.013 0.056, n=0.936 -0.351 DEAL::p=0.553 1.808, n=0.936 -0.351 -DEAL::p=0.424 1.385, n=0.936 -0.351 -DEAL::p=0.294 0.962, n=0.936 -0.351 -DEAL::p=0.165 0.539, n=0.936 -0.351 -DEAL::p=0.035 0.116, n=0.936 -0.351 DEAL::p=0.904 2.744, n=0.936 -0.351 -DEAL::p=0.692 2.102, n=0.936 -0.351 -DEAL::p=0.481 1.460, n=0.936 -0.351 -DEAL::p=0.269 0.818, n=0.936 -0.351 -DEAL::p=0.058 0.176, n=0.936 -0.351 DEAL::p=1.250 0.250, n=0.844 -0.537 -DEAL::p=0.958 0.192, n=0.844 -0.537 -DEAL::p=0.665 0.133, n=0.844 -0.537 -DEAL::p=0.372 0.074, n=0.844 -0.537 -DEAL::p=0.080 0.016, n=0.844 -0.537 DEAL::p=1.659 0.894, n=0.844 -0.537 -DEAL::p=1.271 0.684, n=0.844 -0.537 -DEAL::p=0.883 0.475, n=0.844 -0.537 -DEAL::p=0.495 0.266, n=0.844 -0.537 -DEAL::p=0.106 0.057, n=0.844 -0.537 DEAL::p=2.069 1.537, n=0.844 -0.537 -DEAL::p=1.585 1.177, n=0.844 -0.537 -DEAL::p=1.101 0.818, n=0.844 -0.537 -DEAL::p=0.617 0.458, n=0.844 -0.537 -DEAL::p=0.132 0.098, n=0.844 -0.537 DEAL::p=2.479 2.181, n=0.844 -0.537 -DEAL::p=1.899 1.670, n=0.844 -0.537 -DEAL::p=1.319 1.160, n=0.844 -0.537 -DEAL::p=0.739 0.650, n=0.844 -0.537 -DEAL::p=0.159 0.140, n=0.844 -0.537 DEAL::p=2.888 2.824, n=0.844 -0.537 -DEAL::p=2.212 2.163, n=0.844 -0.537 -DEAL::p=1.536 1.502, n=0.844 -0.537 -DEAL::p=0.861 0.842, n=0.844 -0.537 -DEAL::p=0.185 0.181, n=0.844 -0.537 DEAL::p=-0.500 -1.000, n=0.581 -0.814 -DEAL::p=-0.383 -0.766, n=0.581 -0.814 -DEAL::p=-0.266 -0.532, n=0.581 -0.814 -DEAL::p=-0.149 -0.298, n=0.581 -0.814 -DEAL::p=-0.032 -0.064, n=0.581 -0.814 DEAL::p=-0.090 -0.708, n=0.581 -0.814 -DEAL::p=-0.069 -0.542, n=0.581 -0.814 -DEAL::p=-0.048 -0.376, n=0.581 -0.814 -DEAL::p=-0.027 -0.211, n=0.581 -0.814 -DEAL::p=-0.006 -0.045, n=0.581 -0.814 DEAL::p=0.319 -0.415, n=0.581 -0.814 -DEAL::p=0.244 -0.318, n=0.581 -0.814 -DEAL::p=0.170 -0.221, n=0.581 -0.814 -DEAL::p=0.095 -0.124, n=0.581 -0.814 -DEAL::p=0.020 -0.027, n=0.581 -0.814 DEAL::p=0.729 -0.122, n=0.581 -0.814 -DEAL::p=0.558 -0.094, n=0.581 -0.814 -DEAL::p=0.388 -0.065, n=0.581 -0.814 -DEAL::p=0.217 -0.037, n=0.581 -0.814 -DEAL::p=0.047 -0.008, n=0.581 -0.814 DEAL::p=1.138 0.170, n=0.581 -0.814 -DEAL::p=0.872 0.130, n=0.581 -0.814 -DEAL::p=0.605 0.090, n=0.581 -0.814 -DEAL::p=0.339 0.051, n=0.581 -0.814 -DEAL::p=0.073 0.011, n=0.581 -0.814 DEAL::p=1.000 3.000, n=0.000 -1.000 -DEAL::p=0.766 2.298, n=0.000 -1.000 -DEAL::p=0.532 1.596, n=0.000 -1.000 -DEAL::p=0.298 0.894, n=0.000 -1.000 -DEAL::p=0.064 0.192, n=0.000 -1.000 DEAL::p=1.468 3.000, n=0.000 -1.000 -DEAL::p=1.124 2.298, n=0.000 -1.000 -DEAL::p=0.781 1.596, n=0.000 -1.000 -DEAL::p=0.437 0.894, n=0.000 -1.000 -DEAL::p=0.094 0.192, n=0.000 -1.000 DEAL::p=1.936 3.000, n=0.000 -1.000 -DEAL::p=1.483 2.298, n=0.000 -1.000 -DEAL::p=1.030 1.596, n=0.000 -1.000 -DEAL::p=0.577 0.894, n=0.000 -1.000 -DEAL::p=0.124 0.192, n=0.000 -1.000 DEAL::p=2.404 3.000, n=0.000 -1.000 -DEAL::p=1.841 2.298, n=0.000 -1.000 -DEAL::p=1.279 1.596, n=0.000 -1.000 -DEAL::p=0.716 0.894, n=0.000 -1.000 -DEAL::p=0.154 0.192, n=0.000 -1.000 DEAL::p=2.872 3.000, n=0.000 -1.000 -DEAL::p=2.200 2.298, n=0.000 -1.000 -DEAL::p=1.528 1.596, n=0.000 -1.000 -DEAL::p=0.856 0.894, n=0.000 -1.000 -DEAL::p=0.184 0.192, n=0.000 -1.000 DEAL::OK