1#ifndef UTIL_DMATRIX_PARAM_H
2#define UTIL_DMATRIX_PARAM_H
11#include <util/param/MatrixParam.h>
12#include <util/containers/DMatrix.h>
14#include <util/mpi/MpiSendRecv.h>
85 virtual void bcastValue();
111 template <
class Type>
115 if (!(matrixPtr_->isAllocated())) {
116 UTIL_THROW(
"Cannot read unallocated DMatrix");
118 if (
m() != matrixPtr_->capacity1()) {
119 UTIL_THROW(
"Error: Logical size m() != DMatrix<Type>::capacity1()");
121 if (
n() != matrixPtr_->capacity2()) {
122 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
126 for (i = 0; i <
m(); ++i) {
127 for (j = 0; j <
n(); ++j) {
128 in >> (*matrixPtr_)(i, j);
138 template <
class Type>
141 if (!(matrixPtr_->isAllocated())) {
142 matrixPtr_->allocate(
m(),
n());
144 if (
m() != matrixPtr_->capacity1()) {
145 UTIL_THROW(
"Error: Logical size m() != DMatrix<Type>::capacity1()");
147 if (
n() != matrixPtr_->capacity2()) {
148 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
157 template <
class Type>
160 if (
m() != matrixPtr_->capacity1()) {
161 UTIL_THROW(
"Error: Logical size m() != DMatrix<Type>::capacity1()");
163 if (
n() != matrixPtr_->capacity2()) {
164 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
173 template <
class Type>
176 if (!(matrixPtr_->isAllocated())) {
177 matrixPtr_->allocate(m(), n());
179 if (m() != matrixPtr_->capacity1()) {
180 UTIL_THROW(
"Error: Logical size m() > DMatrix<Type>::capacity1()");
182 if (n() != matrixPtr_->capacity2()) {
183 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity2()");
186 bcast<Type>(ioCommunicator(), *matrixPtr_, m(), n(), 0);
193 template <
class Type>
198 if (!(matrixPtr_->isAllocated())) {
199 UTIL_THROW(
"Cannot read unallocated DMatrix");
201 if (
m() > matrixPtr_->capacity1()) {
202 UTIL_THROW(
"Error: Logical size m() > DMatrix<Type>::capacity1()");
204 if (
n() > matrixPtr_->capacity2()) {
205 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity2()");
213 for (i = 0; i <
m(); ++i) {
219 for (j = 0; j <
n(); ++j) {
220 out << std::right << std::scientific
223 << (*matrixPtr_)(i, j);
A Parameter associated with a 2D built-in C array.
std::string indent() const
Return indent string for this object (string of spaces).
virtual void readValue(std::istream &in)
Read parameter value from an input stream.
void writeParam(std::ostream &out) const
Write DMatrix to file.
virtual void loadValue(Serializable::IArchive &ar)
Load bare parameter value from an archive.
DMatrixParam(const char *label, DMatrix< Type > &matrix, int m, int n, bool isRequired=true)
Constructor.
virtual void saveValue(Serializable::OArchive &ar)
Save parameter value to an archive.
bool isActive() const
Is this parameter active?
Dynamically allocated Matrix.
A label string in a file format.
int m() const
Get the logical array dimension.
std::string label() const
Return label string.
void setBrackets(std::string lBracket, std::string rBracket)
Set left and right bracket / delimiter strings.
void readEndBracket(std::istream &in)
Read the closing delimiter, if any.
void writeEndBracket(std::ostream &out) const
Write the end bracket delimiter, if any.
bool hasBrackets() const
Are brackets being used as delimiters?
bool isRequired() const
Is this an optional parameter?
MatrixParam(const char *label, int m, int n, bool isRequired=true)
Constructor.
int n() const
Get the logical array dimension.
std::string indent() const
Return indent string for this object (string of spaces).
static const int Precision
Precision for io of floating point data field.
Label label_
Label object that contains parameter label string.
bool isActive() const
Is this parameter active?
static const int Width
Width of output field for a scalar variable.
BinaryFileIArchive IArchive
Type of input archive used by load method.
BinaryFileOArchive OArchive
Type of output archive used by save method.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.