18 #ifndef FIELD_VALUES_HH_ 19 #define FIELD_VALUES_HH_ 22 #include <boost/core/explicit_operator_bool.hpp> 23 #include <boost/exception/detail/error_info_impl.hpp> 24 #include <boost/exception/info.hpp> 25 #include <boost/format.hpp> 26 #include <boost/optional/optional.hpp> 34 #include <type_traits> 86 template<
int NRows,
int NCols,
class ET>
95 template <
int NRows,
class ET>
100 template<
int NRows,
int NCols>
114 template <
class RT>
inline RT &
set_raw_scalar(RT &,
double *raw_data) {
return *raw_data;}
115 template <
class RT>
inline RT &
set_raw_scalar(RT &,
int *raw_data) {
return *raw_data;}
118 template <
class RT>
inline RT &
set_raw_vec(RT &val,
double *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
119 template <
class RT>
inline RT &
set_raw_vec(RT &val,
int *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
120 template <
class RT>
inline RT &
set_raw_vec(RT &val,
FieldEnum *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
122 template <
class RT>
inline RT &
set_raw_fix(RT &val,
double *raw_data) { val = RT(raw_data);
return val;}
123 template <
class RT>
inline RT &
set_raw_fix(RT &val,
int *raw_data) { val = RT(raw_data);
return val;}
142 template<
class MatrixType>
144 typedef typename MatrixType::elem_type ET;
145 unsigned int nrows = value.n_rows;
146 unsigned int ncols = value.n_cols;
149 if (it->size() == 1 && nrows == ncols) {
154 if (rec.
size() == 1) {
156 ET scalar=*(it->begin<ET>());
157 for(
unsigned int i=0; i< nrows; i++) value.at(i,i)=scalar;
158 }
else if (rec.
size() == nrows) {
160 for(
unsigned int i=0; i< nrows; i++, ++it) value.at(i,i)=*(it->begin<ET>());
161 }
else if (rec.
size() == (nrows+1)*nrows/2) {
162 for(
unsigned int row=0; row<nrows; row++)
163 for(
unsigned int col=0; col<ncols; col++)
165 value.at(row,col) = *(it->begin<ET>());
167 }
else value.at(row,col) = value.at(col,row);
171 boost::str(
boost::format(
"Initializing symmetric matrix %dx%d by vector of wrong size %d, should be 1, %d, or %d.")
172 % nrows % ncols % rec.
size() % nrows % ((nrows+1)*nrows/2)))
180 if (rec.
size() == nrows && it->size() == ncols) {
182 for (
unsigned int row = 0; row < nrows; row++, ++it) {
183 if (it->size() != ncols)
184 THROW( ExcFV_Input() << EI_InputMsg(
"Wrong number of columns.")
187 for (
unsigned int col = 0; col < ncols; col++, ++col_it)
188 value.at(row, col) = *col_it;
193 boost::str(
boost::format(
"Initializing matrix %dx%d by matrix of wrong size %dx%d.")
194 % nrows % ncols % rec.
size() % it->size() ))
206 template<
class VectorType>
208 typedef typename VectorType::elem_type ET;
209 unsigned int nrows = value.n_rows;
214 if ( rec.
size() == 1 ) {
215 for(
unsigned int i=0; i< nrows; i++)
217 }
else if ( rec.
size() == nrows ) {
218 for(
unsigned int i=0; i< nrows; i++, ++it) {
224 boost::str(
boost::format(
"Initializing vector of size %d by vector of size %d.")
225 % nrows % rec.
size() ))
246 template <
int NRows,
int NCols,
class ET>
253 const static int NRows_ = NRows;
254 const static int NCols_ = NCols;
255 const static int rank_ = 2;
259 if (NRows == NCols) {
276 return value_.memptr();
288 inline ET &operator() (
unsigned int i,
unsigned int j)
289 {
return value_.at(i,j); }
290 inline ET operator() (
unsigned int i,
unsigned int j)
const 291 {
return value_.at(i,j); }
292 inline operator return_type()
const 309 return arma::max(arma::max(arma::abs(value_ - other))) < 4*std::numeric_limits<ET>::epsilon();
314 for(
unsigned int row=0; row<n_rows(); row++)
315 for(
unsigned int col=0; col<n_cols(); col++)
316 value_.at(row,col) = scale_coef * value_.at(row,col);
336 const static int NRows_ = 1;
337 const static int NCols_ = 1;
338 const static int rank_ = 0;
356 const ET *
mem_ptr()
const {
return &(value_); }
365 inline ET &operator() (
unsigned int,
unsigned int )
367 inline ET operator() (
unsigned int,
unsigned int)
const 369 inline operator return_type()
const 385 return std::abs((
double)value_ - other) < 4*std::numeric_limits<ET>::epsilon();
390 value_ = scale_coef * value_;
409 const static int NRows_ = 0;
410 const static int NCols_ = 1;
411 const static int rank_ = 10;
422 const ET *
mem_ptr()
const {
return value_.memptr(); }
431 void set_n_comp(
unsigned int n_comp) { value_ = return_type(n_comp,1); };
435 {
return value_.n_rows; }
436 inline ET &operator() (
unsigned int i,
unsigned int )
437 {
return value_.at(i); }
438 inline ET operator() (
unsigned int i,
unsigned int )
const 439 {
return value_.at(i); }
441 inline operator return_type()
const 458 return arma::max(arma::abs(value_ - other)) < 4*std::numeric_limits<ET>::epsilon();
463 for(
unsigned int i=0; i< n_rows(); i++) {
464 value_.at(i) = scale_coef * value_.at(i);
475 template <
int NRows,
class ET>
482 const static int NRows_ = NRows;
483 const static int NCols_ = 1;
484 const static int rank_ = 1;
497 const ET *
mem_ptr()
const {
return value_.memptr(); }
508 inline ET &operator() (
unsigned int i,
unsigned int )
509 {
return value_.at(i); }
510 inline ET operator() (
unsigned int i,
unsigned int )
const 511 {
return value_.at(i); }
513 inline operator return_type()
const 530 return arma::max(arma::abs(value_ - other)) < 4*std::numeric_limits<ET>::epsilon();
535 for(
unsigned int i=0; i< n_rows(); i++) {
536 value_.at(i) = scale_coef * value_.at(i);
558 : n_rows(n_rows),n_cols(n_cols), values_(n_rows*n_cols) {}
560 std::string &
at(
unsigned int row) {
return at(row,0); }
561 std::string &
at(
unsigned int row,
unsigned int col) {
return values_[col*n_rows+row]; }
564 for(
auto &elem: values_) elem =
"0.0";
574 template<
int NRows,
int NCols>
579 if (NRows == NCols) {
599 tensor.
at(0,0) = input;
623 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_
RT & set_raw_scalar(RT &, double *raw_data)
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)
const ET * mem_ptr() const
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
const ET * mem_ptr() const
static constexpr bool is_scalable()
internal::InputType< ET >::type ElementInputType
const ET * mem_ptr() const
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
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
static IT::Parameter get_input_type()
FieldValue_< 1, 1, double > Scalar
const ET * mem_ptr() const
bool equal_to(const return_type &other)
FieldValue_(return_type &val)
unsigned int n_rows() const
static constexpr bool is_scalable()