18 #ifndef FIELD_VALUES_HH_ 19 #define FIELD_VALUES_HH_ 22 #include <boost/format.hpp> 70 template<
int NRows,
int NCols,
class ET>
79 template <
int NRows,
class ET>
84 template<
int NRows,
int NCols>
98 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
double *raw_data) {
return *raw_data;}
99 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
int *raw_data) {
return *raw_data;}
102 template <
class RT>
inline RT &
set_raw_vec(RT &val,
double *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
103 template <
class RT>
inline RT &
set_raw_vec(RT &val,
int *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
104 template <
class RT>
inline RT &
set_raw_vec(RT &val,
FieldEnum *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
106 template <
class RT>
inline RT &
set_raw_fix(RT &val,
double *raw_data) { val = RT(raw_data);
return val;}
107 template <
class RT>
inline RT &
set_raw_fix(RT &val,
int *raw_data) { val = RT(raw_data);
return val;}
126 template<
class MatrixType>
128 typedef typename MatrixType::elem_type ET;
129 unsigned int nrows = value.n_rows;
130 unsigned int ncols = value.n_cols;
133 if (it->size() == 1 && nrows == ncols) {
138 if (rec.
size() == 1) {
140 ET scalar=*(it->begin<ET>());
141 for(
unsigned int i=0; i< nrows; i++) value.at(i,i)=scalar;
142 }
else if (rec.
size() == nrows) {
144 for(
unsigned int i=0; i< nrows; i++, ++it) value.at(i,i)=*(it->begin<ET>());
145 }
else if (rec.
size() == (nrows+1)*nrows/2) {
146 for(
unsigned int row=0; row<nrows; row++)
147 for(
unsigned int col=0; col<ncols; col++)
149 value.at(row,col) = *(it->begin<ET>());
151 }
else value.at(row,col) = value.at(col,row);
155 boost::str(
boost::format(
"Initializing symmetric matrix %dx%d by vector of wrong size %d, should be 1, %d, or %d.")
156 % nrows % ncols % rec.
size() % nrows % ((nrows+1)*nrows/2)))
164 if (rec.
size() == nrows && it->size() == ncols) {
166 for (
unsigned int row = 0; row < nrows; row++, ++it) {
167 if (it->size() != ncols)
168 THROW( ExcFV_Input() << EI_InputMsg(
"Wrong number of columns.")
171 for (
unsigned int col = 0; col < ncols; col++, ++col_it)
172 value.at(row, col) = *col_it;
177 boost::str(
boost::format(
"Initializing matrix %dx%d by matrix of wrong size %dx%d.")
178 % nrows % ncols % rec.
size() % it->size() ))
190 template<
class VectorType>
192 typedef typename VectorType::elem_type ET;
193 unsigned int nrows = value.n_rows;
198 if ( rec.
size() == 1 ) {
199 for(
unsigned int i=0; i< nrows; i++)
201 }
else if ( rec.
size() == nrows ) {
202 for(
unsigned int i=0; i< nrows; i++, ++it) {
208 boost::str(
boost::format(
"Initializing vector of size %d by vector of size %d.")
209 % nrows % rec.
size() ))
230 template <
int NRows,
int NCols,
class ET>
237 const static int NRows_ = NRows;
238 const static int NCols_ = NCols;
242 if (NRows == NCols) {
255 const ET *
mem_ptr() {
return value_.memptr(); }
266 inline ET &operator() (
unsigned int i,
unsigned int j)
267 {
return value_.at(i,j); }
268 inline ET operator() (
unsigned int i,
unsigned int j)
const 269 {
return value_.at(i,j); }
270 inline operator return_type()
const 307 const static int NRows_ = 1;
308 const static int NCols_ = 1;
332 inline ET &operator() (
unsigned int,
unsigned int )
334 inline ET operator() (
unsigned int i,
unsigned int j)
const 336 inline operator return_type()
const 371 const static int NRows_ = 0;
372 const static int NCols_ = 1;
380 const ET *
mem_ptr() {
return value_.memptr(); }
389 void set_n_comp(
unsigned int n_comp) { value_ = return_type(n_comp,1); };
393 {
return value_.n_rows; }
394 inline ET &operator() (
unsigned int i,
unsigned int )
395 {
return value_.at(i); }
396 inline ET operator() (
unsigned int i,
unsigned int j)
const 397 {
return value_.at(i); }
399 inline operator return_type()
const 426 template <
int NRows,
class ET>
433 const static int NRows_ = NRows;
434 const static int NCols_ = 1;
444 const ET *
mem_ptr() {
return value_.memptr(); }
455 inline ET &operator() (
unsigned int i,
unsigned int )
456 {
return value_.at(i); }
457 inline ET operator() (
unsigned int i,
unsigned int j)
const 458 {
return value_.at(i); }
460 inline operator return_type()
const 498 : n_rows(n_rows),n_cols(n_cols), values_(n_rows*n_cols) {}
500 std::string &
at(
unsigned int row) {
return at(row,0); }
501 std::string &
at(
unsigned int row,
unsigned int col) {
return values_[col*n_rows+row]; }
504 for(
auto &elem: values_) elem =
"0.0";
514 template<
int NRows,
int NCols>
519 if (NRows == NCols) {
539 tensor.
at(0,0) = input;
563 template <
int spacedim>
void init_from_input(AccessType val)
internal::ReturnType< 1, 1, ET >::return_type return_type
arma::Col< ET > return_type
internal::InputType< ET >::type ElementInputType
static const return_type & from_raw(return_type &val, ET *raw_data)
static IT::Array get_input_type()
void set_n_comp(unsigned int)
arma::Col< unsigned int > return_type
std::vector< std::string > values_
internal::InputType< ET >::type ElementInputType
bool equal_to(const return_type &other)
FieldValue_< 0, 1, int > IntVector
static const return_type & from_raw(return_type &val, ET *raw_data)
void set_n_comp(unsigned int n_comp)
std::string format(CStringRef format_str, ArgList args)
void set_n_comp(unsigned int)
void init_from_input(AccessType rec)
static std::string type_name()
RT & set_raw_vec(RT &val, double *raw_data)
void set_n_comp(unsigned int)
unsigned int n_cols() const
internal::ReturnType< NRows, NCols, ET >::return_type return_type
FieldValue_(return_type &val)
void init_from_input(AccessType rec)
FieldValue_< 1, 1, FieldEnum > Enum
void init_matrix_from_input(MatrixType &value, Input::Array rec)
void init_from_input(AccessType rec)
arma::Col< unsigned int >::template fixed< NRows > return_type
StringTensor(unsigned int n_rows, unsigned int n_cols)
internal::InputType< ET >::type ElementInputType
static IT::Array get_input_type()
static std::string type_name()
FieldValue_< 0, 1, FieldEnum > EnumVector
internal::InputType< ET >::type ElementInputType
internal::ReturnType< NRows, 1, ET >::return_type return_type
bool equal_to(const return_type &other)
std::string & at(unsigned int row, unsigned int col)
FieldValue_< spacedim, 1, double > VectorFixed
bool equal_to(const return_type &other)
void init_vector_from_input(VectorType &value, Input::Array rec)
static std::string type_name()
unsigned int n_rows() const
RT & set_raw_fix(RT &val, double *raw_data)
arma::Mat< ET >::template fixed< NRows, NCols > return_type
internal::ReturnType< 0, 1, ET >::return_type return_type
TYPEDEF_ERR_INFO(EI_InputMsg, const string)
std::string & at(unsigned int row)
unsigned int n_cols() const
static IT::Array get_input_type()
unsigned int n_rows() const
arma::Mat< unsigned int >::template fixed< NRows, NCols > return_type
unsigned int n_cols() const
FieldValue_< 1, 1, int > Integer
FieldValue_(return_type &val)
FieldValue_< 0, 1, double > Vector
internal::AccessTypeDispatch< ET >::type AccessType
static std::string type_name()
DECLARE_INPUT_EXCEPTION(ExcFV_Input,<< "Wrong field value input: "<< EI_InputMsg::val)
static const return_type & from_raw(return_type &val, ET *raw_data)
FieldValue_(return_type &val)
static const return_type & from_raw(return_type &val, ET *raw_data)
FieldValue_< spacedim, spacedim, double > TensorFixed
unsigned int n_rows() const
unsigned int n_cols() const
arma::Col< ET >::template fixed< NRows > return_type
RT & set_raw_scalar(RT &val, double *raw_data)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
static IT::Parameter get_input_type()
std::string type_name_(double)
FieldValue_< 1, 1, double > Scalar
bool equal_to(const return_type &other)
FieldValue_(return_type &val)
unsigned int n_rows() const