<commit_before>// This file is part of the dune-gdt project:
//   https://github.com/dune-community/dune-gdt
// Copyright 2010-2018 dune-gdt developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
//      or  GPL-2.0+ (http://opensource.org/licenses/gpl-license)
//          with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
//   <NAME> (2018)
//   <NAME>     (2018)

#ifndef DUNE_GDT_SPACES_H1_CONTINUOUS_LAGRANGE_HH
#define DUNE_GDT_SPACES_H1_CONTINUOUS_LAGRANGE_HH

#include <memory>
#include <vector>

#include <dune/common/typetraits.hh>

#include <dune/geometry/type.hh>

#include <dune/grid/common/gridview.hh>

#include <dune/xt/common/exceptions.hh>

#include <dune/gdt/local/finite-elements/lagrange.hh>
#include <dune/gdt/spaces/basis/default.hh>
#include <dune/gdt/spaces/mapper/continuous.hh>
#include <dune/gdt/spaces/interface.hh>

namespace Dune {
namespace GDT {


/**
 * The following dimensions/orders/elements are tested to work:
 *
 * - 1d: orders 1, 2 work
 * - 2d: orders 1, 2 work on simplices, cubes and mixed simplices and cubes
 * - 3d: orders 1, 2 work on simplices, cubes, prisms
 *
 * The following dimensions/orders/elements are tested to fail:
 *
 * - 3d: pyramids (jacobians seem to be incorrect)
 * - 3d: mixed simplices and cubes (intersections are non-conforming)
 *
 * \sa make_local_lagrange_finite_element
 */
template <class GV, class R = double>
class ContinuousLagrangeSpace : public SpaceInterface<GV, 1, 1, R>
{
  using ThisType = ContinuousLagrangeSpace<GV, R>;
  using BaseType = SpaceInterface<GV, 1, 1, R>;

public:
  using BaseType::d;
  using typename BaseType::D;
  using typename BaseType::FiniteElementType;
  using typename BaseType::GlobalBasisType;
  using typename BaseType::GridViewType;
  using typename BaseType::MapperType;

private:
  using MapperImplementation = ContinuousMapper<GridViewType, FiniteElementType>;
  using GlobalBasisImplementation = DefaultGlobalBasis<GridViewType, 1, 1, R>;

public:
  ContinuousLagrangeSpace(GridViewType grd_vw, const int order)
    : grid_view_(grd_vw)
    , order_(order)
    , finite_elements_(new std::map<GeometryType, std::shared_ptr<FiniteElementType>>())
    , mapper_(nullptr)
    , basis_(nullptr)
  {
    // create finite elements
    for (auto&& geometry_type : grid_view_.indexSet().types(0))
      finite_elements_->insert(
          std::make_pair(geometry_type, make_local_lagrange_finite_element<D, d, R>(geometry_type, order)));
    // check
    if (d == 3 && finite_elements_->size() != 1)
      DUNE_THROW(Exceptions::space_error,
                 "when creating a ContinuousLagrangeSpace: non-conforming intersections are not (yet) "
                 "supported, and more than one element type in 3d leads to non-conforming intersections!");
    // create mapper, basis and communicator
    mapper_ = std::make_shared<MapperImplementation>(grid_view_, finite_elements_);
    basis_ = std::make_shared<GlobalBasisImplementation>(grid_view_, finite_elements_);
    this->create_communicator();
  } // ContinuousLagrangeSpace(...)

  ContinuousLagrangeSpace(const ThisType&) = default;
  ContinuousLagrangeSpace(ThisType&&) = default;

  ThisType& operator=(const ThisType&) = delete;
  ThisType& operator=(ThisType&&) = delete;

  const GridViewType& grid_view() const override final
  {
    return grid_view_;
  }

