1#ifndef UTIL_D_SYMM_MATRIX_PARAM_H
2#define UTIL_D_SYMM_MATRIX_PARAM_H
11#include <util/misc/Log.h>
12#include <util/param/MatrixParam.h>
13#include <util/containers/DMatrix.h>
14#include <util/format/Int.h>
15#include <util/format/Dbl.h>
17#include <util/mpi/MpiSendRecv.h>
99 virtual void bcastValue();
128 template <
class Type>
143 template <
class Type>
147 if (!(matrixPtr_->isAllocated())) {
148 UTIL_THROW(
"Cannot read unallocated DMatrix");
150 if (
n() != matrixPtr_->capacity1()) {
151 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity1()");
153 if (
n() != matrixPtr_->capacity2()) {
154 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
162 for (i = 0; i <
n(); ++i) {
163 for (j = 0; j <
n(); ++j) {
165 (*matrixPtr_)(i, j) = 0.0;
175 std::stringstream stream;
187 if (stream.fail() || in.fail()) {
188 Log::file() <<
"Error reading an element of matrix "
189 << this->
label() <<
"\n";
190 UTIL_THROW(
"Error reading a symmetric matrix element");
192 if (i < 0 || i >=
n() || j < 0 || j >=
n()) {
193 Log::file() <<
"Element (" << i <<
", " << j
194 <<
") of matrix " << this->
label() <<
" with "
195 <<
n() <<
" rows (indices start at 0)\n";
196 UTIL_THROW(
"Symmetric matrix element index out of range");
199 (*matrixPtr_)(i, j) = value;
203 (*matrixPtr_)(j, i) = value;
207 if (k == (
n()+1)*
n()/2) {
219 template <
class Type>
222 if (!(matrixPtr_->isAllocated())) {
223 matrixPtr_->allocate(
n(),
n());
225 if (
n() != matrixPtr_->capacity1()) {
226 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity1()");
228 if (
n() != matrixPtr_->capacity2()) {
229 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
238 template <
class Type>
241 if (
n() != matrixPtr_->capacity1()) {
242 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity1()");
244 if (
n() != matrixPtr_->capacity2()) {
245 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
254 template <
class Type>
257 if (!(matrixPtr_->isAllocated())) {
258 matrixPtr_->allocate(n(), n());
260 if (n() != matrixPtr_->capacity1()) {
261 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity1()");
263 if (n() != matrixPtr_->capacity2()) {
264 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity2()");
267 bcast<Type>(this->ioCommunicator(), *matrixPtr_, n(), n(), 0);
274 template <
class Type>
279 if (!(matrixPtr_->isAllocated())) {
280 UTIL_THROW(
"Cannot read unallocated DMatrix");
282 if (
n() > matrixPtr_->capacity1()) {
283 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity1()");
285 if (
n() > matrixPtr_->capacity2()) {
286 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity2()");
294 for (i = 0; i <
n(); ++i) {
295 for (j = 0; j <= i; ++j) {
301 out <<
Int(i, 4) <<
" " <<
Int(j, 4) <<
" "
302 << std::right << std::scientific
305 << (*matrixPtr_)(i, j)
Dynamically allocated Matrix.
void allocate(int capacity1, int capacity2)
Allocate memory for a matrix.
A Parameter associated with a square symmetric DMatrix.
virtual void readValue(std::istream &in)
Read parameter value from an input stream.
void writeParam(std::ostream &out) const
Write symmetric DMatrix to file.
std::string indent() const
Return indent string for this object (string of spaces).
virtual void loadValue(Serializable::IArchive &ar)
Load bare parameter value from an archive.
DSymmMatrixParam(const char *label, DMatrix< Type > &matrix, int n, bool isRequired=true)
Constructor.
virtual void saveValue(Serializable::OArchive &ar)
Save parameter value to an archive.
Label label_
Label object that contains parameter label string.
bool isActive() const
Is this parameter active?
Int()
Default constructor.
A label string in a file format.
static std::ostream & file()
Get log ostream by reference.
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_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
BracketPolicy::Type get()
Get value of bracket policy.
Utility classes for scientific computation.