Page MenuHomec4science

accessor_dof.hh
No OneTemporary

File Metadata

Created
Tue, Jul 9, 11:10

accessor_dof.hh

#ifndef __LIBMULTISCALE_ACCESSOR_DOF_HH__
#define __LIBMULTISCALE_ACCESSOR_DOF_HH__
/* -------------------------------------------------------------------------- */
#include "lm_common.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Ref, FieldType ftype> class AccessorDof {
public:
using TensorType = typename field_getter<ftype, Ref>::type;
AccessorDof(Ref &nd) : field(field_getter<ftype, Ref>::get(nd)){};
template <typename T>
inline TensorType &operator=(const Vector<Ref::Dim> &val) {
field = val;
return field;
}
template <typename T>
inline TensorType &operator=(const VectorView<Ref::Dim> val) {
field = val;
return field;
}
template <typename T> inline TensorType &operator=(const T &val) {
field = val;
return field;
}
template <typename T> inline T operator=(const T val[]) {
field = Eigen::Map<TensorType>(val);
return field;
}
template <typename T> inline T operator+=(const T &val) {
field += val;
return field;
}
template <typename T = TensorType,
std::enable_if_t<not std::is_same<std::decay_t<T>, Real>::value> * =
nullptr>
decltype(auto) operator[](UInt index) {
return field(index);
}
template <typename T = TensorType,
std::enable_if_t<std::is_same<T, Real>::value or
std::is_same<T, Real &>::value> * = nullptr>
decltype(auto) operator[](UInt index) {
if (index > 0)
LM_FATAL("invalid index");
return field;
}
UInt size() { return Ref::Dim; }
template <typename T = TensorType,
std::enable_if_t<not std::is_same<std::decay_t<T>, Real>::value> * =
nullptr>
decltype(auto) data() {
return field.data();
}
template <
typename T = TensorType,
std::enable_if_t<std::is_same<std::decay_t<T>, Real>::value> * = nullptr>
decltype(auto) data() {
return &field;
}
template <typename T = TensorType,
std::enable_if_t<not std::is_same<T, Real *>::value> * = nullptr>
operator Vector<Ref::Dim>() {
return field;
}
template <typename T = TensorType,
std::enable_if_t<std::is_same<T, Real *>::value> * = nullptr>
operator Vector<Ref::Dim>() {
LM_FATAL("cannot call this conversion");
}
void printself(std::ostream &os) { os << field; }
private:
TensorType field;
};
__END_LIBMULTISCALE__
#endif

Event Timeline