<commit_before>// dune-multiscale
// Copyright Holders: <NAME>, <NAME>
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

// das alles klappt momentan nur in 2-D!!! Es laesst sich aber sehr einfach verallgemeinern.
// Implementierung funktioniert unter folgenden Voraussetzungen an den (Diffusions-)Tensor:
// 1. Elliptizitätsbedingung
// 2. A(x,y) = A(y)

#ifndef DUNE_HOMOGENIZER_HH
#define DUNE_HOMOGENIZER_HH

#include <dune/multiscale/fem/elliptic_fem_matrix_assembler.hh>
#include <dune/fem/gridpart/periodicgridpart/periodicgridpart.hh>

// for data output:
#include <dune/fem/io/file/dataoutput.hh>
#include <dune/fem/io/parameter.hh>
#include <dune/fem/io/file/datawriter.hh>
#include <dune/fem/quadrature/cachingquadrature.hh>
#include <dune/stuff/fem/functions/analytical.hh>
#include <dune/stuff/common/memory.hh>
#include <dune/multiscale/common/righthandside_assembler.hh>

namespace Dune {
namespace Multiscale {

//! define output traits
struct CellDataOutputParameters : public Fem::DataOutputParameters {
public:
  std::string my_prefix_;

  // path where the data is stored
  std::string path() const { return "data_output_hmm"; }

  void set_prefix(std::string my_prefix) {
    my_prefix_ = my_prefix;
    // std :: cout << "Set prefix. my_prefix_ = " << my_prefix_ << std :: endl;
  }

  // base of file name for data file
  std::string prefix() const {
    if (my_prefix_ == "")
      return "solutions_cell_problems";
    else
      return my_prefix_;
  }

  // format of output:
  int outputformat() const {
    // return 0; // GRAPE (lossless format)
    return 1; // VTK
              // return 2; // VTK vertex data
              // return 3; // gnuplot
  }
};

NULLFUNCTION(ZeroFunction)

//! \TODO docme
// (to replace the more general lower order term)
class MassWeight : public Problem::ZeroLowerOrder {
public:

  MassWeight(double lambda) : lambda_(lambda) {}

  void evaluate(const DomainType& /*x*/, const RangeType& position, const JacobianRangeType& /*direction_gradient*/,
                RangeType& y) const {
    y = lambda_ * position;
  }

  virtual void evaluate(const DomainType& /*x*/, RangeType& /*ret*/) const { DUNE_THROW(Dune::NotImplemented, ""); }

  double lambda_;
};

/** since we need to evaluate A( x, \cdot ) to solve cellproblems (in comparison to A( \cdot, \frac{\cdot}{\epsilon} )
 * for the global problem), we must transform the orginal tensor to be able to use a standard FEM operator for solving
 * cell problems (otherwise: calling the method evaluate(i,j,x,y) within the matrixassembler would evaluate A^{\epsilon}
 * instead of A(x,\cdot) )
 **/
template <class TensorImp>
class TransformTensor : public Problem::DiffusionBase {
private:
  typedef CommonTraits::FunctionSpaceType FunctionSpaceType;
  typedef TensorImp TensorType;

  typedef typename FunctionSpaceType::DomainType DomainType;
  typedef typename FunctionSpaceType::RangeType RangeType;
  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;

  typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;

  typedef DomainFieldType TimeType;

  static const int dimDomain = DomainType::dimension;

