10 #ifndef FIELD_VALUES_HH_
11 #define FIELD_VALUES_HH_
14 #include <boost/format.hpp>
44 std::string &
at(
unsigned int row) {
return at(row,0); }
45 std::string &
at(
unsigned int row,
unsigned int col) {
return values_[col*
n_rows+row]; }
47 for(
auto &elem:
values_) elem =
"0.0";
52 operator std::string() {
82 ASSERT( ref.
n_rows==1 ,
"Converting StringTensor(n,m) too std::string with m!=1 or n!=1.");
107 template<
int NRows,
int NCols,
class ET>
116 template <
int NRows,
class ET>
121 template<
int NRows,
int NCols>
135 template<
int NRows,
int NCols>
149 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
double *raw_data) {
return *raw_data;}
150 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
int *raw_data) {
return *raw_data;}
151 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
string *raw_data) {
return val;}
154 template <
class RT>
inline RT &
set_raw_vec(RT &val,
double *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
155 template <
class RT>
inline RT &
set_raw_vec(RT &val,
int *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
156 template <
class RT>
inline RT &
set_raw_vec(RT &val,
string *raw_data) {
return val;}
157 template <
class RT>
inline RT &
set_raw_vec(RT &val,
FieldEnum *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
159 template <
class RT>
inline RT &
set_raw_fix(RT &val,
double *raw_data) { val = RT(raw_data);
return val;}
160 template <
class RT>
inline RT &
set_raw_fix(RT &val,
int *raw_data) { val = RT(raw_data);
return val;}
161 template <
class RT>
inline RT &
set_raw_fix(RT &val,
string *raw_data) {
return val;}
187 template <
int NRows,
int NCols,
class ET>
199 if (element_input_type) {
224 if (it->size() == 1 && NRows == NCols) {
231 if (rec.
size() == 1) {
233 ET scalar=*(it->begin<ET>());
234 for(
unsigned int i=0; i< NRows; i++)
value_.at(i,i)=scalar;
235 }
else if (rec.
size() == NRows) {
237 for(
unsigned int i=0; i< NRows; i++, ++it)
value_.at(i,i)=*(it->begin<ET>());
238 }
else if (rec.
size() == (NRows+1)*NRows/2) {
239 for(
unsigned int row=0; row<NRows; row++)
240 for(
unsigned int col=0; col<NCols; col++)
242 value_.at(row,col) = *(it->begin<ET>());
248 boost::str(boost::format(
"Initializing symmetric matrix %dx%d by vector of wrong size %d, should be 1, %d, or %d.")
249 % NRows % NCols % rec.
size() % NRows % ((NRows+1)*NRows/2)))
257 if (rec.
size() == NRows && it->size() == NCols) {
259 for (
unsigned int row = 0; row < NRows; row++, ++it) {
260 if (it->size() != NCols)
261 THROW( ExcFV_Input() << EI_InputMsg(
"Wrong number of columns.")
264 for (
unsigned int col = 0; col < NCols; col++, ++col_it)
265 value_.at(row, col) = *col_it;
270 boost::str(boost::format(
"Initializing matrix %dx%d by matrix of wrong size %dx%d.")
271 % NRows % NCols % rec.
size() % it->size() ))
284 {
return value_.at(i,j); }
286 {
return value_.at(i,j); }
314 static ElementInputType
get_input_type(
const ElementInputType *element_input_type=
nullptr)
316 if (element_input_type)
317 return *element_input_type;
368 if (element_input_type) {
369 return IT::Array( *element_input_type, 1);
384 if ( rec.
size() == 1 ) {
385 for(
unsigned int i=0; i<
n_rows(); i++)
388 for(
unsigned int i=0; i<
n_rows(); i++, ++it) {
394 boost::str(boost::format(
"Initializing vector of size %d by vector of size %d.")
420 template <
int NRows,
class ET>
433 if (element_input_type) {
434 return IT::Array( *element_input_type, 1, NRows);
447 if ( rec.
size() == 1 ) {
448 for(
unsigned int i=0; i<
n_rows(); i++)
450 }
else if ( rec.
size() == NRows ) {
451 for(
unsigned int i=0; i< NRows; i++, ++it)
456 boost::str(boost::format(
"Initializing fixed vector of size %d by vector of size %d.")
491 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)
void set_n_comp(unsigned int)
arma::Col< unsigned int > return_type
std::vector< std::string > values_
ET & operator()(unsigned int i, unsigned int j)
internal::InputType< ET >::type ElementInputType
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)
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_from_input(AccessType rec)
static ElementInputType get_input_type(const ElementInputType *element_input_type=nullptr)
static IT::Array get_input_type(const ElementInputType *element_input_type=nullptr)
arma::Col< unsigned int >::template fixed< NRows > return_type
StringTensor(unsigned int n_rows, unsigned int n_cols)
internal::InputType< ET >::type ElementInputType
static std::string type_name()
FieldValue_< 0, 1, FieldEnum > EnumVector
static IT::Array get_input_type(const ElementInputType *element_input_type=nullptr)
#define ASSERT_EQUAL(a, b)
internal::InputType< ET >::type ElementInputType
internal::ReturnType< NRows, 1, ET >::return_type return_type
std::string & at(unsigned int row, unsigned int col)
FieldValue_< spacedim, 1, double > VectorFixed
AccessTypeDispatch< ET >::type AccessType
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)
StringTensor(const std::string &value)
unsigned int n_cols() const
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
const std::string * memptr()
FieldValue_(return_type &val)
FieldValue_< 0, 1, double > Vector
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
double & scalar_value_conversion(double &ref)
static IT::Array get_input_type(const ElementInputType *element_input_type=nullptr)
RT & set_raw_scalar(RT &val, double *raw_data)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
std::string type_name_(double)
FieldValue_< 1, 1, double > Scalar
FieldValue_(return_type &val)
unsigned int n_rows() const