From 753bb346cf8d606ee1522a23c678bc56dea98e56 Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 29 Nov 2024 14:18:40 +0100 Subject: [PATCH] Avoid using the wrong grid by accident --- src/mesh/mesh.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mesh/mesh.cxx b/src/mesh/mesh.cxx index 6d7a5de512..c79aa81b43 100644 --- a/src/mesh/mesh.cxx +++ b/src/mesh/mesh.cxx @@ -29,8 +29,16 @@ MeshFactory::ReturnType MeshFactory::create(const std::string& type, Options* op if (options->isSet("file") or Options::root().isSet("grid")) { // Specified mesh file - const auto grid_name = - (*options)["file"].withDefault(Options::root()["grid"].withDefault("")); + const auto grid_name1 = Options::root()["grid"].withDefault(""); + const auto grid_name = (*options)["file"].withDefault(grid_name1); + if (options->isSet("file") ond Options::root().isSet("grid")) { + if (grid_name1 != grid_name) { + throw BoutException( + "Mismatch in grid names - specified `{:s}` in grid and `{:s} in " + "mesh:file!\nPlease specify only one name or ensure they are the same!", + name1, grid_name); + } + } output << "\nGetting grid data from file " << grid_name << "\n"; // Create a grid file, using specified format if given