<commit_before>// ---------------------------------------------------------------------
//
// Copyright (C) 1998 - 2016 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 at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------

#include <deal.II/base/tensor.h>
#include <deal.II/grid/manifold.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/fe/fe_q.h>
#include <cmath>

DEAL_II_NAMESPACE_OPEN

using namespace Manifolds;

/* -------------------------- Manifold --------------------- */


template <int dim, int spacedim>
Manifold<dim, spacedim>::~Manifold ()
{}



template <int dim, int spacedim>
Point<spacedim>
Manifold<dim, spacedim>::
project_to_manifold (const std::vector<Point<spacedim> > &,
                     const Point<spacedim> &) const
{
  Assert (false, ExcPureFunctionCalled());
  return Point<spacedim>();
}



template <int dim, int spacedim>
Point<spacedim>
Manifold<dim, spacedim>::
get_new_point (const Quadrature<spacedim> &quad) const
{
  Assert(std::abs(std::accumulate(quad.get_weights().begin(), quad.get_weights().end(), 0.0)-1.0) < 1e-10,
         ExcMessage("The weights for the individual points should sum to 1!"));

  Point<spacedim> p;
  for (unsigned int i=0; i<quad.size(); ++i)
    p += quad.weight(i) * quad.point(i);

  return project_to_manifold(quad.get_points(), p);
}



template <>
Tensor<1,2>
Manifold<2, 2>::
normal_vector (const typename Triangulation<2, 2>::face_iterator &face,
               const Point<2> &p) const
{
  const int spacedim=2, dim=2;

  Tensor<1,spacedim> tangent = ((p-face->vertex(0)).norm_square() > (p-face->vertex(1)).norm_square() ?
                                -get_tangent_vector(p, face->vertex(0)) :
                                get_tangent_vector(p, face->vertex(1)));
  Tensor<1,spacedim> normal = cross_product_2d(tangent);
  return normal/normal.norm();
}

template<>
Tensor<1,3>
Manifold<3, 3>::
normal_vector (const typename Triangulation<3, 3>::face_iterator &face,
               const Point<3> &p) const
{
  const int spacedim=3, dim=3;
  Tensor<1,spacedim> t1,t2;

  // Take the difference between p and all four vertices
  int min_index=0;
  Tensor<1,spacedim> dp = p-face->vertex(0);
  double min_distance = dp.norm_square();

  for (unsigned int i=1; i<4; ++i)
    {
      dp = p-face->vertex(i);
      double distance = dp.norm_square();
      if (distance < min_distance)
        {
          min_index = i;
          min_distance = distance;
        }
    }
  // Verify we have a valid vertex index
  AssertIndexRange(min_index, 4);

  // now figure out which vertices are better to compute tangent vectors
  // we split the cell in 4 quadrants, and use v1/v2 for the first quadrant
  // (the one at the corner with vertex 0)
  if ((p-face->center()).norm_square() < min_distance)
    {
      // we are close to the face center: pick two consecutive vertices,
      // but not the closest one. We make sure the direction is always
      // the same.
      if (min_index < 2)
        {
          t1 = get_tangent_vector(p, face->vertex(3));
          t2 = get_tangent_vector(p, face->vertex(2));
        }
      else
        {
          t1 = get_tangent_vector(p, face->vertex(0));
          t2 = get_tangent_vector(p, face->vertex(1));
        }
    }
  else<commit_msg>Updated comment.<commit_after>// ---------------------------------------------------------------------
//
// Copyright (C) 1998 - 2016 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 at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------

#include <deal.II/base/tensor.h>
#include <deal.II/grid/manifold.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/fe/fe_q.h>
#include <cmath>

DEAL_II_NAMESPACE_OPEN

using namespace Manifolds;

/* -------------------------- Manifold --------------------- */


template <int dim, int spacedim>
Manifold<dim, spacedim>::~Manifold ()
{}



template <int dim, int spacedim>
Point<spacedim>
Manifold<dim, spacedim>::
project_to_manifold (const std::vector<Point<spacedim> > &,
                     const Point<spacedim> &) const
{
  Assert (false, ExcPureFunctionCalled());
  return Point<spacedim>();
}



template <int dim, int spacedim>
Point<spacedim>
Manifold<dim, spacedim>::
get_new_point (const Quadrature<spacedim> &quad) const
{
  Assert(std::abs(std::accumulate(quad.get_weights().begin(), quad.get_weights().end(), 0.0)-1.0) < 1e-10,
         ExcMessage("The weights for the individual points should sum to 1!"));

  Point<spacedim> p;
  for (unsigned int i=0; i<quad.size(); ++i)
    p += quad.weight(i) * quad.point(i);

  return project_to_manifold(quad.get_points(), p);
}



template <>
Tensor<1,2>
Manifold<2, 2>::
normal_vector (const typename Triangulation<2, 2>::face_iterator &face,
               const Point<2> &p) const
{
  const int spacedim=2, dim=2;

  Tensor<1,spacedim> tangent = ((p-face->vertex(0)).norm_square() > (p-face->vertex(1)).norm_square() ?
                                -get_tangent_vector(p, face->vertex(0)) :
                                get_tangent_vector(p, face->vertex(1)));
  Tensor<1,spacedim> normal = cross_product_2d(tangent);
  return normal/normal.norm();
}

template<>
Tensor<1,3>
Manifold<3, 3>::
normal_vector (const typename Triangulation<3, 3>::face_iterator &face,
               const Point<3> &p) const
{
  const int spacedim=3, dim=3;
  Tensor<1,spacedim> t1,t2;

  // Take the difference between p and all four vertices
  int min_index=0;
  Tensor<1,spacedim> dp = p-face->vertex(0);
  double min_distance = dp.norm_square();

  for (unsigned int i=1; i<4; ++i)
    {
      dp = p-face->vertex(i);
      double distance = dp.norm_square();
      if (distance < min_distance)
        {
          min_index = i;
          min_distance = distance;
        }
    }
  // Verify we have a valid vertex index
  AssertIndexRange(min_index, 4);

  // Now figure out which vertices are better to compute tangent vectors
  // we split the cell in 4 quadrants, and use the most orthogonal vertices
  // to the closest vertex if we ar far from the center, othewise we use
  // the two consecutive vertices, on the opposite side with respect to
  // the face center.
  if ((p-face->center()).norm_square() < min_distance)
    {
      // we are close to the face center: pick two consecutive vertices,
      // but not the closest one. We make sure the direction is always
      // the same.
      if (min_index < 2)
        {
          t1 = get_tangent_vector(p, face->vertex(3));
          t2 = get_tangent_vector(p, face->vertex(2));
        }
      else
        {
          t1 = get_tangent_vector(p, face->vertex(0));
          t2 = get_tangent_vector(p, face->vertex(1));
        }
    }
  else
{'fraction_non_alphanumeric': 0.1744382387323029, 'fraction_numerical': 0.016755422782179504, 'mean_word_length': 2.4904805077062555, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1272216', 'n_tokens_mistral': 2570, 'n_tokens_neox': 2433, 'n_words': 703}