34#include "../geometry/dual_grid/CVertex.hpp"
35#include "../parallelization/mpi_structure.hpp"
48#define PY_WRAPPER_MATRIX_INTERFACE \
50 std::pair<unsigned long, unsigned long> Shape() const { return std::make_pair(rows_, cols_); } \
53 bool IsReadOnly() const { return read_only_; } \
56 passivedouble operator()(unsigned long row, unsigned long col) const { return Get(row, col); } \
59 std::vector<passivedouble> operator()(unsigned long row) const { return Get(row); } \
62 passivedouble Get(unsigned long row, unsigned long col) const { return SU2_TYPE::GetValue(Access(row, col)); } \
65 std::vector<passivedouble> Get(unsigned long row) const { \
66 std::vector<passivedouble> vals(cols_); \
67 for (unsigned long j = 0; j < cols_; ++j) vals[j] = Get(row, j); \
71 void Set(unsigned long row, unsigned long col, passivedouble val) { Access(row, col) = val; } \
74 void Set(unsigned long row, std::vector<passivedouble> vals) { \
75 unsigned long j = 0; \
76 for (const auto& val : vals) Set(row, j++, val); \
100 const auto& const_me = *
this;
101 return const_cast<su2double&
>(const_me.Access(row, col));
129 const CVertex*
const* vertices_ =
nullptr;
130 unsigned long rows_ = 0, cols_ = 0;
132 bool read_only_ =
false;
135 inline const su2double& Access(
unsigned long row,
unsigned long col)
const {
136 if (row > rows_ || col > cols_)
SU2_MPI::Error(name_ +
" out of bounds",
"CPyWrapperMarkerMatrixView");
137 return data_[vertices_[row]->
GetNode() * cols_ + col];
139 inline su2double& Access(
unsigned long row,
unsigned long col) {
140 if (read_only_)
SU2_MPI::Error(name_ +
" is read-only",
"CPyWrapperMarkerMatrixView");
141 const auto& const_me = *
this;
142 return const_cast<su2double&
>(const_me.Access(row, col));
154 const std::string& name,
bool read_only)
160 read_only_(read_only) {
161 if (mat.
rows() < n_vertices) {
162 SU2_MPI::Error(name +
" has fewer rows than the number of vertices in the marker.",
"CPyWrapperMarkerMatrixView");
185 inline const su2double&
Access(
unsigned long row,
unsigned long col,
unsigned long dim)
const {
191 const auto& const_me = *
this;
192 return const_cast<su2double&
>(const_me.Access(row, col, dim));
221 std::vector<passivedouble>
operator()(
unsigned long row,
unsigned long col)
const {
return Get(row, col); }
229 std::vector<passivedouble>
Get(
unsigned long row,
unsigned long col)
const {
230 std::vector<passivedouble> vals(
dims_);
231 for (
unsigned long j = 0; j <
dims_; ++j) vals[j] =
Get(row, col, j);
238 void Set(
unsigned long row,
unsigned long col, std::vector<passivedouble> vals) {
240 for (
const auto& val : vals)
Set(row, col, j++, val);
A templated vector/matrix object.
#define PY_WRAPPER_MATRIX_INTERFACE
Python wrapper matrix interface The accessors in this macro provide a passive double interface to mat...
Definition CPyWrapperMatrixView.hpp:48
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
static constexpr bool IsRowMajor
Definition C2DContainer.hpp:391
Index_t rows() const noexcept
Definition C2DContainer.hpp:222
static void Error(const std::string &ErrorMsg, const std::string &FunctionName)
Definition mpi_structure.cpp:131
This class wraps C3DDoubleMatrix for the python wrapper matrix interface. It is generaly used to wrap...
Definition CPyWrapperMatrixView.hpp:176
unsigned long cols_
Definition CPyWrapperMatrixView.hpp:180
std::string name_
Definition CPyWrapperMatrixView.hpp:181
CPyWrapper3DMatrixView(C3DDoubleMatrix &mat, const std::string &name, bool read_only)
Construct the view of the matrix.
Definition CPyWrapperMatrixView.hpp:203
unsigned long dims_
Definition CPyWrapperMatrixView.hpp:180
unsigned long rows_
Definition CPyWrapperMatrixView.hpp:180
std::vector< passivedouble > operator()(unsigned long row, unsigned long col) const
Gets the values for a row and column of the matrix.
Definition CPyWrapperMatrixView.hpp:221
void Set(unsigned long row, unsigned long col, unsigned long dim, passivedouble val)
Sets the value for a (row, column, dimension) triplet. This clears derivative information.
Definition CPyWrapperMatrixView.hpp:235
su2double * data_
Definition CPyWrapperMatrixView.hpp:179
passivedouble operator()(unsigned long row, unsigned long col, unsigned long dim) const
Gets the value for a (row, column, dimension) triplet.
Definition CPyWrapperMatrixView.hpp:218
bool read_only_
Definition CPyWrapperMatrixView.hpp:182
void Set(unsigned long row, unsigned long col, std::vector< passivedouble > vals)
Sets the values for a row and column of the matrix.
Definition CPyWrapperMatrixView.hpp:238
std::vector< unsigned long > Shape() const
Returns the shape of the matrix.
Definition CPyWrapperMatrixView.hpp:212
passivedouble Get(unsigned long row, unsigned long col, unsigned long dim) const
Gets the value for a (row, column, dimension) triplet.
Definition CPyWrapperMatrixView.hpp:224
bool IsReadOnly() const
Returns whether the data is read-only [true] or if it can be modified [false].
Definition CPyWrapperMatrixView.hpp:215
const su2double & Access(unsigned long row, unsigned long col, unsigned long dim) const
Definition CPyWrapperMatrixView.hpp:185
CPyWrapper3DMatrixView()=default
std::vector< passivedouble > Get(unsigned long row, unsigned long col) const
Gets the values for a row and column of the matrix.
Definition CPyWrapperMatrixView.hpp:229
su2double & Access(unsigned long row, unsigned long col, unsigned long dim)
Definition CPyWrapperMatrixView.hpp:189
This class wraps su2activematrix for the python wrapper matrix interface restricting it to the vertic...
Definition CPyWrapperMatrixView.hpp:125
CPyWrapperMarkerMatrixView(su2activematrix &mat, const CVertex *const *vertices, unsigned long n_vertices, const std::string &name, bool read_only)
Construct the view of the matrix.
Definition CPyWrapperMatrixView.hpp:153
CPyWrapperMarkerMatrixView()=default
This class wraps su2activematrix for the python wrapper matrix interface. It is generaly used to wrap...
Definition CPyWrapperMatrixView.hpp:85
su2double * data_
Definition CPyWrapperMatrixView.hpp:88
CPyWrapperMatrixView(su2activematrix &mat, const std::string &name, bool read_only)
Construct the view of the matrix.
Definition CPyWrapperMatrixView.hpp:112
CPyWrapperMatrixView()=default
unsigned long rows_
Definition CPyWrapperMatrixView.hpp:89
bool read_only_
Definition CPyWrapperMatrixView.hpp:91
std::string name_
Definition CPyWrapperMatrixView.hpp:90
const su2double & Access(unsigned long row, unsigned long col) const
Definition CPyWrapperMatrixView.hpp:94
su2double & Access(unsigned long row, unsigned long col)
Definition CPyWrapperMatrixView.hpp:98
unsigned long cols_
Definition CPyWrapperMatrixView.hpp:89
Class for vertex definition (equivalent to edges, but for the boundaries).
Definition CVertex.hpp:38
unsigned long GetNode() const
Get the node of the vertex.
Definition CVertex.hpp:70
double passivedouble
Definition code_config.hpp:129
passivedouble su2double
Definition code_config.hpp:181
passivedouble GetValue(const su2double &data)
Get the (primitive) value of the datatype (needs to be specialized for active types).
Definition datatype_structure.hpp:113