18 #ifndef FIELD_VALUES_HH_
19 #define FIELD_VALUES_HH_
22 #include <boost/core/explicit_operator_bool.hpp>
23 #include <boost/optional/optional.hpp>
31 #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>());
171 fmt::format(
"Initializing symmetric matrix {:d}x{:d} by vector of wrong size {:d}, "
172 "should be 1, {:d}, or {:d}.",
173 nrows, ncols, rec.
size(), nrows, (nrows+1)*nrows/2))
181 if (rec.
size() == nrows &&
it->size() == ncols) {
183 for (
unsigned int row = 0; row < nrows; row++, ++
it) {
184 if (
it->size() != ncols)
185 THROW( ExcFV_Input() << EI_InputMsg(
"Wrong number of columns.")
188 for (
unsigned int col = 0; col < ncols; col++, ++col_it)
189 value.at(row, col) = *col_it;
194 fmt::format(
"Initializing symmetric matrix {:d}x{:d} by vector of wrong size {:d}x{:d}.",
195 nrows, ncols, rec.
size(),
it->size()))
207 template<
class VectorType>
209 typedef typename VectorType::elem_type ET;
210 unsigned int nrows =
value.n_rows;
215 if (
it->size() == 1 && rec.
size() == 1 ) {
216 InnerType v = *(
it->begin<InnerType>());
217 for(
unsigned int i=0; i< nrows; i++)
219 }
else if (
it->size() == 1 && rec.
size() == nrows ) {
220 for(
unsigned int i=0; i< nrows; i++, ++
it) {
221 InnerType v = *(
it->begin<InnerType>());
226 << EI_InputMsg(
fmt::format(
"Initializing vector of size {:d} by vector of other size or by tensor", nrows))
247 template <
int NRows,
int NCols,
class ET>
272 return arr.template mat<NRows, NCols>(idx);
285 {
return value_.at(i,j); }
287 {
return value_.at(i,j); }
305 return arma::max(arma::max(arma::abs(
value_ - other))) < 4*std::numeric_limits<ET>::epsilon();
310 for(
unsigned int row=0; row<
n_rows(); row++)
311 for(
unsigned int col=0; col<
n_cols(); col++)
357 if (
it->size() == 1 && rec.
size() == 1) {
362 << EI_InputMsg(
"Initializing scalar field value by vector or tensor")
394 return std::abs((
double)
value_ - other) < 4*std::numeric_limits<ET>::epsilon();
432 return arr.template vec<NRows_>(idx);
469 return arma::max(arma::abs(
value_ - other)) < 4*std::numeric_limits<ET>::epsilon();
474 for(
unsigned int i=0; i<
n_rows(); i++) {
486 template <
int NRows,
class ET>
509 return arr.template vec<NRows>(idx);
543 return arma::max(arma::abs(
value_ - other)) < 4*std::numeric_limits<ET>::epsilon();
548 for(
unsigned int i=0; i<
n_rows(); i++) {
566 template <
int spacedim>
Type scalar(uint mat_index) const
unsigned int n_cols() const
void scale(double scale_coef)
internal::ReturnType< 0, 1, ET >::return_type return_type
static const return_type & from_raw(return_type &val, ET *raw_data)
static constexpr bool is_scalable()
void set_n_comp(unsigned int n_comp)
unsigned int n_rows() const
const ET * mem_ptr() const
static std::string type_name()
FieldValue_(return_type &val)
bool equal_to(const return_type &other)
internal::InputType< ET >::type ElementInputType
static return_type get_from_array(const Armor::Array< element_type > &arr, uint idx)
Casts value stored in Armor::Array to return type.
void init_from_input(AccessType rec)
unsigned int n_cols() const
static return_type get_from_array(const Armor::Array< element_type > &arr, uint idx)
Casts value stored in Armor::Array to return type.
static constexpr bool is_scalable()
unsigned int n_rows() const
const ET * mem_ptr() const
FieldValue_(return_type &val)
bool equal_to(const return_type &other)
static std::string type_name()
void set_n_comp(unsigned int)
void init_from_input(Input::Array rec)
internal::ReturnType< 1, 1, ET >::return_type return_type
internal::InputType< ET >::type ElementInputType
void scale(double scale_coef)
internal::AccessTypeDispatch< ET >::type AccessType
static const return_type & from_raw(return_type &val, ET *raw_data)
unsigned int n_cols() const
unsigned int n_rows() const
internal::ReturnType< NRows, 1, ET >::return_type return_type
static std::string type_name()
void set_n_comp(unsigned int)
internal::InputType< ET >::type ElementInputType
bool equal_to(const return_type &other)
static return_type get_from_array(const Armor::Array< element_type > &arr, uint idx)
Casts value stored in Armor::Array to return type.
static constexpr bool is_scalable()
static const return_type & from_raw(return_type &val, ET *raw_data)
void scale(double scale_coef)
FieldValue_(return_type &val)
void init_from_input(AccessType rec)
const ET * mem_ptr() const
void init_from_input(AccessType rec)
internal::InputType< ET >::type ElementInputType
static return_type get_from_array(const Armor::Array< element_type > &arr, uint idx)
Casts value stored in Armor::Array to return type.
bool equal_to(const return_type &other)
static std::string type_name()
static const return_type & from_raw(return_type &val, ET *raw_data)
const ET * mem_ptr() const
ET & operator()(unsigned int i, unsigned int j)
internal::ReturnType< NRows, NCols, ET >::return_type return_type
FieldValue_(return_type &val)
unsigned int n_cols() const
static constexpr bool is_scalable()
unsigned int n_rows() const
void scale(double scale_coef)
void set_n_comp(unsigned int)
TYPEDEF_ERR_INFO(EI_InputMsg, const string)
DECLARE_INPUT_EXCEPTION(ExcFV_Input,<< "Wrong field value input: "<< EI_InputMsg::val)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
static constexpr bool value
std::string format(CStringRef format_str, ArgList args)
void init_matrix_from_input(MatrixType &value, Input::Array rec)
RT & set_raw_fix(RT &val, double *raw_data)
RT & set_raw_vec(RT &val, double *raw_data)
void init_vector_from_input(VectorType &value, Input::Array rec)
RT & set_raw_scalar(RT &, double *raw_data)
FieldValue_< 0, 1, FieldEnum > EnumVector
FieldValue_< 0, 1, int > IntVector
FieldValue_< spacedim, spacedim, double > TensorFixed
FieldValue_< 1, 1, int > Integer
FieldValue_< 0, 1, double > Vector
FieldValue_< 1, 1, FieldEnum > Enum
FieldValue_< 1, 1, double > Scalar
FieldValue_< spacedim, 1, double > VectorFixed
arma::Col< ET > return_type
arma::Col< unsigned int > return_type
arma::Col< ET >::template fixed< NRows > return_type
arma::Col< unsigned int >::template fixed< NRows > return_type
arma::Mat< unsigned int >::template fixed< NRows, NCols > return_type
arma::Mat< ET >::template fixed< NRows, NCols > return_type