<commit_before>// This file is part of the dune-gdt project:
//   http://users.dune-project.org/projects/dune-gdt
// Copyright holders: <NAME>
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

#ifndef DUNE_GDT_SPACES_CONSTRAINTS_HH
#define DUNE_GDT_SPACES_CONSTRAINTS_HH

#include <dune/common/dynvector.hh>
#include <dune/stuff/common/disable_warnings.hh>
# include <dune/common/dynmatrix.hh>
#include <dune/stuff/common/reenable_warnings.hh>

#include <dune/stuff/grid/boundaryinfo.hh>

namespace Dune {
namespace GDT {
namespace Constraints {


template< class RangeFieldImp = double >
class LocalDefault
{
public:
  typedef RangeFieldImp RangeFieldType;

private:
  typedef Dune::DynamicVector< size_t >         IndicesType;
  typedef Dune::DynamicMatrix< RangeFieldType > ValuesType;

public:
  LocalDefault(const size_t numRows,
               const size_t numCols)
    : rows_(numRows)
    , cols_(numCols)
    , globalRows_(rows_)
    , globalCols_(cols_)
    , values_(rows_, cols_)
  {}

  virtual ~LocalDefault() {}

  virtual size_t rows() const
  {
    return rows_;
  }

  virtual size_t cols() const
  {
    return cols_;
  }

  void setSize(const size_t rr, const size_t cc)
  {
    rows_ = rr;
    cols_ = cc;
    bool changed = false;
    if (rows_ > globalRows_.size()) {
      globalRows_.resize(rows_, 0);
      changed = true;
    }
    if (cols_ > globalCols_.size()) {
      globalCols_.resize(cols_, 0);
      changed = true;
    }
    if (changed)
      values_.resize(globalRows_.size(), globalCols_.size(), 0);
  } // ... setSize(...)

  virtual size_t& globalRow(const size_t ii)
  {
    assert(ii < std::min(rows_, globalRows_.size()));
    return globalRows_[ii];
  }

  virtual const size_t& globalRow(const size_t ii) const
  {
    assert(ii < std::min(rows_, globalRows_.size()));
    return globalRows_[ii];
  }

  virtual size_t& globalCol(const size_t jj)
  {
    assert(jj < std::min(cols_, globalCols_.size()));
    return globalCols_[jj];
  }

  virtual const size_t& globalCol(const size_t jj) const
  {
    assert(jj < std::min(cols_, globalCols_.size()));
    return globalCols_[jj];
  }

  virtual RangeFieldType& value(const size_t ii, const size_t jj)
  {
    assert(ii < std::min(rows_, globalRows_.size()));
    assert(jj < std::min(cols_, globalCols_.size()));
    return values_[ii][jj];
  }

  virtual const RangeFieldType& value(const size_t ii, const size_t jj) const
  {
    assert(ii < std::min(rows_, globalRows_.size()));
    assert(jj < std::min(cols_, globalCols_.size()));
    return values_[ii][jj];
  }

private:
  size_t rows_;
  size_t cols_;
  IndicesType globalRows_;
  IndicesType globalCols_;
  ValuesType values_;
}; // class LocalDefault


template< class IntersectionType, class RangeFieldImp = double, bool setRow = true >
class Dirichlet
  : public LocalDefault< RangeFieldImp >
{
public:
  typedef LocalDefault< RangeFieldImp > BaseType;
  typedef Dune::Stuff::Grid::BoundaryInfoInterface< IntersectionType > GridBoundaryType;

  Dirichlet(const GridBoundaryType& gB,
            const size_t numRows,
            const size_t numCols)
    : BaseType(numRows, numCols)
    , gridBoundary_(gB)
  {}

  ~Dirichlet() {}

  const GridBoundaryType& gridBoundary() const
  {
    return gridBoundary_;
  }

private:
  const GridBoundaryType& gridBoundary_;
}; // class Dirichlet


} // namespace Constraints
} // namespace GDT
} // namespace Dune

#endif // DUNE_GDT_SPACES_CONSTRAINTS_HH<commit_msg>[spaces.constraints] added ConstraintsInterface<commit_after>// This file is part of the dune-gdt project:
//   http://users.dune-project.org/projects/dune-gdt
// Copyright holders: <NAME>
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

#ifndef DUNE_GDT_SPACES_CONSTRAINTS_HH
#define DUNE_GDT_SPACES_CONSTRAINTS_HH

