Skip to content

Commit 958062e

Browse files
Fix some things about accessing the dependent variable values.
1 parent 37f3840 commit 958062e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

spiner/databox.hpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -230,24 +230,31 @@ class DataBox {
230230

231231
// Data array accessors
232232
template <typename... Args>
233-
PORTABLE_INLINE_FUNCTION T get(Args... args) {
233+
PORTABLE_INLINE_FUNCTION T get_data_value(Args... args) const {
234234
return Transform::reverse(dataView_(std::forward<Args>(args)...));
235235
}
236+
// TODO: Should this method be const? Having this be const is in line with the second operator()
237+
// below (the one with const), which allows the user to modify the dependent variable
238+
// values of a const DataBox.
236239
template<typename... Args>
237-
PORTABLE_INLINE_FUNCTION void set(const T new_value, Args... args) {
240+
PORTABLE_INLINE_FUNCTION void set_data_value(const T new_value, Args... args) const {
238241
dataView_(std::forward<Args>(args)...) = Transform::forward(new_value);
239242
}
240243

241244
// Index operators
242245
// examle calls:
243246
// T x = db(n4, n3, n2, n1);
244-
template <typename... Args,
245-
typename std::enable_if<std::is_same<Transform,TransformLinear>::value>::type* = nullptr>
247+
template <
248+
typename... Args,
249+
typename transform_t=Transform, // only for SFINAE
250+
typename std::enable_if<std::is_same<transform_t,TransformLinear>::value>::type* = nullptr>
246251
PORTABLE_INLINE_FUNCTION T &operator()(Args... args) {
247252
return dataView_(std::forward<Args>(args)...);
248253
}
249-
template <typename... Args,
250-
typename std::enable_if<std::is_same<Transform,TransformLinear>::value>::type* = nullptr>
254+
template <
255+
typename... Args,
256+
typename transform_t=Transform, // only for SFINAE
257+
typename std::enable_if<std::is_same<transform_t,TransformLinear>::value>::type* = nullptr>
251258
PORTABLE_INLINE_FUNCTION T &operator()(Args... args) const {
252259
return dataView_(std::forward<Args>(args)...);
253260
}

test/test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ TEST_CASE("DataBox Interpolation with log-lin transformations", "[DataBox]") {
550550
TEST_CASE("DataBox Interpolation with log-log transformations", "[DataBox]") {
551551
using Transform = Spiner::TransformLogarithmic;
552552
using RG1D = Spiner::RegularGrid1D<double, Transform>;
553-
using DB = Spiner::DataBox<double, RG1D, Spiner::TransformLinear>;
553+
using DB = Spiner::DataBox<double, RG1D, Transform>;
554554

555555
constexpr int RANK = 2;
556556
const int Npt = 32;
@@ -570,7 +570,7 @@ TEST_CASE("DataBox Interpolation with log-log transformations", "[DataBox]") {
570570
RG1D grid(xmin, xmax, Npt);
571571
const double x = grid.x(ix);
572572
const double y = grid.x(iy);
573-
db(ix, iy) = log_log_func(x, y);
573+
db.set_data_value(log_log_func(x,y), ix, iy);
574574
});
575575

576576
double error = 0;

0 commit comments

Comments
 (0)