  const MapperType& mapper() const override final
  {
    return *mapper_;
  }<commit_msg>[spaces.h1.cg] disallow higher order and alugrid, refs #144<commit_after>// This file is part of the dune-gdt project:
//   https://github.com/dune-community/dune-gdt
// Copyright 2010-2018 dune-gdt developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
//      or  GPL-2.0+ (http://opensource.org/licenses/gpl-license)
//          with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
//   <NAME> (2018)
//   <NAME>     (2018)

#ifndef DUNE_GDT_SPACES_H1_CONTINUOUS_LAGRANGE_HH
#define DUNE_GDT_SPACES_H1_CONTINUOUS_LAGRANGE_HH

// see https://github.com/dune-community/dune-gdt/issues/144
#ifndef DUNE_GDT_SPACES_H1_CONTINUOUS_LAGRANGE_IGNORE_FAILING_ALUGRID
#  define DUNE_GDT_SPACES_H1_CONTINUOUS_LAGRANGE_IGNORE_FAILING_ALUGRID 0
#endif

#include <memory>
#include <vector>

#include <dune/common/typetraits.hh>

#include <dune/geometry/type.hh>

#include <dune/grid/common/gridview.hh>

#include <dune/xt/common/exceptions.hh>
#include <dune/xt/grid/type_traits.hh>

#include <dune/gdt/local/finite-elements/lagrange.hh>
#include <dune/gdt/spaces/basis/default.hh>
#include <dune/gdt/spaces/mapper/continuous.hh>
#include <dune/gdt/spaces/interface.hh>

namespace Dune {
namespace GDT {


/**
 * The following dimensions/orders/elements are tested to work:
 *
 * - 1d: orders 1, 2 work
 * - 2d: orders 1, 2 work on simplices, cubes and mixed simplices and cubes
 * - 3d: orders 1, 2 work on simplices, cubes, prisms
 *
 * The following dimensions/orders/elements are tested to fail:
 *
 * - 3d: pyramids (jacobians seem to be incorrect)
 * - 3d: mixed simplices and cubes (intersections are non-conforming)
 *
 * \sa make_local_lagrange_finite_element
 */
template <class GV, class R = double>
class ContinuousLagrangeSpace : public SpaceInterface<GV, 1, 1, R>
{
  using ThisType = ContinuousLagrangeSpace<GV, R>;
  using BaseType = SpaceInterface<GV, 1, 1, R>;

public:
  using BaseType::d;
  using typename BaseType::D;
  using typename BaseType::FiniteElementType;
  using typename BaseType::GlobalBasisType;
  using typename BaseType::GridViewType;
  using typename BaseType::MapperType;

private:
  using MapperImplementation = ContinuousMapper<GridViewType, FiniteElementType>;
  using GlobalBasisImplementation = DefaultGlobalBasis<GridViewType, 1, 1, R>;

public:
  ContinuousLagrangeSpace(GridViewType grd_vw, const int order)
    : grid_view_(grd_vw)
    , order_(order)
    , finite_elements_(new std::map<GeometryType, std::shared_ptr<FiniteElementType>>())
    , mapper_(nullptr)
    , basis_(nullptr)
  {
#if !DUNE_GDT_SPACES_H1_CONTINUOUS_LAGRANGE_IGNORE_FAILING_ALUGRID
    // see https://github.com/dune-community/dune-gdt/issues/144
    DUNE_THROW_IF(XT::Grid::is_alugrid<typename GridViewType::Grid>::value && order > 1,
                  Exceptions::space_error,
                  "Higher order CG spaces do not work with alugrid atm, see "
                  "https://github.com/dune-community/dune-gdt/issues/144!");
#endif
    // create finite elements
    for (auto&& geometry_type : grid_view_.indexSet().types(0))
      finite_elements_->insert(
          std::make_pair(geometry_type, make_local_lagrange_finite_element<D, d, R>(geometry_type, order)));
    // check
    if (d == 3 && finite_elements_->size() != 1)
      DUNE_THROW(Exceptions::space_error,
                 "when creating a ContinuousLagrangeSpace: non-conforming intersections are not (yet) "
                 "supported, and more than one element type in 3d leads to non-conforming intersections!");
    // create mapper, basis and communicator
    mapper_ = std::make_shared<MapperImplementation>(grid_view_, finite_elements_);
    basis_ = std::make_shared<GlobalBasisImplementation>(grid_view_, finite_elements_);
    this->create_communicator();
  } // ContinuousLagrangeSpace(...)

  ContinuousLagrangeSpace(const ThisType&) = default;
  ContinuousLagrangeSpace(ThisType&&) = default;

  ThisType& operator=(const ThisType&) = delete;
  ThisType& operator=(ThisType&&) = delete;

  const GridViewType& grid_view() const override final
  {
    return grid_view_;
  }

  const MapperType& mapper() const override final
  {
    return *mapper_;
  }
{'fraction_non_alphanumeric': 0.11581776298950601, 'fraction_numerical': 0.013309444586639366, 'mean_word_length': 4.262626262626263, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 58, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, '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': '6601169', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2562, 'n_words': 585}