Flow123d
JS_before_hm-2087-gb06a8f5d8
|
Go to the documentation of this file.
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 ( rec.
size() == 1 ) {
216 for(
unsigned int i=0; i< nrows; i++)
218 }
else if ( rec.
size() == nrows ) {
219 for(
unsigned int i=0; i< nrows; i++, ++
it) {
225 fmt::format(
"Initializing vector of size {:d} by vector of size {%d.}",
247 template <
int NRows,
int NCols,
class ET>
260 if (NRows == NCols) {
282 return arr.template mat<NRows, NCols>(idx);
295 {
return value_.at(i,j); }
297 {
return value_.at(i,j); }
315 return arma::max(arma::max(arma::abs(
value_ - other))) < 4*std::numeric_limits<ET>::epsilon();
320 for(
unsigned int row=0; row<
n_rows(); row++)
321 for(
unsigned int col=0; col<
n_cols(); col++)
396 return std::abs((
double)
value_ - other) < 4*std::numeric_limits<ET>::epsilon();
437 return arr.template vec<NRows_>(idx);
474 return arma::max(arma::abs(
value_ - other)) < 4*std::numeric_limits<ET>::epsilon();
479 for(
unsigned int i=0; i<
n_rows(); i++) {
491 template <
int NRows,
class ET>
517 return arr.template vec<NRows>(idx);
551 return arma::max(arma::abs(
value_ - other)) < 4*std::numeric_limits<ET>::epsilon();
556 for(
unsigned int i=0; i<
n_rows(); i++) {
581 std::string &
at(
unsigned int row) {
return at(row,0); }
582 std::string &
at(
unsigned int row,
unsigned int col) {
return values_[col*
n_rows+row]; }
585 for(
auto &elem:
values_) elem =
"0.0";
595 template<
int NRows,
int NCols>
600 if (NRows == NCols) {
620 tensor.
at(0,0) = input;
644 template <
int spacedim>
arma::Col< ET > return_type
FieldValue_< 1, 1, double > Scalar
void init_from_input(AccessType rec)
ET & operator()(unsigned int i, unsigned int j)
void set_n_comp(unsigned int)
internal::ReturnType< 0, 1, ET >::return_type return_type
unsigned int n_cols() const
static const return_type & from_raw(return_type &val, ET *raw_data)
static constexpr bool is_scalable()
void init_from_input(AccessType rec)
bool equal_to(const return_type &other)
StringTensor(unsigned int n_rows, unsigned int n_cols)
static constexpr bool value
FieldValue_< 0, 1, int > IntVector
static return_type get_from_array(const Armor::Array< element_type > &arr, uint idx)
Casts value stored in Armor::Array to return type.
internal::InputType< ET >::type ElementInputType
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
FieldValue_< 1, 1, FieldEnum > Enum
arma::Mat< ET >::template fixed< NRows, NCols > return_type
static const return_type & from_raw(return_type &val, ET *raw_data)
std::string format(CStringRef format_str, ArgList args)
internal::AccessTypeDispatch< ET >::type AccessType
arma::Mat< unsigned int >::template fixed< NRows, NCols > return_type
FieldValue_< 0, 1, FieldEnum > EnumVector
std::vector< std::string > values_
static return_type get_from_array(const Armor::Array< element_type > &arr, uint idx)
Casts value stored in Armor::Array to return type.
RT & set_raw_fix(RT &val, double *raw_data)
FieldValue_(return_type &val)
static IT::Array get_input_type()
unsigned int n_rows() const
FieldValue_(return_type &val)
static constexpr bool is_scalable()
static std::string type_name()
unsigned int n_cols() const
void set_n_comp(unsigned int)
DECLARE_INPUT_EXCEPTION(ExcFV_Input,<< "Wrong field value input: "<< EI_InputMsg::val)
static IT::Array get_input_type()
const ET * mem_ptr() const
std::string & at(unsigned int row)
unsigned int n_rows() const
bool equal_to(const return_type &other)
void scale(double scale_coef)
internal::InputType< ET >::type ElementInputType
static std::string type_name()
internal::InputType< ET >::type ElementInputType
RT & set_raw_vec(RT &val, double *raw_data)
arma::Col< unsigned int > return_type
static return_type get_from_array(const Armor::Array< element_type > &arr, uint idx)
Casts value stored in Armor::Array to return type.
FieldValue_< spacedim, 1, double > VectorFixed
const ET * mem_ptr() const
void set_n_comp(unsigned int n_comp)
void init_from_input(AccessType val)
static const return_type & from_raw(return_type &val, ET *raw_data)
void set_n_comp(unsigned int)
FieldValue_< 1, 1, int > Integer
const ET * mem_ptr() const
arma::Col< unsigned int >::template fixed< NRows > return_type
static const return_type & from_raw(return_type &val, ET *raw_data)
void scale(double scale_coef)
bool equal_to(const return_type &other)
unsigned int n_cols() const
static std::string type_name()
unsigned int n_rows() const
FieldValue_< 0, 1, double > Vector
unsigned int n_cols() const
static IT::Array get_input_type()
std::string & at(unsigned int row, unsigned int col)
arma::Col< ET >::template fixed< NRows > return_type
TYPEDEF_ERR_INFO(EI_InputMsg, const string)
internal::InputType< ET >::type ElementInputType
const ET * mem_ptr() const
RT & set_raw_scalar(RT &, double *raw_data)
void scale(double scale_coef)
static std::string type_name()
static IT::Parameter get_input_type()
void init_from_input(AccessType rec)
void scale(double scale_coef)
static return_type get_from_array(const Armor::Array< element_type > &arr, uint idx)
Casts value stored in Armor::Array to return type.
Type scalar(uint mat_index) const
static constexpr bool is_scalable()
internal::ReturnType< NRows, 1, ET >::return_type return_type
FieldValue_(return_type &val)
FieldValue_< spacedim, spacedim, double > TensorFixed
static constexpr bool is_scalable()
unsigned int n_rows() const
FieldValue_(return_type &val)
void init_matrix_from_input(MatrixType &value, Input::Array rec)
bool equal_to(const return_type &other)
void init_vector_from_input(VectorType &value, Input::Array rec)
internal::ReturnType< NRows, NCols, ET >::return_type return_type
internal::ReturnType< 1, 1, ET >::return_type return_type