From 52745baf9c6f0268dc9cfe212fc7dcc7cff98780 Mon Sep 17 00:00:00 2001 From: Timo Koch Date: Thu, 28 Jan 2021 19:55:35 +0100 Subject: [PATCH 1/2] [subgridmanager] Allow to specify pixel dimensions to automatically determine domain size --- dumux/io/grid/gridmanager_sub.hh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/dumux/io/grid/gridmanager_sub.hh b/dumux/io/grid/gridmanager_sub.hh index cf18c0bb84..fadeff1335 100644 --- a/dumux/io/grid/gridmanager_sub.hh +++ b/dumux/io/grid/gridmanager_sub.hh @@ -25,6 +25,7 @@ #define DUMUX_IO_GRID_MANAGER_SUB_HH #include +#include #include #include @@ -241,14 +242,26 @@ private: template void createGridFromImage_(const Img& img, const std::string& paramGroup) { - // get the corner coordinates - using GlobalPosition = typename ParentType::Grid::template Codim<0>::Geometry::GlobalCoordinate; - const auto upperRight = getParamFromGroup(paramGroup, "Grid.UpperRight"); - const auto lowerLeft = getParamFromGroup(paramGroup, "Grid.LowerLeft", GlobalPosition(0.0)); - // get the number of cells const std::array cells{static_cast(img.header().nCols), static_cast(img.header().nRows)}; + // get the corner coordinates + const auto [lowerLeft, upperRight] = [&]() + { + using GlobalPosition = typename ParentType::Grid::template Codim<0>::Geometry::GlobalCoordinate; + const auto lowerLeft = getParamFromGroup(paramGroup, "Grid.LowerLeft", GlobalPosition(0.0)); + if (hasParamInGroup(paramGroup, "Grid.PixelDimensions")) + { + auto upperRight = getParamFromGroup(paramGroup, "Grid.PixelDimensions"); + for (int i = 0; i < upperRight.size(); ++i) + upperRight[i] *= cells[i]; + upperRight += lowerLeft; + return std::make_pair(lowerLeft, upperRight); + } + else + return std::make_pair(lowerLeft, getParamFromGroup(paramGroup, "Grid.UpperRight")); + }(); + // construct the host grid this->initHostGrid_(lowerLeft, upperRight, cells, paramGroup); -- GitLab From 6d27b0638e026a8b331a6090d77f213d760cab72 Mon Sep 17 00:00:00 2001 From: Timo Koch Date: Mon, 1 Feb 2021 11:39:40 +0100 Subject: [PATCH 2/2] [io][imagereader] Fix compiler warning about unnecessary references. Image values are simple types use value type. --- dumux/io/rasterimagereader.hh | 4 ++-- test/io/rasterimagereader/test_rasterimagereader.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dumux/io/rasterimagereader.hh b/dumux/io/rasterimagereader.hh index 4ead3192f7..0e5304f9d6 100644 --- a/dumux/io/rasterimagereader.hh +++ b/dumux/io/rasterimagereader.hh @@ -328,7 +328,7 @@ public: std::size_t rowIdx = 0; std::size_t colIdx = 0; - for (const auto& val : result) + for (const auto val : result) { image[rowIdx][colIdx] = val; @@ -354,7 +354,7 @@ public: std::vector data; data.reserve(image.size()*image[0].size()); for (const auto& row: image) - for (const auto& col : row) + for (const auto col : row) data.push_back(col); return data; diff --git a/test/io/rasterimagereader/test_rasterimagereader.cc b/test/io/rasterimagereader/test_rasterimagereader.cc index 491a4fab09..3853f420e7 100644 --- a/test/io/rasterimagereader/test_rasterimagereader.cc +++ b/test/io/rasterimagereader/test_rasterimagereader.cc @@ -49,7 +49,7 @@ int main(int argc, char** argv) // print the image for (const auto& row: printableBlackAndWhiteImage) { - for (const auto& col : row) + for (bool col : row) std::cout << col << " "; std::cout << std::endl; } @@ -131,7 +131,7 @@ int main(int argc, char** argv) // print the image for (const auto& row: printableGrayScaleImage) { - for (const auto& col : row) + for (bool col : row) std::cout << std::setw(3) << +col << " "; std::cout << std::endl; } -- GitLab