23 #include <boost/foreach.hpp> 32 template <
int spacedim, class Value>
40 "String, array of strings, or matrix of strings with formulas for individual " 41 "entries of scalar, vector, or tensor value respectively.\n" 42 "For vector values, you can use just one string to enter homogeneous vector.\n" 43 "For square (($N\\times N$))-matrix values, you can use:\n\n" 44 " - array of strings of size (($N$)) to enter diagonal matrix\n" 45 " - array of strings of size (($\\frac12N(N+1)$)) to enter symmetric matrix (upper triangle, row by row)\n" 46 " - just one string to enter (spatially variable) multiple of the unit matrix.\n" 47 "Formula can contain variables ```x,y,z,t``` and usual operators and functions." )
56 template <
int spacedim,
class Value>
58 Input::register_class< FieldFormula<spacedim, Value>,
unsigned int >(
"FieldFormula") +
63 template <
int spacedim,
class Value>
66 formula_matrix_(this->value_.n_rows(), this->value_.n_cols())
69 for(
unsigned int row=0; row < this->
value_.n_rows(); row++) {
76 template <
int spacedim,
class Value>
86 template <
int spacedim,
class Value>
90 bool any_parser_changed =
false;
93 std::string vars = string(
"x,y,z").substr(0, 2*spacedim-1);
95 for(
unsigned int row=0; row < this->
value_.n_rows(); row++)
96 for(
unsigned int col=0; col < this->
value_.n_cols(); col++) {
100 FunctionParser tmp_parser;
101 tmp_parser.AddConstant(
"Pi", 3.14159265358979323846);
102 tmp_parser.AddConstant(
"E", 2.71828182845904523536);
105 #pragma GCC diagnostic push 106 #pragma GCC diagnostic ignored "-Wunused-variable" 108 int err=tmp_parser.ParseAndDeduceVariables(
formula_matrix_.
at(row,col), var_list);
109 OLD_ASSERT( err != FunctionParser::FP_NO_ERROR,
"ParseAndDeduceVariables error: %s\n", tmp_parser.ErrorMsg() );
111 #pragma GCC diagnostic pop 113 bool time_dependent =
false;
114 BOOST_FOREACH(std::string &var_name, var_list ) {
115 if (var_name == std::string(
"t") ) time_dependent=
true;
116 else if (var_name ==
"x" || var_name ==
"y" || var_name ==
"z")
continue;
118 WarningOut().fmt(
"Unknown variable '{}' in the FieldFormula[{}][{}] == '{}'\n at the input address:\n {} \n",
123 parser_matrix_[row][col].AddConstant(
"Pi", 3.14159265358979323846);
124 parser_matrix_[row][col].AddConstant(
"E", 2.71828182845904523536);
125 if (time_dependent) {
136 if (
parser_matrix_[row][col].GetParseErrorType() != FunctionParser::FP_NO_ERROR ) {
137 xprintf(
UsrErr,
"ParserError: %s\n in the FieldFormula[%d][%d] == '%s'\n at the input address:\n %s \n",
144 any_parser_changed =
true;
151 return any_parser_changed;
158 template <
int spacedim,
class Value>
161 for(
unsigned int row=0; row < this->
value_.n_rows(); row++)
162 for(
unsigned int col=0; col < this->
value_.n_cols(); col++) {
172 template <
int spacedim,
class Value>
177 for(
unsigned int i=0; i< point_list.size(); i++) {
178 Value envelope(value_list[i]);
180 "value_list[%d] has wrong number of rows: %d; should match number of components: %d\n",
181 i, envelope.n_rows(),this->
value_.n_rows());
183 for(
unsigned int row=0; row < this->
value_.n_rows(); row++)
184 for(
unsigned int col=0; col < this->
value_.n_cols(); col++) {
191 template <
int spacedim,
class Value>
TimeStep time_
Actual time level; initial value is -infinity.
void init_unit_conversion_coefficient(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data)
Init value of unit_conversion_coefficient_ from input.
#define INSTANCE_ALL(field)
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
Value::return_type r_value_
double unit_conversion_coefficient_
Coeficient of conversion of user-defined unit.
Space< spacedim >::Point Point
std::string & at(unsigned int row)
Value value_
Last value, prevents passing large values (vectors) by value.
#define WarningOut()
Macro defining 'warning' record of log.
#define OLD_ASSERT_EQUAL(a, b)
Representation of one time step..
#define FLOW123D_FORCE_LINK_IN_CHILD(x)