18 #ifndef FIELD_VALUES_HH_ 19 #define FIELD_VALUES_HH_ 22 #include <boost/format.hpp> 71 template<
int NRows,
int NCols,
class ET>
80 template <
int NRows,
class ET>
85 template<
int NRows,
int NCols>
99 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
double *raw_data) {
return *raw_data;}
100 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
int *raw_data) {
return *raw_data;}
103 template <
class RT>
inline RT &
set_raw_vec(RT &val,
double *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
104 template <
class RT>
inline RT &
set_raw_vec(RT &val,
int *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
105 template <
class RT>
inline RT &
set_raw_vec(RT &val,
FieldEnum *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
107 template <
class RT>
inline RT &
set_raw_fix(RT &val,
double *raw_data) { val = RT(raw_data);
return val;}
108 template <
class RT>
inline RT &
set_raw_fix(RT &val,
int *raw_data) { val = RT(raw_data);
return val;}
127 template<
class MatrixType>
129 typedef typename MatrixType::elem_type ET;
130 unsigned int nrows = value.n_rows;
131 unsigned int ncols = value.n_cols;
134 if (it->size() == 1 && nrows == ncols) {
139 if (rec.
size() == 1) {
141 ET scalar=*(it->begin<ET>());
142 for(
unsigned int i=0; i< nrows; i++) value.at(i,i)=scalar;
143 }
else if (rec.
size() == nrows) {
145 for(
unsigned int i=0; i< nrows; i++, ++it) value.at(i,i)=*(it->begin<ET>());
146 }
else if (rec.
size() == (nrows+1)*nrows/2) {
147 for(
unsigned int row=0; row<nrows; row++)
148 for(
unsigned int col=0; col<ncols; col++)
150 value.at(row,col) = *(it->begin<ET>());
152 }
else value.at(row,col) = value.at(col,row);
156 boost::str(
boost::format(
"Initializing symmetric matrix %dx%d by vector of wrong size %d, should be 1, %d, or %d.")
157 % nrows % ncols % rec.
size() % nrows % ((nrows+1)*nrows/2)))
165 if (rec.
size() == nrows && it->size() == ncols) {
167 for (
unsigned int row = 0; row < nrows; row++, ++it) {
168 if (it->size() != ncols)
169 THROW( ExcFV_Input() << EI_InputMsg(
"Wrong number of columns.")
172 for (
unsigned int col = 0; col < ncols; col++, ++col_it)
173 value.at(row, col) = *col_it;
178 boost::str(
boost::format(
"Initializing matrix %dx%d by matrix of wrong size %dx%d.")
179 % nrows % ncols % rec.
size() % it->size() ))
191 template<
class VectorType>
193 typedef typename VectorType::elem_type ET;
194 unsigned int nrows = value.n_rows;
199 if ( rec.
size() == 1 ) {
200 for(
unsigned int i=0; i< nrows; i++)
202 }
else if ( rec.
size() == nrows ) {
203 for(
unsigned int i=0; i< nrows; i++, ++it) {
209 boost::str(
boost::format(
"Initializing vector of size %d by vector of size %d.")
210 % nrows % rec.
size() ))
231 template <
int NRows,
int NCols,
class ET>
238 const static int NRows_ = NRows;
239 const static int NCols_ = NCols;
243 if (NRows == NCols) {
259 const ET *
mem_ptr() {
return value_.memptr(); }
270 inline ET &operator() (
unsigned int i,
unsigned int j)
271 {
return value_.at(i,j); }
272 inline ET operator() (
unsigned int i,
unsigned int j)
const 273 {
return value_.at(i,j); }
274 inline operator return_type()
const 296 for(
unsigned int row=0; row<n_rows(); row++)
297 for(
unsigned int col=0; col<n_cols(); col++)
298 value_.at(row,col) = scale_coef * value_.at(row,col);
318 const static int NRows_ = 1;
319 const static int NCols_ = 1;
346 inline ET &operator() (
unsigned int,
unsigned int )
348 inline ET operator() (
unsigned int i,
unsigned int j)
const 350 inline operator return_type()
const 371 value_ = scale_coef * value_;
390 const static int NRows_ = 0;
391 const static int NCols_ = 1;
402 const ET *
mem_ptr() {
return value_.memptr(); }
411 void set_n_comp(
unsigned int n_comp) { value_ = return_type(n_comp,1); };
415 {
return value_.n_rows; }
416 inline ET &operator() (
unsigned int i,
unsigned int )
417 {
return value_.at(i); }
418 inline ET operator() (
unsigned int i,
unsigned int j)
const 419 {
return value_.at(i); }
421 inline operator return_type()
const 443 for(
unsigned int i=0; i< n_rows(); i++) {
444 value_.at(i) = scale_coef * value_.at(i);
455 template <
int NRows,
class ET>
462 const static int NRows_ = NRows;
463 const static int NCols_ = 1;
476 const ET *
mem_ptr() {
return value_.memptr(); }
487 inline ET &operator() (
unsigned int i,
unsigned int )
488 {
return value_.at(i); }
489 inline ET operator() (
unsigned int i,
unsigned int j)
const 490 {
return value_.at(i); }
492 inline operator return_type()
const 514 for(
unsigned int i=0; i< n_rows(); i++) {
515 value_.at(i) = scale_coef * value_.at(i);
537 : n_rows(n_rows),n_cols(n_cols), values_(n_rows*n_cols) {}
539 std::string &
at(
unsigned int row) {
return at(row,0); }
540 std::string &
at(
unsigned int row,
unsigned int col) {
return values_[col*n_rows+row]; }
543 for(
auto &elem: values_) elem =
"0.0";
553 template<
int NRows,
int NCols>
558 if (NRows == NCols) {
578 tensor.
at(0,0) = input;
602 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)
void scale(double scale_coef)
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)
static constexpr bool value
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
static constexpr bool is_scalable()
internal::InputType< ET >::type ElementInputType
internal::ReturnType< NRows, 1, ET >::return_type return_type
void scale(double scale_coef)
bool equal_to(const return_type &other)
static constexpr bool is_scalable()
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
static constexpr bool is_scalable()
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
void scale(double scale_coef)
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)
void scale(double scale_coef)
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()
FieldValue_< 1, 1, double > Scalar
bool equal_to(const return_type &other)
FieldValue_(return_type &val)
unsigned int n_rows() const
static constexpr bool is_scalable()