Commit da72a198 authored by Lukas Riedel's avatar Lukas Riedel

Make dorie-rfg compatible to dune-randomfield v2.6

* Adapt new template signature of RandomField class.
* Convert indentation to spaces.
* Remove unnecessary includes.
* Switch from 'switch' to 'if...else'.
parent 43db5c2e
// -*- tab-width: 4; indent-tabs-mode: nil -*-
/** \file
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
// common includes
#include <random>
#include <fstream>
#include <vector>
#include <fftw3.h>
#include <fftw3-mpi.h>
#include <time.h>
#include <hdf5.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>
#include <sstream>
#include <cstdio>
#include <cerrno>
// DUNE includes
// Do not treat DUNE warnings as errors
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wall"
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/parametertree.hh>
#include <dune/common/parametertreeparser.hh>
#include <dune/common/fvector.hh>
#include <dune/geometry/type.hh>
#include <dune/grid/common/gridenums.hh>
#include <dune/pdelab/common/geometrywrapper.hh>
#pragma GCC diagnostic pop
#include <dune/common/exceptions.hh>
#include <dune/common/parallel/mpihelper.hh>
// dorie-rfg includes
#include <dune/randomfield/randomfield.hh>
/// Traits for the Random Field
template<unsigned int dimension>
/// Set up dummy traits required by RandomField (usually supplied by grid)
template<int dimension>
struct GridTraits
{
enum {dim = dimension};
using RangeField = double;
using Scalar = Dune::FieldVector<RangeField,1>;
using DomainField = double;
using Domain = Dune::FieldVector<DomainField,dim>;
enum {dim = dimension};
using RangeField = double;
using Scalar = Dune::FieldVector<RangeField, 1>;
using DomainField = double;
using Domain = Dune::FieldVector<DomainField, dim>;
};
int main(int argc, char** argv)
{
try{
//Initialize Mpi
Dune::MPIHelper::instance(argc, argv);
try{
//Initialize Mpi
Dune::MPIHelper::instance(argc, argv);
if (argc!=2)
DUNE_THROW(Dune::IOError,"No parameter file specified!");
const std::string inifilename = argv[1];
if (argc!=2)
DUNE_THROW(Dune::IOError,"No parameter file specified!");
const std::string inifilename = argv[1];
// Read ini file
Dune::ParameterTree inifile;
Dune::ParameterTreeParser ptreeparser;
ptreeparser.readINITree(inifilename, inifile);
const unsigned int dim = inifile.get<unsigned int>("grid.dimensions");
// Read ini file
Dune::ParameterTree inifile;
Dune::ParameterTreeParser ptreeparser;
ptreeparser.readINITree(inifilename, inifile);
const unsigned int dim = inifile.get<unsigned int>("grid.dimensions");
// Attempt to create output directory
const std::string outputPath
= inifile.get<std::string>("general.tempDir");
mkdir(outputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
int result = access(outputPath.c_str(), W_OK);
if (result != 0)
DUNE_THROW(Dune::IOError,"Output folder " << outputPath << " not writable");
// Attempt to create output directory
const std::string outputPath
= inifile.get<std::string>("general.tempDir");
const int status = mkdir(outputPath.c_str(),
S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (status != 0)
DUNE_THROW(Dune::IOError,
"Output folder " << outputPath << " not writable");
const std::string outputFile = outputPath + "/field";
// fix output filename to ensure the file is found by Python frontend
const std::string outputFile = outputPath + "/field";
// standard values
inifile["stochastic.anisotropy"] = "axiparallel";
// standard values
inifile["stochastic.anisotropy"] = "axiparallel";
// extract seed
const unsigned int seed = inifile.get<unsigned int>("stochastic.seed");
// extract seed
const unsigned int seed = inifile.get<unsigned int>("stochastic.seed");
// Create RFG objects
switch(dim){
case 2:
{
using Traits = GridTraits<2>;
Dune::RandomField::RandomField<Traits,false,false> field(inifile);
field.generate(seed);
field.writeToFile(outputFile);
}
break;
case 3:
{
using Traits = GridTraits<3>;
Dune::RandomField::RandomField<Traits,false,false> field(inifile);
field.generate(seed);
field.writeToFile(outputFile);
}
break;
default:
DUNE_THROW(Dune::NotImplemented,"Only 2 and 3-dimensional fields are supported");
}
// Create RFG objects
if (dim == 2) {
using Traits = GridTraits<2>;
Dune::RandomField::RandomField<Traits> field(inifile);
field.generate(seed);
field.writeToFile(outputFile);
}
else if (dim == 3) {
using Traits = GridTraits<3>;
Dune::RandomField::RandomField<Traits> field(inifile);
field.generate(seed);
field.writeToFile(outputFile);
}
else {
DUNE_THROW(Dune::NotImplemented,
"Only 2 and 3-dimensional fields are supported");
}
return 0;
}
return 0;
}
catch (Dune::Exception &e)
{
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch (...)
{
std::cerr << "Unknown exception thrown!" << std::endl;
throw;
return 1;
}
catch (Dune::Exception &e)
{
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch (std::exception& e)
{
std::cerr << "Exception occurred: " << e.what() << std::endl;
return 1;
}
catch (...)
{
std::cerr << "Unknown exception thrown!" << std::endl;
throw;
return 1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment