Commit c7124e06 authored by Lukas Riedel's avatar Lukas Riedel

Build interpolator in H5 initial condition directly from config

parent 6ff38911
...@@ -41,60 +41,11 @@ public: ...@@ -41,60 +41,11 @@ public:
InitialConditionH5( const GV& grid_view, InitialConditionH5( const GV& grid_view,
const Dune::ParameterTree& config, const Dune::ParameterTree& config,
std::shared_ptr<spdlog::logger> log) std::shared_ptr<spdlog::logger> log)
: Base(grid_view) : Base(grid_view),
{ _interpolator(InterpolatorFactory<T>::create(config.sub("initial"),
// open the H5 file grid_view,
const auto datafile = config.template get<std::string>("initial.datafile"); log))
const auto dataset = config.template get<std::string>("initial.dataset"); { }
H5File h5file(datafile, log);
// read the dataset
std::vector<RF> data;
std::vector<size_t> shape;
h5file.read_dataset(dataset, H5T_NATIVE_DOUBLE, data, shape);
std::reverse(std::begin(shape), std::end(shape));
/// retrieve extensions and offset from grid extensions
const auto level_gv = grid_view.grid().levelGridView(0);
const auto [off, upper_right] = get_grid_extensions(level_gv);
const auto ext = upper_right - off;
if (shape.size() != dim) {
log->error("Expected {}-dimensional dataset. File: {}, "
"Dataset: {}, Dimensions: {}",
dim, datafile, dataset, shape.size());
DUNE_THROW(Dune::IOError, "Invalid dataset for interpolator");
}
if (ext.size() != dim) {
log->error("Expected {}-dimensional sequence as 'extensions'",
dim);
DUNE_THROW(Dune::IOError, "Invalid interpolator input");
}
if (off.size() != dim) {
log->error("Expected {}-dimensional sequence as 'offset'",
dim);
DUNE_THROW(Dune::IOError, "Invalid interpolator input");
}
// copy into correct data structure
Domain extensions;
std::copy(std::begin(ext), std::end(ext), std::begin(extensions));
Domain offset;
std::copy(std::begin(off), std::end(off), std::begin(offset));
// build interpolator
_interpolator = InterpolatorFactory<T>::create(
config.template get<std::string>("initial.interpolation"),
data,
shape,
extensions,
offset,
log
);
}
/// Evaluate the initial condition at certain position /// Evaluate the initial condition at certain position
/** \param y /** \param y
...@@ -110,10 +61,10 @@ public: ...@@ -110,10 +61,10 @@ public:
} }
private: private:
std::shared_ptr<Interpolator<RF,T>> _interpolator; std::shared_ptr<Interpolator<RF, T>> _interpolator;
}; };
} // namespace Dorie } // namespace Dorie
} // namespace Dune } // namespace Dune
#endif // DUNE_DORIE_INITIAL_CONDITION_H5_HH #endif // DUNE_DORIE_INITIAL_CONDITION_H5_HH
\ No newline at end of file
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