Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hermes-3 merges #1

Open
wants to merge 37 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9d7f620
Add Array<int> to Options
bendudson Jun 14, 2023
c8e3dd0
GridFile: Check sizes, allocate vector ints
bendudson Jun 15, 2023
2e9f495
Add limiters in input mesh
bendudson Jun 15, 2023
1c77e00
Merge branch 'bugfix-fvops-yalign' into hermes3-temp
bendudson Jun 15, 2023
7d261d4
Merge branch 'next' into hermes3-temp
bendudson Feb 16, 2024
30a93f7
Apply black changes
bendudson Feb 16, 2024
fee27c9
Dump field before and after rhs evaluation for debugging
dschwoerer Nov 3, 2023
96da2e9
Add setName function
dschwoerer Nov 3, 2023
e56981c
Set div_par and grad_par names
dschwoerer Jun 19, 2023
6b2c132
Dump debug file if PVODE fails
dschwoerer Jun 19, 2023
df2d661
Add tracking to Field3D
dschwoerer Jun 19, 2023
263f9fe
Add tracking to Field3D
dschwoerer Jun 19, 2023
bac4ca9
cvode: Add option to use Adams Moulton solver instead of BDF
dschwoerer Apr 25, 2023
708bdcb
Expose more pvode option to user
dschwoerer Mar 29, 2023
d88b454
Fix bad cherry-pick
dschwoerer Mar 19, 2024
023bc41
Update to new API
dschwoerer Mar 19, 2024
affc995
Fix documentation
dschwoerer Mar 19, 2024
71f5b6a
Apply clang-format changes
dschwoerer Mar 19, 2024
31fd461
Apply recomendations from code-review
dschwoerer Mar 20, 2024
17e46cf
Use more meaningful names
dschwoerer Mar 20, 2024
9c0ae16
Apply clang-format changes
dschwoerer Mar 20, 2024
4a17b49
Apply suggestions from code review
dschwoerer Mar 20, 2024
2f7c3c0
Workaround for gcc 9.4
dschwoerer Mar 20, 2024
d611758
Add option to debug on failure
dschwoerer Apr 9, 2024
db96b7e
Add option to euler solver to dump debug info
dschwoerer Apr 9, 2024
84bfcef
Disable tracking once we are done
dschwoerer Apr 15, 2024
73265df
Allow to dump every timestep with euler
dschwoerer Apr 15, 2024
8ff388a
Apply clang-format changes
dschwoerer Apr 15, 2024
d7f8807
Merge branch 'next' into hermes3-temp
bendudson Jul 5, 2024
acdc86c
Add debug_on_failure for cvode
dschwoerer Jul 24, 2024
87e6877
Add cvode_max_conv_fails option
Steven-Roberts Jul 24, 2024
ffca58c
Apply clang-format changes
mikekryjak Jul 25, 2024
bb7c0f2
Merge remote-tracking branch 'boutproject/pvcode-cvode-improvements' …
mikekryjak Jul 25, 2024
01951e8
Merge remote-tracking branch 'Steven-Roberts/cvode_max_conv_fails' in…
mikekryjak Jul 25, 2024
44022f9
Merge remote-tracking branch 'boutproject/cvode-for-mike' into hermes3
mikekryjak Jul 25, 2024
9cccd66
merge
mikekryjak Jul 25, 2024
79821e2
Apply clang-format changes
mikekryjak Jul 25, 2024
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
10 changes: 7 additions & 3 deletions include/bout/options.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ 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>>;
using ValueType = bout::utils::variant<bool, int, BoutReal, std::string, Field2D,
Field3D, FieldPerp, Array<BoutReal>, Array<int>,
Matrix<BoutReal>, Tensor<BoutReal>>;

/// A tree representation with leaves containing ValueType.
/// Used to construct Options from initializer lists.
Expand Down Expand Up @@ -914,6 +914,8 @@ void Options::assign<>(FieldPerp val, std::string source);
template <>
void Options::assign<>(Array<BoutReal> val, std::string source);
template <>
void Options::assign<>(Array<int> val, std::string source);
template <>
void Options::assign<>(Matrix<BoutReal> val, std::string source);
template <>
void Options::assign<>(Tensor<BoutReal> val, std::string source);
Expand Down Expand Up @@ -942,6 +944,8 @@ FieldPerp Options::as<FieldPerp>(const FieldPerp& similar_to) const;
template <>
Array<BoutReal> Options::as<Array<BoutReal>>(const Array<BoutReal>& similar_to) const;
template <>
Array<int> Options::as<Array<int>>(const Array<int>& similar_to) const;
template <>
Matrix<BoutReal> Options::as<Matrix<BoutReal>>(const Matrix<BoutReal>& similar_to) const;
template <>
Tensor<BoutReal> Options::as<Tensor<BoutReal>>(const Tensor<BoutReal>& similar_to) const;
Expand Down
4 changes: 2 additions & 2 deletions include/bout/utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ 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>";
}

