Skip to content

Commit

Permalink
Notes
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanKKrueger committed Sep 3, 2024
1 parent 58437f4 commit 63ac33b
Showing 1 changed file with 90 additions and 17 deletions.
107 changes: 90 additions & 17 deletions spiner/databox_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,90 @@
#ifndef SINGE_UTIL_DATABOXWRAPPER_HPP
#define SINGE_UTIL_DATABOXWRAPPER_HPP
#ifndef _SPINER_DATABOXWRAPPER_HPP_
#define _SPINER_DATABOXWRAPPER_HPP_

#include "singe/util/databox.hpp"
#include "singe/util/portability_macros.hpp"
#include "databox.hpp"

#include "ports-of-call//portability.hpp"

#include <cmath>

namespace singe {
namespace util {
namespace Spiner {

// ================================================================================================

// The original use-case did three things:
// * Add transformations of the data. This was originally hard-coded, but we'll make it general.
// * Add extrapolations off the edge of the table.
// * Adapt the interface. We should instead follow the Databox interface.
// * DataBox() = default;
// * DataBox(T * data, Args... args) noexcept;
// * DataBox(AllocationTarget t, Args... args) noexcept;
// * DataBox(Args... args) noexcept;
// * DataBox(PortableMDArray<T> A) noexcept;
// * DataBox(PortableMDArray<T>& A) noexcept;
// * DataBox(const DataBox& src) noexcept;
// * DataBox(const DataBox& b, const int dim, const int indx, const int nvar) noexcept
// #ifdef SPINER_USE_HDF
// * DataBox(const std::string& filename);
// * DataBox(hid_t loc, const std::string& groupname);
// #endif // SPINER_USE_HDF
// * void setArray(PortableMDArray<T>& A);
// * void resize(AllocationTarget t, Args... args);
// * void resize(Args... args);
// * T& operator()(Args... args);
// * T& operator()(Args... args) const;
// * DataBox slice(const int dim, const int indx, const int nvar) const;
// * DataBox slice(const int indx) const;
// * DataBox slice(const int ix2, const int ix1) const;
// * void reshape(Args... args);
// * T interpToReal(const T x) const noexcept;
// * T interpToReal(const T x2, const T x1) const noexcept;
// * T interpToReal(const T x3, const T x2, const T x1) const noexcept;
// * T interpToReal(const T x4, const T x3, const T x2, const T x1) const noexcept;
// * void interpFromDB(const DataBox& db, const T x);
// * void interpFromDB(const DataBox& db, const T x2, const T x1);
// * DataBox interpToDB(Args... args);
// * void setIndexType(int i, IndexType t);
// * void setRange(int i, Grid_t g);
// * void setRange(int i, Args&&... args);
// * void copyShape(const DataBox& db, const int ndims = 0);
// * void copyMetadata(const DataBox& src);
// #ifdef SPINER_USE_HDF
// * herr_t saveHDF() const;
// * herr_t saveHDF(const std::string& filename) const;
// * herr_t saveHDF(hid_t loc, const std::string& groupname) const;
// * herr_t loadHDF();
// * herr_t loadHDF(const std::string& filename);
// * herr_t loadHDF(hid_t loc, const std::string& groupname);
// #endif // SPINER_USE_HDF
// * IndexType& indexType(const int i);
// * Grid_t& range(const int i);
// * DataBox& operator=(const DataBox& other);
// * void copy(const DataBox& src);
// * DataStatus dataStatus() const;
// * bool isReference();
// * bool ownsAllocatedMemory();
// * bool operator==(const DataBox& other) const;
// * bool operator!=(const DataBox& other) const;
// * void makeShallow();
// * void reset();
// * T* data() const;
// * T min() const;
// * T max() const;
// * int rank() const;
// * int size() const;
// * int sizeBytes() const;
// * int dim() const;
// * Grid_t range(int i) const;
// * IndexType indexType(const int i) const;
// * std::size_t serializedSizeInBytes() const;
// * std::size_t serialize(char* dst) const;
// * std::size_t setPointer(T* src);
// * std::size_t setPointer(char* src);
// * std::size_t deSerialize(char* src);
// * DataBox getOnDevice() const;
// * void finalize();


// a wrapper to (a) adapt the interface and (b) handle extrapolation off the table
// -- note that we assume this is a 1D databox
template <typename DataType_t, typename LowerExtrapolation, typename UpperExtrapolation>
Expand All @@ -23,32 +97,32 @@ class DataBoxWrapper
DataType_t Thi_;

public:
SINGE_PORTABLE_FUNCTION DataBoxWrapper(DataBox<DataType_t> databox)
PORTABLE_FUNCTION DataBoxWrapper(DataBox<DataType_t> databox)
: databox_{databox} // MUST be initialized before Tlo_ and Thi_
, Tlo_{get_temperature(0)}
, Thi_{get_temperature(size() - 1)}
{}
SINGE_PORTABLE_FUNCTION constexpr DataType_t get_logT(int const index) const
PORTABLE_FUNCTION constexpr DataType_t get_logT(int const index) const
{
return databox_.range(0).x(index);
}
SINGE_PORTABLE_FUNCTION constexpr DataType_t get_temperature(int const index) const
PORTABLE_FUNCTION constexpr DataType_t get_temperature(int const index) const
{
return std::exp(get_logT(index));
}
SINGE_PORTABLE_FUNCTION constexpr DataType_t get_value(int const index) const
PORTABLE_FUNCTION constexpr DataType_t get_value(int const index) const
{
return databox_(index);
}
SINGE_PORTABLE_FUNCTION constexpr DataType_t get_logV(int const index) const
PORTABLE_FUNCTION constexpr DataType_t get_logV(int const index) const
{
return std::log(get_value(index));
}
SINGE_PORTABLE_FUNCTION constexpr int size() const
PORTABLE_FUNCTION constexpr int size() const
{
return databox_.dim(1);
}
SINGE_PORTABLE_FUNCTION constexpr DataType_t operator()(DataType_t const temperature) const
PORTABLE_FUNCTION constexpr DataType_t operator()(DataType_t const temperature) const
{
if (temperature < Tlo_) {
return LowerExtrapolation::extrapolate(temperature, *this);
Expand All @@ -58,15 +132,14 @@ class DataBoxWrapper
return databox_.interpToReal(std::log(temperature));
}
}
SINGE_PORTABLE_FUNCTION constexpr void finalize()
PORTABLE_FUNCTION constexpr void finalize()
{
databox_.finalize();
}
};

// ================================================================================================

} // end namespace util
} // end namespace singe
} // end namespace Spiner

#endif // ifndef SINGE_UTIL_DATABOXWRAPPER_HPP
#endif // ifndef _SPINER_DATABOXWRAPPER_HPP_

0 comments on commit 63ac33b

Please sign in to comment.