Commit 9e404b86 authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos

Merge branch 'update-rfg-to-randomfield-v2.6' into 'master'

Update rfg to randomfield v2.6

Closes #150

See merge request !153
parents 43db5c2e fb7813f5
...@@ -98,6 +98,7 @@ build:system-tests: &build-tests ...@@ -98,6 +98,7 @@ build:system-tests: &build-tests
script: script:
- CMAKE_FLAGS="$CMAKE_FLAGS" - CMAKE_FLAGS="$CMAKE_FLAGS"
$DUNECONTROL --only=dorie configure $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make $MAKE_FLAGS dorie-rfg
- $DUNECONTROL --only=dorie make $MAKE_FLAGS build_system_tests - $DUNECONTROL --only=dorie make $MAKE_FLAGS build_system_tests
- $DUNECONTROL --only=dorie make doc - $DUNECONTROL --only=dorie make doc
artifacts: artifacts:
...@@ -123,6 +124,7 @@ build:debug: &debug ...@@ -123,6 +124,7 @@ build:debug: &debug
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_TYPE=Debug
-DCMAKE_CXX_FLAGS_DEBUG='-Werror'" -DCMAKE_CXX_FLAGS_DEBUG='-Werror'"
$DUNECONTROL --only=dorie configure $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make $MAKE_FLAGS dorie-rfg
- $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests - $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests
build:debug-clang: build:debug-clang:
...@@ -136,6 +138,7 @@ build:debug-clang: ...@@ -136,6 +138,7 @@ build:debug-clang:
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_COMPILER=clang++
-DCMAKE_CXX_FLAGS_DEBUG='-Werror'" -DCMAKE_CXX_FLAGS_DEBUG='-Werror'"
$DUNECONTROL --only=dorie configure $DUNECONTROL --only=dorie configure
- $DUNECONTROL --only=dorie make $MAKE_FLAGS dorie-rfg
- $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests - $DUNECONTROL --only=dorie make $MAKE_FLAGS build_unit_tests
......
...@@ -145,7 +145,8 @@ ...@@ -145,7 +145,8 @@
* Specifying scaling field `extensions` and `offset` is now optional !133 * Specifying scaling field `extensions` and `offset` is now optional !133
* Generalized initial condition specification in config file !129 * Generalized initial condition specification in config file !129
* Structure and setup of Sphinx user docs !126 * Structure and setup of Sphinx user docs !126
* Switch to stable `dune-randomfield` release branch !151 * Switch to stable `dune-randomfield` release branch !151, !153
* System tests for executing `dorie pfg` module !153
### Fixed ### Fixed
* Solver in `RichardsSimulation` was using the wrong time variable. * Solver in `RichardsSimulation` was using the wrong time variable.
......
// -*- tab-width: 4; indent-tabs-mode: nil -*-
/** \file
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #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/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <cstdio>
#include <assert.h> #include <cerrno>
#include <sstream>
// DUNE includes #include <dune/common/parametertree.hh>
// 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/parametertreeparser.hh> #include <dune/common/parametertreeparser.hh>
#include <dune/common/fvector.hh> #include <dune/common/exceptions.hh>
#include <dune/geometry/type.hh> #include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/common/gridenums.hh>
#include <dune/pdelab/common/geometrywrapper.hh>
#pragma GCC diagnostic pop
// dorie-rfg includes
#include <dune/randomfield/randomfield.hh> #include <dune/randomfield/randomfield.hh>
/// Traits for the Random Field /// Set up dummy traits required by RandomField (usually supplied by grid)
template<unsigned int dimension> template<int dimension>
struct GridTraits struct GridTraits
{ {
enum {dim = dimension}; enum {dim = dimension};
using RangeField = double; using RangeField = double;
using Scalar = Dune::FieldVector<RangeField,1>; using Scalar = Dune::FieldVector<RangeField, 1>;
using DomainField = double; using DomainField = double;
using Domain = Dune::FieldVector<DomainField,dim>; using Domain = Dune::FieldVector<DomainField, dim>;
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
try{ try{
//Initialize Mpi //Initialize Mpi
Dune::MPIHelper::instance(argc, argv); Dune::MPIHelper::instance(argc, argv);
if (argc!=2) if (argc!=2)
DUNE_THROW(Dune::IOError,"No parameter file specified!"); DUNE_THROW(Dune::IOError,"No parameter file specified!");
const std::string inifilename = argv[1]; const std::string inifilename = argv[1];
// Read ini file // Read ini file
Dune::ParameterTree inifile; Dune::ParameterTree inifile;
Dune::ParameterTreeParser ptreeparser; Dune::ParameterTreeParser ptreeparser;
ptreeparser.readINITree(inifilename, inifile); ptreeparser.readINITree(inifilename, inifile);
const unsigned int dim = inifile.get<unsigned int>("grid.dimensions"); const unsigned int dim = inifile.get<unsigned int>("grid.dimensions");
// Attempt to create output directory // Attempt to create output directory
const std::string outputPath const std::string outputPath
= inifile.get<std::string>("general.tempDir"); = inifile.get<std::string>("general.tempDir");
mkdir(outputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); const int status = mkdir(outputPath.c_str(),
int result = access(outputPath.c_str(), W_OK); S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (result != 0) // allow failure because directory exists
DUNE_THROW(Dune::IOError,"Output folder " << outputPath << " not writable"); if (status != 0 && errno != EEXIST)
DUNE_THROW(Dune::IOError,
"Output folder " << outputPath << " not writable. "
"Error by system: " << std::strerror(errno));
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 // standard values
inifile["stochastic.anisotropy"] = "axiparallel"; inifile["stochastic.anisotropy"] = "axiparallel";
// extract seed // extract seed
const unsigned int seed = inifile.get<unsigned int>("stochastic.seed"); const unsigned int seed = inifile.get<unsigned int>("stochastic.seed");
// Create RFG objects // Create RFG objects
switch(dim){ if (dim == 2) {
case 2: using Traits = GridTraits<2>;
{ Dune::RandomField::RandomField<Traits> field(inifile);
using Traits = GridTraits<2>; field.generate(seed);
Dune::RandomField::RandomField<Traits,false,false> field(inifile); field.writeToFile(outputFile);
field.generate(seed); }
field.writeToFile(outputFile); else if (dim == 3) {
} using Traits = GridTraits<3>;
break; Dune::RandomField::RandomField<Traits> field(inifile);
case 3: field.generate(seed);
{ field.writeToFile(outputFile);
using Traits = GridTraits<3>; }
Dune::RandomField::RandomField<Traits,false,false> field(inifile); else {
field.generate(seed); DUNE_THROW(Dune::NotImplemented,
field.writeToFile(outputFile); "Only 2 and 3-dimensional fields are supported");
} }
break;
default:
DUNE_THROW(Dune::NotImplemented,"Only 2 and 3-dimensional fields are supported");
}
return 0; return 0;
} }
catch (Dune::Exception &e) catch (Dune::Exception &e)
{ {
std::cerr << "Dune reported error: " << e << std::endl; std::cerr << "Dune reported error: " << e << std::endl;
return 1; return 1;
} }
catch (...) catch (std::exception& e)
{ {
std::cerr << "Unknown exception thrown!" << std::endl; std::cerr << "Exception occurred: " << e.what() << std::endl;
throw; return 1;
return 1; }
} catch (...)
{
std::cerr << "Unknown exception thrown!" << std::endl;
throw;
return 1;
}
} }
import h5py import h5py
import os import os
import sys import sys
import configparser
import numpy as np import numpy as np
from dune.testtools.parser import parse_ini_file
from dorie.utilities.text_to_bool import text_to_bool from dorie.utilities.text_to_bool import text_to_bool
class BaseConverter(object): class BaseConverter(object):
...@@ -20,9 +21,7 @@ class BaseConverter(object): ...@@ -20,9 +21,7 @@ class BaseConverter(object):
_dataset = None # The field to be written into the target file _dataset = None # The field to be written into the target file
def __init__(self, param, input_file=None): def __init__(self, param, input_file=None):
self._cp = configparser.ConfigParser(interpolation=None) self._cp = parse_ini_file(param)
with open(param) as file:
self._cp.read_file(file)
outfile = self._read_parameter('general', 'outputFile') outfile = self._read_parameter('general', 'outputFile')
dataset = self._read_parameter('general', 'dataset') dataset = self._read_parameter('general', 'dataset')
......
...@@ -8,7 +8,8 @@ import argparse ...@@ -8,7 +8,8 @@ import argparse
import warnings import warnings
import subprocess import subprocess
import multiprocessing import multiprocessing
import configparser
from dune.testtools.parser import parse_ini_file
from dorie.parfield.converter import BaseConverter, \ from dorie.parfield.converter import BaseConverter, \
BinaryConverter, \ BinaryConverter, \
...@@ -47,14 +48,13 @@ if __name__ == "__main__": ...@@ -47,14 +48,13 @@ if __name__ == "__main__":
parser.add_argument('--debug',help='Display warnings',action='store_true',required=False) parser.add_argument('--debug',help='Display warnings',action='store_true',required=False)
args = vars(parser.parse_args()) args = vars(parser.parse_args())
cp = configparser.ConfigParser(interpolation=None) # retrieve the inifile tree
with open(args["param"]) as file: inifile = parse_ini_file(args["param"])
cp.read_file(file)
params = {} params = {}
for par in ("converter", "outputFile"): for par in ("converter", "outputFile"):
try: try:
params[par] = cp["general"][par] params[par] = inifile["general"][par]
except KeyError: except KeyError:
raise RuntimeError("Missing option general.{} in " raise RuntimeError("Missing option general.{} in "
"parameter file {}".format(par, args["param"])) "parameter file {}".format(par, args["param"]))
...@@ -72,7 +72,7 @@ if __name__ == "__main__": ...@@ -72,7 +72,7 @@ if __name__ == "__main__":
print("FFT Field generator failed") print("FFT Field generator failed")
sys.exit(1) sys.exit(1)
rng_outpath = cp.get("general", "tempDir") rng_outpath = inifile["general"]["tempDir"]
input_file = os.path.join(rng_outpath, "field.stoch.h5") input_file = os.path.join(rng_outpath, "field.stoch.h5")
# CALL CONVERTER # CALL CONVERTER
......
...@@ -45,6 +45,7 @@ add_custom_target(test_run_parallel ...@@ -45,6 +45,7 @@ add_custom_target(test_run_parallel
add_dependencies(test_run_parallel prepare_testing) add_dependencies(test_run_parallel prepare_testing)
# dorie exec tests # dorie exec tests
dorie_add_metaini_test(TARGET dorie METAINI pfg.mini.in)
dorie_add_metaini_test(TARGET dorie METAINI run.mini.in) dorie_add_metaini_test(TARGET dorie METAINI run.mini.in)
dorie_add_metaini_test(TARGET dorie METAINI plot.mini.in) dorie_add_metaini_test(TARGET dorie METAINI plot.mini.in)
......
include ${CMAKE_BINARY_DIR}/doc/default_files/parfield.ini
_converter = none, binary, exponential | expand
_covariance = exponential, gaussian | expand
_dim = 2, 3 | expand dim
__name = exec_pfg-{_converter}-{_covariance}-{_dim}
_test_command = pfg
[general]
outputFile = pfg.h5
dataset = {_converter}-{_covariance}-{_dim}
tempDir = ./pfg-tmp/
converter = {_converter}
[grid]
dimensions = {_dim}
extensions = 1 1, 1 1 1 | expand dim
cells = 50 50, 10 10 10 | expand dim
[stochastic]
seed = 2
covariance = {_covariance}
corrLength = .1 .05, .2 .1 .05 | expand dim
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