21 template <
int spacedim>
23 const unsigned int &n_components,
24 const std::string &parsed_component_names,
25 const std::string &parsed_id_components,
26 const std::string &parsed_id_functions,
27 const std::string &parsed_constants):
30 str_id_components (parsed_id_components),
31 str_id_functions (parsed_id_functions),
32 str_component_names (parsed_component_names),
33 str_constants (parsed_constants),
34 n_components(n_components)
37 template <
int spacedim>
41 for (
unsigned int i=0; i<var.size(); ++i)
48 std::pair<unsigned int, std::string> nc (pos, var[i]+
".N");
54 template <
int spacedim>
68 typedef std::map<unsigned int, ComponentMask>::iterator it_type;
71 std::pair<ComponentMask, shared_ptr<dealii::Functions::ParsedFunction<spacedim> > > mapped(it->second,
id_functions[it->first]);
81 template <
int spacedim>
84 std::vector<std::string> idcomponents;
88 for (
unsigned int i=0; i<idcomponents.size(); ++i)
90 std::vector<std::string> id_comp;
91 std::vector<std::string> components;
101 ExcMessage(
"Wrong number of components specified for id " + id_comp[0]));
102 for (
unsigned int c=0; c<components.size(); ++c)
104 if (components[c] ==
"ALL")
112 ExcMessage(
"Parsed components name must match the number of components of the problem"));
136 catch (std::exception &exc)
145 template <
int spacedim>
147 const std::string &constants)
149 std::vector<unsigned int> id_defined_functions;
153 if (parsed_idfunctions ==
"")
155 for (
unsigned int i=0; i<
ids.size(); ++i)
157 id_defined_functions.push_back(
ids[i]);
158 shared_ptr<dealii::Functions::ParsedFunction<spacedim> > ptr;
161 dealii::Functions::ParsedFunction<spacedim>::declare_parameters(internal_prm,
n_components);
162 ptr =
SP(
new dealii::Functions::ParsedFunction<spacedim>(
n_components));
163 ptr->parse_parameters(internal_prm);
179 std::vector<std::string> idfunctions;
182 for (
unsigned int i=0; i<idfunctions.size(); ++i)
184 std::vector<std::string> id_func;
194 id_defined_functions.push_back(
id);
196 shared_ptr<dealii::Functions::ParsedFunction<spacedim> > ptr;
199 dealii::Functions::ParsedFunction<spacedim>::declare_parameters(internal_prm,
n_components);
200 internal_prm.
set(
"Function expression", id_func[1]);
201 internal_prm.
set(
"Function constants", constants);
202 ptr =
SP(
new dealii::Functions::ParsedFunction<spacedim>(
n_components));
203 ptr->parse_parameters(internal_prm);
213 ExcMessage(
"Ids associated to components and to functions are not the same."));
217 template <
int spacedim>
218 shared_ptr<dealii::Functions::ParsedFunction<spacedim> >
221 std::pair<unsigned int, unsigned int> id_fcv (
id,fcv);
228 template <
int spacedim>
236 template <
int spacedim>
244 template <
int spacedim>
250 template <
int spacedim>
256 template <
int spacedim>
262 "These variables can be used to set the corrisponding component mask, " 263 "instead of specifying each component number");
270 "These variables can be used to set the corrisponding component mask, " 271 "instead of specifying each component number");
276 "Pattern to be used " 277 "id followed by '=' component masks separated by ';' " 278 "each couple of id and mask is separated by '%' " 279 "0=0;1;2 % 4=u;p % 2=3 % 5=ALL " 280 "You can specify the components either by numbers " 281 "or by the corrisponding variable name, which are parsed at " 282 "construction time. " 283 "The keyword 'ALL' means all the components. " 284 "Normal component is referred with suffix N " 285 "e.g. uN means the normal component of u. " 286 "note that the normal component can be set only " 287 "for a vector variable.");
291 "Pattern to be used " 292 "id followed by '=' component separated by ';' " 293 "each couple of id and expression _id_functions separated by '%' " 294 "0=x;y;k;0 % 4=sin(x);cos(y);2*k;1 % 2=0;0;0;0 " 295 "If it is left empty, a ZeroFunction<dim>(n_components) " 296 "is applied on the parsed ids in the components. ");
299 "Costants which are employed in the definitions of the function expressions. " 300 "The pattern to be used is " 301 "constant_name=value , other_constant=other_value");
305 template <
int spacedim>
311 template <
int spacedim>
314 typedef typename std::map<unsigned int, shared_ptr<dealii::Functions::ParsedFunction<spacedim> > >::iterator it_type;
316 it->second->set_time(t);
319 template <
int spacedim>
322 typedef std::map<std::string, std::pair<std::vector<unsigned int>,
unsigned int > >::iterator it_type;
327 std::vector<unsigned int>
normal_ids = (it->second).first;
328 unsigned int fcv = (it->second).second;
330 for (
unsigned int i=0; i<normal_ids.size(); ++i)
332 std::vector<std::string> normal_func;
334 shared_ptr<dealii::Functions::ParsedFunction<spacedim> > normal_ptr;
337 dealii::Functions::ParsedFunction<spacedim>::declare_parameters(normal_prm, spacedim);
338 std::string str_normal_func;
340 for (
unsigned int j=0; j<spacedim-1; ++j)
341 str_normal_func += normal_func[fcv+j] +
";";
342 str_normal_func += normal_func[fcv+spacedim-1];
344 normal_prm.
set(
"Function expression", str_normal_func);
346 normal_ptr =
SP(
new dealii::Functions::ParsedFunction<spacedim>(spacedim));
347 normal_ptr->parse_parameters(normal_prm);
348 std::pair<unsigned int, unsigned int> id_fcv (normal_ids[i],fcv);
357 template class deal2lkit::ParsedMappedFunctions<1>;
358 template class deal2lkit::ParsedMappedFunctions<2>;
359 template class deal2lkit::ParsedMappedFunctions<3>;
A parameter acceptor base class.
const unsigned int n_components
static ParameterHandler prm
Static parameter.
std::vector< std::pair< unsigned int, std::string > > normal_components
std::map< unsigned int, std::string > id_str_functions
std::string str_id_functions
std::vector< unsigned int > ids
void set(const std::string &entry_name, const std::string &new_value)
std::vector< unsigned int > get_mapped_normal_ids() const
return the list of the mapped ids for which normal components have been set
std::vector< unsigned int > normal_ids
#define AssertThrow(cond, exc)
shared_ptr< T > SP(T *t)
Construct a shared pointer to a non const class T.
std::vector< std::string > _component_names
std::vector< unsigned int > get_mapped_ids() const
return the list of the mapped ids
std::map< unsigned int, shared_ptr< dealii::Functions::ParsedFunction< spacedim > > > id_functions
void set_normal_functions()
void set_time(const double &t)
set time equal to t for all the mapped functions
std::string str_id_components
static::ExceptionBase & ExcMessage(std::string arg1)
std::map< std::string, std::pair< std::vector< unsigned int >, unsigned int > > mapped_normal_components
void split_id_components(const std::string &parsed_idcomponents)
virtual void parse_parameters_call_back()
parse_parameters_call_back is inherithed by ParameterAcceptor
std::string str_constants
#define Assert(cond, exc)
void split_id_functions(const std::string &parsed_idfunctions, const std::string &constants)
std::string str_component_names
std::map< std::pair< unsigned int, unsigned int >, shared_ptr< dealii::Functions::ParsedFunction< spacedim > > > _normal_functions
virtual void declare_parameters(ParameterHandler &prm)
declare_parameters is inherithed by ParameterAcceptor
std::map< unsigned int, std::pair< ComponentMask, shared_ptr< dealii::Functions::ParsedFunction< spacedim > > > > mapped_functions
std::string print(const std::vector< Type > &list, const std::string sep=",")
Return a string containing the content of the vector, with elements separated by the @ sep parameter...
bool acts_on_id(unsigned int &id) const
return true if there is a function that acts on the passed id
std::vector< std::string > _normal_components
std::vector< std::string > split_string_list(const std::string &s, const char delimiter=',')
std::vector< T > unique(const std::vector< T > &myvector)
A simple function that accepts a vector as an input and returns a second vector containing only the u...
ParsedMappedFunctions(const std::string &name="Mapped Functions", const unsigned int &n_components=1, const std::string &component_names="", const std::string &default_id_components="0=ALL", const std::string &default_id_functions="", const std::string &default_constants="")
Constructor.
int string_to_int(const std::string &s)
static::ExceptionBase & ExcNotImplemented()
shared_ptr< dealii::Functions::ParsedFunction< spacedim > > get_mapped_function(const unsigned int &id) const
return a shared_ptr to the ParsedFunction corresponding to the given id
void add_parameter(ParameterHandler &prm, T *parameter, const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
Add a parameter the given parameter list.
shared_ptr< dealii::Functions::ParsedFunction< spacedim > > get_mapped_normal_function(const unsigned int &id, const unsigned int &fcv) const
return a shared_ptr to the ParsedFunction corresponding to the given id the function has spacedim com...
void add_normal_components()
std::map< unsigned int, ComponentMask > id_components
ComponentMask get_mapped_mask(const unsigned int &id) const
return the ComponentMask corresponding to the given id
std::vector< std::string > _all_components