<commit_before>#include <config.h>
#include <dune/common/exceptions.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/parallel/collectivecommunication.hh>
#include <dune/stuff/common/validation.hh>
#include <dune/stuff/common/float_cmp.hh>
#include <dune/stuff/grid/boundaryinfo.hh>
#include <dune/stuff/common/profiler.hh>
#include <dune/stuff/common/configuration.hh>
#include <dune/multiscale/problems/selector.hh>
#include <math.h>
#include <sstream>
#include <mpi.h>

#include "dune/multiscale/problems/base.hh"

#include "random.hh"

#if HAVE_RANDOM_PROBLEM
# include "random_permeability.hh"
#endif

namespace Dune {
namespace Multiscale {
namespace Problem {
namespace Random {

ModelProblemData::ModelProblemData()
  : IModelProblemData()
  , boundaryInfo_(DSG::BoundaryInfos::NormalBased<typename View::Intersection>::create(boundary_settings()))
  , subBoundaryInfo_() {}

// functions actually unused
std::string ModelProblemData::getMacroGridFile() const {
  return "";
}

std::pair<CommonTraits::DomainType, CommonTraits::DomainType> ModelProblemData::gridCorners() const {
  CommonTraits::DomainType lowerLeft(0.0);
  CommonTraits::DomainType upperRight(1.0);
  return {lowerLeft, upperRight};
}

void ModelProblemData::problem_init(MPIHelper::MPICommunicator global, MPIHelper::MPICommunicator local)
{
  getMutableDiffusion().init(global, local);
}

void Diffusion::init(MPIHelper::MPICommunicator global, MPIHelper::MPICommunicator local)
{
  const int log2Seg = DSC_CONFIG_GET("grids.macro_cells_per_dim", 4);
  int seed = 0;
  MPI_Comm_rank(global, &seed);
  assert(seed >= 0);
  const int overlap = DSC_CONFIG_GET("grids.overlap", 1u);
  correlation_ = DSC::make_unique<CorrelationType>();
  DSC::ScopedTiming field_tm("msfem.perm_field.init");
#if HAVE_RANDOM_PROBLEM
  field_ = DSC::make_unique<PermeabilityType>(local, *correlation_, log2Seg, seed+1, overlap);
#else
  DUNE_THROW(InvalidStateException, "random problem needs additional libs to be configured properly");
#endif
}

void Diffusion::prepare_new_evaluation()
{
  DSC::ScopedTiming field_tm("msfem.perm_field.init");
#if HAVE_RANDOM_PROBLEM
  assert(field_);
  field_->create();
#else
  DUNE_THROW(InvalidStateException, "random problem needs additional libs to be configured properly");<commit_msg>[problems] proper slab setup for random field gen<commit_after>#include <config.h>
#include <dune/common/exceptions.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/parallel/collectivecommunication.hh>
#include <dune/stuff/common/validation.hh>
#include <dune/stuff/common/float_cmp.hh>
#include <dune/stuff/grid/boundaryinfo.hh>
#include <dune/stuff/common/profiler.hh>
#include <dune/stuff/common/configuration.hh>
#include <dune/multiscale/problems/selector.hh>
#include <math.h>
#include <sstream>
#include <mpi.h>

#include "dune/multiscale/problems/base.hh"

#include "random.hh"

#if HAVE_RANDOM_PROBLEM
# include "random_permeability.hh"
#endif

namespace Dune {
namespace Multiscale {
namespace Problem {
namespace Random {

ModelProblemData::ModelProblemData()
  : IModelProblemData()
  , boundaryInfo_(DSG::BoundaryInfos::NormalBased<typename View::Intersection>::create(boundary_settings()))
  , subBoundaryInfo_() {}

// functions actually unused
std::string ModelProblemData::getMacroGridFile() const {
  return "";
}

std::pair<CommonTraits::DomainType, CommonTraits::DomainType> ModelProblemData::gridCorners() const {
  CommonTraits::DomainType lowerLeft(0.0);
  CommonTraits::DomainType upperRight(1.0);
  return {lowerLeft, upperRight};
}

void ModelProblemData::problem_init(MPIHelper::MPICommunicator global, MPIHelper::MPICommunicator local)
{
  getMutableDiffusion().init(global, local);
}

void Diffusion::init(MPIHelper::MPICommunicator global, MPIHelper::MPICommunicator local)
{
  const auto cells_per_dim = DSC_CONFIG.get<std::vector<std::size_t>>("grids.macro_cells_per_dim");
  std::for_each(cells_per_dim.begin(), cells_per_dim.end(), [&](size_t t){assert(t==cells_per_dim[0]);});
  const int log2Seg = cells_per_dim[0];
  int seed = 0;
  MPI_Comm_rank(global, &seed);
  assert(seed >= 0);
  const int overlap = DSC_CONFIG_GET("grids.overlap", 1u);
  correlation_ = DSC::make_unique<CorrelationType>();
  DSC::ScopedTiming field_tm("msfem.perm_field.init");
#if HAVE_RANDOM_PROBLEM
  field_ = DSC::make_unique<PermeabilityType>(local, *correlation_, log2Seg, seed+1, overlap);
#else
  DUNE_THROW(InvalidStateException, "random problem needs additional libs to be configured properly");
#endif
}

void Diffusion::prepare_new_evaluation()
{
  DSC::ScopedTiming field_tm("msfem.perm_field.init");
#if HAVE_RANDOM_PROBLEM
  assert(field_);
  field_->create();
#else
  DUNE_THROW(InvalidStateException, "random problem needs additional libs to be configured properly");
{'fraction_non_alphanumeric': 0.13334715885524678, 'fraction_numerical': 0.00476980506014102, 'mean_word_length': 7.536283185840708, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, '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': '5505962', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1649, 'n_words': 289}