Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/bout/adios_object.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public:
}

template <class T>
adios2::Variable<T> GetArrayVariable(const std::string& varname, adios2::Dims& shape,
const std::vector<std::string>& dimNames,
int rank) {
adios2::Variable<T>
GetArrayVariable(const std::string& varname, const adios2::Dims& shape,
const std::vector<std::string>& dimNames, int rank) {
adios2::Variable<T> v = io.InquireVariable<T>(varname);
if (!v) {
adios2::Dims start(shape.size());
Expand Down
4 changes: 4 additions & 0 deletions include/bout/array.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <algorithm>
#include <map>
#include <memory>
#include <tuple>
#include <vector>

#if BOUT_USE_OPENMP
Expand Down Expand Up @@ -283,6 +284,9 @@ public:
return ptr->size();
}

/// Return shape of the array (the `size()` in a length-1 tuple)
std::tuple<size_type> shape() const { return std::make_tuple(size()); };

/*!
* Returns true if the data is unique to this Array.
*
Expand Down
38 changes: 26 additions & 12 deletions include/bout/options.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* options and allows access to all sub-sections
*
**************************************************************************
* Copyright 2010-2024 BOUT++ contributors
* Copyright 2010-2025 BOUT++ contributors
*
* Contact: Ben Dudson, dudson2@llnl.gov
*
Expand All @@ -39,6 +39,7 @@ class Options;
#ifndef OPTIONS_H
#define OPTIONS_H

#include "bout/array.hxx"
#include "bout/bout_types.hxx"
#include "bout/field2d.hxx"
#include "bout/field3d.hxx"
Expand Down Expand Up @@ -203,7 +204,8 @@ public:
/// The type used to store values
using ValueType =
bout::utils::variant<bool, int, BoutReal, std::string, Field2D, Field3D, FieldPerp,
Array<BoutReal>, Matrix<BoutReal>, Tensor<BoutReal>>;
Array<BoutReal>, Array<int>, Matrix<BoutReal>, Matrix<int>,
Comment thread
ZedThree marked this conversation as resolved.
Tensor<BoutReal>, Tensor<int>>;

/// Methods to iterate over `Options`
auto begin() { return std::begin(children); }
Expand Down Expand Up @@ -963,9 +965,15 @@ Options& Options::assign<>(FieldPerp val, std::string source);
template <>
Options& Options::assign<>(Array<BoutReal> val, std::string source);
template <>
Options& Options::assign<>(Array<int> val, std::string source);
template <>
Options& Options::assign<>(Matrix<BoutReal> val, std::string source);
template <>
Options& Options::assign<>(Matrix<int> val, std::string source);
template <>
Options& Options::assign<>(Tensor<BoutReal> val, std::string source);
template <>
Options& Options::assign<>(Tensor<int> val, std::string source);

/// Specialised similar comparison methods
template <>
Expand All @@ -975,25 +983,31 @@ inline bool Options::similar<BoutReal>(BoutReal lhs, BoutReal rhs) const {

/// Specialised as routines
template <>
std::string Options::as<std::string>(const std::string& similar_to) const;
auto Options::as(const std::string& similar_to) const -> std::string;
template <>
auto Options::as(const int& similar_to) const -> int;
template <>
auto Options::as(const BoutReal& similar_to) const -> BoutReal;
template <>
auto Options::as(const bool& similar_to) const -> bool;
template <>
int Options::as<int>(const int& similar_to) const;
auto Options::as(const Field2D& similar_to) const -> Field2D;
template <>
BoutReal Options::as<BoutReal>(const BoutReal& similar_to) const;
auto Options::as(const Field3D& similar_to) const -> Field3D;
template <>
bool Options::as<bool>(const bool& similar_to) const;
auto Options::as(const FieldPerp& similar_to) const -> FieldPerp;
template <>
Field2D Options::as<Field2D>(const Field2D& similar_to) const;
auto Options::as(const Array<BoutReal>& similar_to) const -> Array<BoutReal>;
template <>
Field3D Options::as<Field3D>(const Field3D& similar_to) const;
auto Options::as(const Array<int>& similar_to) const -> Array<int>;
template <>
FieldPerp Options::as<FieldPerp>(const FieldPerp& similar_to) const;
auto Options::as(const Matrix<BoutReal>& similar_to) const -> Matrix<BoutReal>;
template <>
Array<BoutReal> Options::as<Array<BoutReal>>(const Array<BoutReal>& similar_to) const;
auto Options::as(const Matrix<int>& similar_to) const -> Matrix<int>;
template <>
Matrix<BoutReal> Options::as<Matrix<BoutReal>>(const Matrix<BoutReal>& similar_to) const;
auto Options::as(const Tensor<BoutReal>& similar_to) const -> Tensor<BoutReal>;
template <>
Tensor<BoutReal> Options::as<Tensor<BoutReal>>(const Tensor<BoutReal>& similar_to) const;
auto Options::as(const Tensor<int>& similar_to) const -> Tensor<int>;

/// Convert \p value to string
std::string toString(const Options& value);
Expand Down
19 changes: 19 additions & 0 deletions include/bout/sys/type_name.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
#ifndef TYPE_NAME_HXX
#define TYPE_NAME_HXX

#include "bout/array.hxx"
#include "bout/bout_types.hxx"

#include <string>
#include <typeinfo>

class Field2D;
class Field3D;
class FieldPerp;
template <class T>
class Matrix;
template <class T>
class Tensor;

namespace bout {
namespace utils {
Expand Down Expand Up @@ -41,6 +47,19 @@ std::string typeName<Field3D>();

template <>
std::string typeName<FieldPerp>();

template <>
std::string typeName<Array<int>>();
template <>
std::string typeName<Array<BoutReal>>();
template <>
std::string typeName<Matrix<int>>();
template <>
std::string typeName<Matrix<BoutReal>>();
template <>
std::string typeName<Tensor<int>>();
template <>
std::string typeName<Tensor<BoutReal>>();
} // namespace utils
} // namespace bout

Expand Down
5 changes: 5 additions & 0 deletions include/bout/traits.hxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BOUT_TRAITS_H
#define BOUT_TRAITS_H

#include <tuple>
#include <type_traits>

class Field;
Expand Down Expand Up @@ -112,6 +113,10 @@ using EnableIfFieldPerp =
/// Enable a function if T is a subclass of Options
template <class T>
using EnableIfOptions = std::enable_if_t<std::is_base_of_v<Options, T>>;

/// Create a `std::index_sequence` with the length of a tuple ``T``
template <typename T>
using tuple_index_sequence = std::make_index_sequence<std::tuple_size_v<T>>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::make_index_sequence" is directly included [misc-include-cleaner]

include/bout/traits.hxx:5:

+ #include <utility>

} // namespace utils
} // namespace bout

Expand Down
16 changes: 8 additions & 8 deletions include/bout/utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* simple but common calculations
*
**************************************************************************
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
* Copyright 2010 - 2025 BOUT++ contributors
*
* Contact: Ben Dudson, bd512@york.ac.uk
* Contact: Ben Dudson, dudson2@llnl.gov
*
* This file is part of BOUT++.
*
Expand Down Expand Up @@ -517,18 +517,18 @@ std::string toString(const T& val) {
/// where the type may be std::string.
inline std::string toString(const std::string& val) { return val; }

template <>
inline std::string toString<>(const Array<BoutReal>& UNUSED(val)) {
template <typename T>
inline std::string toString(const Array<T>& UNUSED(val)) {
return "<Array>";
}

template <>
inline std::string toString<>(const Matrix<BoutReal>& UNUSED(val)) {
template <typename T>
inline std::string toString(const Matrix<T>& UNUSED(val)) {
return "<Matrix>";
}

template <>
inline std::string toString<>(const Tensor<BoutReal>& UNUSED(val)) {
template <typename T>
inline std::string toString(const Tensor<T>& UNUSED(val)) {
return "<Tensor>";
}

Expand Down
25 changes: 24 additions & 1 deletion src/mesh/data/gridfromfile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "bout/traits.hxx"
#include <bout/griddata.hxx>

#include <bout/array.hxx>
#include <bout/boutexception.hxx>
#include <bout/constants.hxx>
#include <bout/fft.hxx>
Expand All @@ -11,6 +12,9 @@
#include <bout/sys/timer.hxx>
#include <bout/unused.hxx>
#include <bout/utils.hxx>

#include <algorithm>
#include <iterator>
#include <utility>

GridFile::GridFile(std::string gridfilename)
Expand Down Expand Up @@ -471,7 +475,26 @@ bool GridFile::get([[maybe_unused]] Mesh* m, [[maybe_unused]] std::vector<int>&
[[maybe_unused]] GridDataSource::Direction dir) {
TRACE("GridFile::get(vector<int>)");

return false;
if (not data.isSet(name)) {
return false;
}

const auto full_var = data[name].as<Array<int>>();
Comment thread
ZedThree marked this conversation as resolved.

// Check size
if (full_var.size() < len + offset) {
throw BoutException("{} has length {}. Expected {} elements + {} offset", name,
full_var.size(), len, offset);
}

// Ensure that output variable has the correct size
var.resize(len);

const auto* it = std::begin(full_var);
Comment thread
ZedThree marked this conversation as resolved.
Comment thread
ZedThree marked this conversation as resolved.
std::advance(it, offset);
Comment thread
ZedThree marked this conversation as resolved.
std::copy_n(it, len, std::begin(var));
Comment thread
ZedThree marked this conversation as resolved.
Comment thread
ZedThree marked this conversation as resolved.

return true;
}

bool GridFile::get(Mesh* UNUSED(m), std::vector<BoutReal>& var, const std::string& name,
Expand Down
31 changes: 31 additions & 0 deletions src/mesh/impls/bout/boutmesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,37 @@ void BoutMesh::topology() {
add_target(ny_inner - 1, 0, nx);
}

// Additional limiters
// Each limiter needs 3 indices: A Y index, start and end X indices
int limiter_count = 0;
Mesh::get(limiter_count, "limiter_count", 0);
if (limiter_count > 0) {
std::vector<int> limiter_yinds;
if (!source->get(this, limiter_yinds, "limiter_yinds", limiter_count)) {
throw BoutException("Couldn't read limiter_yinds vector of length {} from mesh",
limiter_count);
}
std::vector<int> limiter_xstarts;
if (!source->get(this, limiter_xstarts, "limiter_xstarts", limiter_count)) {
throw BoutException("Couldn't read limiter_xstarts vector of length {} from mesh",
limiter_count);
}
std::vector<int> limiter_xends;
if (!source->get(this, limiter_xends, "limiter_xends", limiter_count)) {
throw BoutException("Couldn't read limiter_xend vector of length {} from mesh",
limiter_count);
}

for (int i = 0; i < limiter_count; ++i) {
int const yind = limiter_yinds[i];
int const xstart = limiter_xstarts[i];
int const xend = limiter_xends[i];
output_info.write("Adding a limiter between y={} and {}. X indices {} to {}\n",
yind, yind + 1, xstart, xend);
add_target(yind, xstart, xend);
}
}

if ((ixseps_inner > 0)
&& (((PE_YIND * MYSUB > jyseps1_1) && (PE_YIND * MYSUB <= jyseps2_1))
|| ((PE_YIND * MYSUB > jyseps1_2) && (PE_YIND * MYSUB <= jyseps2_2)))) {
Expand Down
Loading
Loading