  const TensorType& tensor_;

public:
  // Constructor
  inline explicit TransformTensor(const TensorType& tensor) : tensor_(tensor) {}<commit_msg>fix massweight parent class<commit_after>// dune-multiscale
// Copyright Holders: <NAME>, <NAME>
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

// das alles klappt momentan nur in 2-D!!! Es laesst sich aber sehr einfach verallgemeinern.
// Implementierung funktioniert unter folgenden Voraussetzungen an den (Diffusions-)Tensor:
// 1. Elliptizitätsbedingung
// 2. A(x,y) = A(y)

#ifndef DUNE_HOMOGENIZER_HH
#define DUNE_HOMOGENIZER_HH

#include <dune/multiscale/fem/elliptic_fem_matrix_assembler.hh>
#include <dune/fem/gridpart/periodicgridpart/periodicgridpart.hh>

// for data output:
#include <dune/fem/io/file/dataoutput.hh>
#include <dune/fem/io/parameter.hh>
#include <dune/fem/io/file/datawriter.hh>
#include <dune/fem/quadrature/cachingquadrature.hh>
#include <dune/stuff/fem/functions/analytical.hh>
#include <dune/stuff/common/memory.hh>
#include <dune/multiscale/common/righthandside_assembler.hh>

namespace Dune {
namespace Multiscale {

//! define output traits
struct CellDataOutputParameters : public Fem::DataOutputParameters {
public:
  std::string my_prefix_;

  // path where the data is stored
  std::string path() const { return "data_output_hmm"; }

  void set_prefix(std::string my_prefix) {
    my_prefix_ = my_prefix;
    // std :: cout << "Set prefix. my_prefix_ = " << my_prefix_ << std :: endl;
  }

  // base of file name for data file
  std::string prefix() const {
    if (my_prefix_ == "")
      return "solutions_cell_problems";
    else
      return my_prefix_;
  }

  // format of output:
  int outputformat() const {
    // return 0; // GRAPE (lossless format)
    return 1; // VTK
              // return 2; // VTK vertex data
              // return 3; // gnuplot
  }
};

NULLFUNCTION(ZeroFunction)

//! \TODO docme
// (to replace the more general lower order term)
class MassWeight : public Problem::LowerOrderBase {
public:

  MassWeight(double lambda) : lambda_(lambda) {}

  void evaluate(const DomainType& /*x*/, const RangeType& position, const JacobianRangeType& /*direction_gradient*/,
                RangeType& y) const {
    y = lambda_ * position;
  }

  virtual void evaluate(const DomainType& /*x*/, RangeType& /*ret*/) const { DUNE_THROW(Dune::NotImplemented, ""); }
  virtual void evaluate(const DomainType&, const TimeType&, RangeType& y) const { DUNE_THROW(Dune::NotImplemented, ""); }

  virtual void position_derivative(const DomainType&, const RangeType&, const JacobianRangeType&, RangeType& y) const {
    y = RangeType(0);
  }
  virtual void direction_derivative(const DomainType&, const RangeType&, const JacobianRangeType&,
                                    JacobianRangeType& y) const {
    y = JacobianRangeType(0);
  }

  double lambda_;
};

/** since we need to evaluate A( x, \cdot ) to solve cellproblems (in comparison to A( \cdot, \frac{\cdot}{\epsilon} )
 * for the global problem), we must transform the orginal tensor to be able to use a standard FEM operator for solving
 * cell problems (otherwise: calling the method evaluate(i,j,x,y) within the matrixassembler would evaluate A^{\epsilon}
 * instead of A(x,\cdot) )
 **/
template <class TensorImp>
class TransformTensor : public Problem::DiffusionBase {
private:
  typedef CommonTraits::FunctionSpaceType FunctionSpaceType;
  typedef TensorImp TensorType;

  typedef typename FunctionSpaceType::DomainType DomainType;
  typedef typename FunctionSpaceType::RangeType RangeType;
  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;

  typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;

  typedef DomainFieldType TimeType;

  static const int dimDomain = DomainType::dimension;

  const TensorType& tensor_;

public:
  // Constructor
  inline explicit TransformTensor(const TensorType& tensor) : tensor_(tensor) {}
{'fraction_non_alphanumeric': 0.11015089163237311, 'fraction_numerical': 0.0027434842249657062, 'mean_word_length': 4.200427960057062, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5208513', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2242, 'n_words': 625}