1#ifndef UTIL_D_SYMM_MATRIX_PARAM_H
2#define UTIL_D_SYMM_MATRIX_PARAM_H
11#include <util/param/MatrixParam.h>
12#include <util/containers/DMatrix.h>
13#include <util/format/Int.h>
14#include <util/format/Dbl.h>
127 template <
class Type>
130 int n,
bool isRequired)
142 template <
class Type>
146 if (!(matrixPtr_->isAllocated())) {
147 UTIL_THROW(
"Cannot read unallocated DMatrix");
149 if (n() != matrixPtr_->capacity1()) {
150 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity1()");
152 if (n() != matrixPtr_->capacity2()) {
153 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
161 for (i = 0; i < n(); ++i) {
162 for (j = 0; j < n(); ++j) {
164 (*matrixPtr_)(i, j) = 0.0;
174 std::stringstream stream;
180 readEndBracket(stream);
185 (*matrixPtr_)(i, j) = value;
189 (*matrixPtr_)(j, i) = value;
193 if (k == (n()+1)*n()/2) {
205 template <
class Type>
208 if (!(matrixPtr_->isAllocated())) {
209 matrixPtr_->allocate(n(), n());
211 if (n() != matrixPtr_->capacity1()) {
212 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity1()");
214 if (n() != matrixPtr_->capacity2()) {
215 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
224 template <
class Type>
227 if (n() != matrixPtr_->capacity1()) {
228 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity1()");
230 if (n() != matrixPtr_->capacity2()) {
231 UTIL_THROW(
"Error: Logical size n() != DMatrix<Type>::capacity2()");
240 template <
class Type>
243 if (!(matrixPtr_->isAllocated())) {
244 matrixPtr_->allocate(n(), n());
246 if (n() != matrixPtr_->capacity1()) {
247 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity1()");
249 if (n() != matrixPtr_->capacity2()) {
250 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity2()");
253 bcast<Type>(ioCommunicator(), *matrixPtr_, n(), n(), 0);
260 template <
class Type>
265 if (!(matrixPtr_->isAllocated())) {
266 UTIL_THROW(
"Cannot read unallocated DMatrix");
268 if (n() > matrixPtr_->capacity1()) {
269 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity1()");
271 if (n() > matrixPtr_->capacity2()) {
272 UTIL_THROW(
"Error: Logical size n() > DMatrix<Type>::capacity2()");
276 out << indent() << label_ << std::endl;
280 for (i = 0; i < n(); ++i) {
281 for (j = 0; j <= i; ++j) {
282 if (i == 0 && j == 0 && !hasBrackets()) {
283 out << indent() << label_;
285 out << indent() << space;
287 out <<
Int(i, 4) <<
" " <<
Int(j, 4) <<
" "
288 << std::right << std::scientific
291 << (*matrixPtr_)(i, j)
295 writeEndBracket(out);
This file contains templates for global functions send<T>, recv<T> and bcast<T>.
Saving archive for binary istream.
Saving / output archive for binary ostream.
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.
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.
virtual void bcastValue()
Broadcast parameter value within the ioCommunicator.
Wrapper for an int, for formatted ostream output.
A label string in a file format.
An array-valued parameter in a parameter file.
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?
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.
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.