diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index c70b34babe..43a5292e9d 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -17,4 +17,5 @@ d1cfb8abd6aa5c76e6c1a4d7ab20929c65f8afc2 ec69e8838be2dde140a915e50506f8e1ce3cb534 f2bc0488a298f136294c523bc5ab4086d090059b 1b4707187a3a85126338303dc766280b8fb2dc56 +b2e2f3575e68f771be2a4341af5fd14e2870469e 64e4285ec38569f66d31e589a4610cefd16d8076 diff --git a/include/bout/array.hxx b/include/bout/array.hxx index 2305fe3b22..82677fd38a 100644 --- a/include/bout/array.hxx +++ b/include/bout/array.hxx @@ -227,6 +227,12 @@ public: ptr = get(new_size); } + /*! + * Change shape of the container. + * Invalidates contents. + */ + void reshape(std::tuple new_shape) { reallocate(std::get<0>(new_shape)); } + /*! * Holds a static variable which controls whether * memory blocks (dataBlock) are put into a store diff --git a/include/bout/utils.hxx b/include/bout/utils.hxx index 560f97f954..5088a025c1 100644 --- a/include/bout/utils.hxx +++ b/include/bout/utils.hxx @@ -5,7 +5,7 @@ * simple but common calculations * ************************************************************************** - * Copyright 2010 - 2025 BOUT++ contributors + * Copyright 2010 - 2026 BOUT++ contributors * * Contact: Ben Dudson, dudson2@llnl.gov * @@ -231,6 +231,14 @@ public: data.reallocate(new_size_1 * new_size_2); } + /*! + * Change shape of the container. + * Invalidates contents. + */ + void reshape(std::tuple new_shape) { + reallocate(std::get<0>(new_shape), std::get<1>(new_shape)); + } + Matrix& operator=(const Matrix& other) { n1 = other.n1; n2 = other.n2; @@ -331,6 +339,14 @@ public: data.reallocate(new_size_1 * new_size_2 * new_size_3); } + /*! + * Change shape of the container. + * Invalidates contents. + */ + void reshape(std::tuple new_shape) { + reallocate(std::get<0>(new_shape), std::get<1>(new_shape), std::get<2>(new_shape)); + } + Tensor& operator=(const Tensor& other) { n1 = other.n1; n2 = other.n2; diff --git a/src/sys/options.cxx b/src/sys/options.cxx index d60e91079d..8bd83c0bfb 100644 --- a/src/sys/options.cxx +++ b/src/sys/options.cxx @@ -744,27 +744,46 @@ FieldPerp Options::as(const FieldPerp& similar_to) const { } namespace { -/// Visitor to convert an int, BoutReal or Array/Matrix/Tensor to the -/// appropriate container +/// Primary declaration of ConvertContainer, for specialization below. +/// No definition needed unless it is used. template -struct ConvertContainer { +struct ConvertContainer; + +/// Visitor to convert an int, BoutReal or Array/Matrix/Tensor to the +/// appropriate container. Templated on both the container class C +/// and scalar type Scalar. +template