Expand Down
26 changes: 24 additions & 2 deletions src/mesh/data/gridfromfile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ struct GetDimensions {
std::vector<int> operator()([[maybe_unused]] int value) { return {1}; }
std::vector<int> operator()([[maybe_unused]] BoutReal value) { return {1}; }
std::vector<int> operator()([[maybe_unused]] const std::string& value) { return {1}; }
std::vector<int> operator()(const Array<BoutReal>& array) { return {array.size()}; }
template <typename T>
std::vector<int> operator()(const Array<T>& array) {
return {array.size()};
}
std::vector<int> operator()(const Matrix<BoutReal>& array) {
const auto shape = array.shape();
return {std::get<0>(shape), std::get<1>(shape)};
Expand Down Expand Up @@ -477,7 +480,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>>();

// 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);

Choose a reason for hiding this comment

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

warning: variable name 'it' is too short, expected at least 3 characters [readability-identifier-length]

  const auto* it = std::begin(full_var);
              ^


const auto* it = std::begin(full_var);

Choose a reason for hiding this comment

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

warning: variable name 'it' is too short, expected at least 3 characters [readability-identifier-length]

  const auto* it = std::begin(full_var);
              ^

std::advance(it, offset);
std::copy_n(it, len, std::begin(var));

return true;
}

bool GridFile::get(Mesh* UNUSED(m), std::vector<BoutReal>& var, const std::string& name,
Expand Down
29 changes: 29 additions & 0 deletions src/mesh/impls/bout/boutmesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,35 @@ 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, limiter_xstarts, limiter_xends;

Choose a reason for hiding this comment

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

warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]

Suggested change
std::vector<int> limiter_yinds, limiter_xstarts, limiter_xends;
std::vector<int> limiter_yinds;
std::vector<int> limiter_xstarts;
std::vector<int> limiter_xends;

if (!source->get(this, limiter_yinds, "limiter_yinds", limiter_count)) {
throw BoutException("Couldn't read limiter_yinds vector of length {} from mesh",
limiter_count);
}
if (!source->get(this, limiter_xstarts, "limiter_xstarts", limiter_count)) {
throw BoutException("Couldn't read limiter_xstarts vector of length {} from mesh",
limiter_count);
}
if (!source->get(this, limiter_xends, "limiter_xends", limiter_count)) {
throw BoutException("Couldn't read limiter_xend vector of length {} from mesh",
limiter_count);
}

Choose a reason for hiding this comment

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

warning: variable 'yind' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
}
int const yind = limiter_yinds[i];


Choose a reason for hiding this comment

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

warning: variable 'xstart' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int const xstart = limiter_xstarts[i];

for (int i = 0; i < limiter_count; ++i) {

Choose a reason for hiding this comment

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

warning: variable 'xend' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
for (int i = 0; i < limiter_count; ++i) {
int const xend = limiter_xends[i];

int yind = limiter_yinds[i];

Choose a reason for hiding this comment

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

warning: variable 'yind' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int yind = limiter_yinds[i];
int const yind = limiter_yinds[i];

int xstart = limiter_xstarts[i];

Choose a reason for hiding this comment

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

warning: variable 'xstart' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int xstart = limiter_xstarts[i];
int const xstart = limiter_xstarts[i];

int xend = limiter_xends[i];

Choose a reason for hiding this comment

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

warning: variable 'xend' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int xend = limiter_xends[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
30 changes: 30 additions & 0 deletions src/sys/options.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ void Options::assign<>(Array<BoutReal> val, std::string source) {
_set_no_check(std::move(val), std::move(source));
}
template <>
void Options::assign<>(Array<int> val, std::string source) {
_set_no_check(std::move(val), std::move(source));
}
template <>
void Options::assign<>(Matrix<BoutReal> val, std::string source) {
_set_no_check(std::move(val), std::move(source));
}
Expand Down Expand Up @@ -751,6 +755,32 @@ Array<BoutReal> Options::as<Array<BoutReal>>(const Array<BoutReal>& similar_to)
return result;
}

template <>
Array<int> Options::as<Array<int>>(const Array<int>& similar_to) const {
if (is_section) {
throw BoutException(_("Option {:s} has no value"), full_name);
}

Array<int> result = bout::utils::visit(
ConvertContainer<Array<int>>{
fmt::format(_("Value for option {:s} cannot be converted to an Array<int>"),
full_name),
similar_to},
value);

// Mark this option as used
value_used = true;

output_info << _("\tOption ") << full_name << " = Array<int>";
if (hasAttribute("source")) {
// Specify the source of the setting
output_info << " (" << bout::utils::variantToString(attributes.at("source")) << ")";
}
output_info << endl;

return result;
}

template <>
Matrix<BoutReal> Options::as<Matrix<BoutReal>>(const Matrix<BoutReal>& similar_to) const {
if (is_section) {
Expand Down
4 changes: 4 additions & 0 deletions src/sys/options/options_netcdf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ void readGroup(const std::string& filename, const NcGroup& group, Options& resul
Array<double> value(static_cast<int>(dims[0].getSize()));
var.getVar(value.begin());
result[var_name] = value;
} else if (var_type == ncInt or var_type == ncShort) {
Array<int> value(static_cast<int>(dims[0].getSize()));
var.getVar(value.begin());
result[var_name] = value;
} else if ((var_type == ncString) or (var_type == ncChar)) {
std::string value;
value.resize(dims[0].getSize());
Expand Down