Flow123d
release_3.0.0-968-gc87a28e79
|
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>
85 template<
int NRows,
int NCols,
class ET>
94 template <
int NRows,
class ET>
99 template<
int NRows,
int NCols>
113 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
double *raw_data) {
return *raw_data;}
114 template <
class RT>
inline RT &
set_raw_scalar(RT &val,
int *raw_data) {
return *raw_data;}
117 template <
class RT>
inline RT &
set_raw_vec(RT &val,
double *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
118 template <
class RT>
inline RT &
set_raw_vec(RT &val,
int *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
119 template <
class RT>
inline RT &
set_raw_vec(RT &val,
FieldEnum *raw_data) { arma::access::rw(val.mem) = raw_data;
return val;}
121 template <
class RT>
inline RT &
set_raw_fix(RT &val,
double *raw_data) { val = RT(raw_data);
return val;}
122 template <
class RT>
inline RT &
set_raw_fix(RT &val,
int *raw_data) { val = RT(raw_data);
return val;}
141 template<
class MatrixType>
143 typedef typename MatrixType::elem_type ET;
144 unsigned int nrows =
value.n_rows;
145 unsigned int ncols =
value.n_cols;
148 if (
it->size() == 1 && nrows == ncols) {
153 if (rec.
size() == 1) {
155 ET scalar=*(
it->begin<ET>());
156 for(
unsigned int i=0; i< nrows; i++)
value.at(i,i)=scalar;
157 }
else if (rec.
size() == nrows) {
159 for(
unsigned int i=0; i< nrows; i++, ++
it)
value.at(i,i)=*(
it->begin<ET>());
160 }
else if (rec.
size() == (nrows+1)*nrows/2) {
161 for(
unsigned int row=0; row<nrows; row++)
162 for(
unsigned int col=0; col<ncols; col++)
164 value.at(row,col) = *(
it->begin<ET>());
170 fmt::format(
"Initializing symmetric matrix {:d}x{:d} by vector of wrong size {:d}, "
171 "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 fmt::format(
"Initializing symmetric matrix {:d}x{:d} by vector of wrong size {:d}x{: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 fmt::format(
"Initializing vector of size {:d} by vector of size {%d.}",
246 template <
int NRows,
int NCols,
class ET>
259 if (NRows == NCols) {
289 {
return value_.at(i,j); }
291 {
return value_.at(i,j); }
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++)
385 return std::abs((
double)
value_ - other) < 4*std::numeric_limits<ET>::epsilon();
458 return arma::max(arma::abs(
value_ - other)) < 4*std::numeric_limits<ET>::epsilon();
463 for(
unsigned int i=0; i<
n_rows(); i++) {
475 template <
int NRows,
class ET>
530 return arma::max(arma::abs(
value_ - other)) < 4*std::numeric_limits<ET>::epsilon();
535 for(
unsigned int i=0; i<
n_rows(); i++) {
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>
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
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_
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
RT & set_raw_scalar(RT &val, double *raw_data)
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
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
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 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