#include <dune/stuff/common/disable_warnings.hh>
# include <dune/common/dynvector.hh>
# include <dune/common/dynmatrix.hh>
#include <dune/stuff/common/reenable_warnings.hh>

#include <dune/stuff/grid/boundaryinfo.hh>
#include <dune/stuff/common/crtp.hh>

namespace Dune {
namespace GDT {
namespace Spaces {


template< class ValueImp >
class ConstraintsInterface
{
public:
  typedef ValueImp ValueType;

  virtual ~ConstraintsInterface() {}

  virtual size_t rows() const = 0;

  virtual size_t cols() const = 0;

  virtual size_t global_row(const size_t ii) const = 0;

  virtual size_t global_col(const size_t jj) const = 0;

  virtual ValueType value(const size_t ii, const size_t jj) const = 0;
}; // class ConstraintsInterface


namespace Constraints {
namespace internal {


template< class ValueImp >
class Default
  : public ConstraintsInterface< ValueImp >
{
  typedef ConstraintsInterface< ValueImp > BaseType;
public:
  typedef typename BaseType::ValueType ValueType;

private:
  typedef DynamicVector< size_t >    IndicesType;
  typedef DynamicMatrix< ValueType > ValuesType;

public:
  Default(const size_t rws, const size_t cls)
    : rows_(rws)
    , cols_(cls)
    , global_rows_(rows_)
    , global_cols_(cols_)
    , values_(rows_, cols_)
  {}

  virtual ~Default() {}

  virtual size_t rows() const DS_OVERRIDE
  {
    return rows_;
  }

  virtual size_t cols() const DS_OVERRIDE
  {
    return cols_;
  }

  void set_size(const size_t rr, const size_t cc)
  {
    rows_ = rr;
    cols_ = cc;
    bool changed = false;
    if (rows_ > global_rows_.size()) {
      global_rows_.resize(rows_, 0);
      changed = true;
    }
    if (cols_ > global_cols_.size()) {
      global_cols_.resize(cols_, 0);
      changed = true;
    }
    if (changed)
      values_.resize(global_rows_.size(), global_cols_.size(), 0);
    assert(global_rows_.size() == rows_);
    assert(global_cols_.size() == cols_);
  } // ... set_size(...)

  size_t& global_row(const size_t ii)
  {
    assert(ii < rows_);
    return global_rows_[ii];
  }

  virtual size_t global_row(const size_t ii) const DS_OVERRIDE
  {
    assert(ii < rows_);
    return global_rows_[ii];
  }

  size_t& global_col(const size_t jj)
  {
    assert(jj < cols_);
    return global_cols_[jj];
  }

  virtual size_t global_col(const size_t jj) const
  {
    assert(jj < cols_);
    return global_cols_[jj];
  }

  ValueType& value(const size_t ii, const size_t jj)
  {
    assert(ii < rows_);
    assert(jj < cols_);
    return values_[ii][jj];
  }

  virtual ValueType value(const size_t ii, const size_t jj) const DS_OVERRIDE
  {
    assert(ii < rows_);
    assert(jj < cols_);
    return values_[ii][jj];
  }

private:
  size_t rows_;
  size_t cols_;
  IndicesType global_rows_;
  IndicesType global_cols_;
  ValuesType values_;
}; // class Default


} // namespace internal


template< class IntersectionType, class ValueImp = double, bool setRow = true >
class Dirichlet
  : public internal::Default< ValueImp >
{
public:
  typedef internal::Default< ValueImp > BaseType;
  typedef Stuff::Grid::BoundaryInfoInterface< IntersectionType > BoundaryInfoType;

  Dirichlet(const BoundaryInfoType& bound_info, const size_t rws, const size_t cls)
    : BaseType(rws, cls)
    , boundary_info_(bound_info)
  {}

  virtual ~Dirichlet() {}

  const BoundaryInfoType& boundary_info() const
  {
    return boundary_info_;
  }

private:
  const BoundaryInfoType& boundary_info_;
}; // class Dirichlet


} // namespace Constraints
} // namespace Spaces
} // namespace GDT
} // namespace Dune

#endif // DUNE_GDT_SPACES_CONSTRAINTS_HH
{'fraction_non_alphanumeric': 0.11418964357767317, 'fraction_numerical': 0.0020174848688634837, 'mean_word_length': 3.6649937264742785, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 37, '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': '6790248', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2517, 'n_words': 590}