libMesh
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
libMesh::Parameters Class Reference

This class provides the ability to map between arbitrary, user-defined strings and several data types. More...

#include <parameters.h>

Classes

class  Parameter
 Concrete definition of a parameter value for a specified type. More...
 
class  Value
 Abstract definition of a parameter value. More...
 

Public Types

typedef std::map< std::string, Value * >::iterator iterator
 Parameter map iterator. More...
 
typedef std::map< std::string, Value * >::const_iterator const_iterator
 Constant parameter map iterator. More...
 

Public Member Functions

 Parameters ()
 Default constructor. More...
 
 Parameters (const Parameters &)
 Copy constructor. More...
 
virtual ~Parameters ()
 Destructor. More...
 
virtual Parametersoperator= (const Parameters &source)
 Assignment operator. More...
 
virtual Parametersoperator+= (const Parameters &source)
 Addition/Assignment operator. More...
 
template<typename T >
bool have_parameter (const std::string &) const
 
template<typename T >
const T & get (const std::string &) const
 
template<typename T >
void insert (const std::string &)
 Inserts a new Parameter into the object but does not return a writable reference. More...
 
template<typename T >
T & set (const std::string &)
 
virtual void set_attributes (const std::string &, bool)
 Overridable function to set any extended attributes for classes inheriting from this class. More...
 
void remove (const std::string &)
 Removes the specified parameter from the list, if it exists. More...
 
std::size_t n_parameters () const
 
template<typename T >
unsigned int n_parameters () const
 
virtual void clear ()
 Clears internal data structures & frees any allocated memory. More...
 
void print (std::ostream &os=libMesh::out) const
 Prints the contents, by default to libMesh::out. More...
 
iterator begin ()
 Iterator pointing to the beginning of the set of parameters. More...
 
const_iterator begin () const
 Iterator pointing to the beginning of the set of parameters. More...
 
iterator end ()
 Iterator pointing to the end of the set of parameters. More...
 
const_iterator end () const
 Iterator pointing to the end of the set of parameters. More...
 

Protected Attributes

std::map< std::string, Value * > _values
 Data structure to map names with values. More...
 

Detailed Description

This class provides the ability to map between arbitrary, user-defined strings and several data types.

This can be used to provide arbitrary user-specified options.

Author
Benjamin S. Kirk
Date
2004

Definition at line 59 of file parameters.h.

Member Typedef Documentation

◆ const_iterator

typedef std::map<std::string, Value *>::const_iterator libMesh::Parameters::const_iterator

Constant parameter map iterator.

Definition at line 243 of file parameters.h.

◆ iterator

typedef std::map<std::string, Value *>::iterator libMesh::Parameters::iterator

Parameter map iterator.

Definition at line 238 of file parameters.h.

Constructor & Destructor Documentation

◆ Parameters() [1/2]

libMesh::Parameters::Parameters ( )
inline

Default constructor.

Does nothing.

Definition at line 66 of file parameters.h.

66 {}

◆ Parameters() [2/2]

libMesh::Parameters::Parameters ( const Parameters p)
inline

Copy constructor.

Definition at line 351 of file parameters.h.

352 {
353  *this = p;
354 }

◆ ~Parameters()

libMesh::Parameters::~Parameters ( )
inlinevirtual

Destructor.

Clears any allocated memory.

Definition at line 359 of file parameters.h.

360 {
361  this->clear ();
362 }

References clear().

Member Function Documentation

◆ begin() [1/2]

Parameters::iterator libMesh::Parameters::begin ( )
inline

Iterator pointing to the beginning of the set of parameters.

Definition at line 505 of file parameters.h.

506 {
507  return _values.begin();
508 }

References _values.

◆ begin() [2/2]

Parameters::const_iterator libMesh::Parameters::begin ( ) const
inline

Iterator pointing to the beginning of the set of parameters.

Definition at line 511 of file parameters.h.

512 {
513  return _values.begin();
514 }

References _values.

◆ clear()

void libMesh::Parameters::clear ( )
inlinevirtual

Clears internal data structures & frees any allocated memory.

Definition at line 313 of file parameters.h.

314 { // before its first use (for some compilers)
315  while (!_values.empty())
316  {
317  Parameters::iterator it = _values.begin();
318 
319  delete it->second;
320  it->second = nullptr;
321 
322  _values.erase(it);
323  }
324 }

References _values.

Referenced by libMesh::EquationSystems::clear(), operator=(), and ~Parameters().

◆ end() [1/2]

Parameters::iterator libMesh::Parameters::end ( )
inline

Iterator pointing to the end of the set of parameters.

Definition at line 517 of file parameters.h.

518 {
519  return _values.end();
520 }

References _values.

◆ end() [2/2]

Parameters::const_iterator libMesh::Parameters::end ( ) const
inline

Iterator pointing to the end of the set of parameters.

Definition at line 523 of file parameters.h.

524 {
525  return _values.end();
526 }

References _values.

◆ get()

template<typename T >
const T & libMesh::Parameters::get ( const std::string &  name) const
inline
Returns
A constant reference to the specified parameter value. Requires, of course, that the parameter exists.

Definition at line 421 of file parameters.h.

422 {
423  if (!this->have_parameter<T>(name))
424  {
425  std::ostringstream oss;
426 
427  oss << "ERROR: no";
428 #ifdef LIBMESH_HAVE_RTTI
429  oss << ' ' << demangle(typeid(T).name());
430 #endif
431  oss << " parameter named \""
432  << name << "\" found.\n\n"
433  << "Known parameters:\n"
434  << *this;
435 
436  libmesh_error_msg(oss.str());
437  }
438 
440 
441  libmesh_assert(it != _values.end());
442  libmesh_assert(it->second);
443 
444  return cast_ptr<Parameter<T> *>(it->second)->get();
445 }

References _values, libMesh::demangle(), libMesh::libmesh_assert(), and libMesh::Quality::name().

Referenced by add_M_C_K_helmholtz(), assemble_cd(), assemble_ellipticdg(), assemble_helmholtz(), assemble_poisson(), assemble_SchroedingerEquation(), assemble_shell(), assemble_stokes(), assemble_wave(), libMesh::FrequencySystem::clear_all(), compute_jacobian(), compute_residual(), LinearElasticityWithContact::compute_stresses(), LargeDeformationElasticity::compute_stresses(), exact_derivative(), exact_solution(), exact_value(), fill_dirichlet_bc(), libMesh::ImplicitSystem::get_linear_solve_parameters(), libMesh::FEComputeData::init(), libMesh::FrequencySystem::init_data(), Biharmonic::JR::InitialDensityBall(), Biharmonic::JR::InitialDensityRod(), Biharmonic::JR::InitialDensityStrip(), LargeDeformationElasticity::jacobian(), line_print(), main(), libMesh::FrequencySystem::n_frequencies(), LargeDeformationElasticity::residual(), LinearElasticityWithContact::residual_and_jacobian(), libMesh::FrequencySystem::set_current_frequency(), libMesh::NonlinearImplicitSystem::set_solver_parameters(), SolidSystem::side_time_derivative(), libMesh::CondensedEigenSystem::solve(), libMesh::EigenSystem::solve(), libMesh::FrequencySystem::solve(), libMesh::LinearImplicitSystem::solve(), and libMesh::RBConstruction::solve_for_matrix_and_rhs().

◆ have_parameter()

template<typename T >
bool libMesh::Parameters::have_parameter ( const std::string &  name) const
inline
Returns
true if a parameter of type T with a specified name exists, false otherwise.

If RTTI has been disabled then we return true if a parameter of specified name exists regardless of its type.

Definition at line 402 of file parameters.h.

403 {
405 
406  if (it != _values.end())
407 #ifdef LIBMESH_HAVE_RTTI
408  if (dynamic_cast<const Parameter<T> *>(it->second) != nullptr)
409 #else // LIBMESH_HAVE_RTTI
410  if (cast_ptr<const Parameter<T> *>(it->second) != nullptr)
411 #endif // LIBMESH_HAVE_RTTI
412  return true;
413 
414  return false;
415 }

References _values, libMesh::cast_ptr(), and libMesh::Quality::name().

Referenced by libMesh::FrequencySystem::clear_all(), libMesh::FEComputeData::init(), libMesh::FrequencySystem::init_data(), libMesh::CondensedEigenSystem::solve(), and libMesh::EigenSystem::solve().

◆ insert()

template<typename T >
void libMesh::Parameters::insert ( const std::string &  name)
inline

Inserts a new Parameter into the object but does not return a writable reference.

The value of the newly inserted parameter may not be valid.

Definition at line 449 of file parameters.h.

450 {
451  if (!this->have_parameter<T>(name))
452  _values[name] = new Parameter<T>;
453 
454  set_attributes(name, true);
455 }

References _values, libMesh::Quality::name(), and set_attributes().

◆ n_parameters() [1/2]

std::size_t libMesh::Parameters::n_parameters ( ) const
inline
Returns
The total number of parameters.

Definition at line 139 of file parameters.h.

139 { return _values.size(); }

References _values.

◆ n_parameters() [2/2]

template<typename T >
unsigned int libMesh::Parameters::n_parameters ( ) const
inline
Returns
The number of parameters of the requested type.

Definition at line 489 of file parameters.h.

490 {
491  unsigned int cnt = 0;
492 
493  Parameters::const_iterator it = _values.begin();
494  const Parameters::const_iterator vals_end = _values.end();
495 
496  for (; it != vals_end; ++it)
497  if (dynamic_cast<Parameter<T> *>(it->second) != nullptr)
498  cnt++;
499 
500  return cnt;
501 }

References _values.

◆ operator+=()

Parameters & libMesh::Parameters::operator+= ( const Parameters source)
inlinevirtual

Addition/Assignment operator.

Inserts copies of all parameters from source. Any parameters of the same name already in this are replaced.

Definition at line 338 of file parameters.h.

339 {
340  for (const auto & pr : source._values)
341  {
342  if (_values.find(pr.first) != _values.end())
343  delete _values[pr.first];
344  _values[pr.first] = pr.second->clone();
345  }
346 
347  return *this;
348 }

References _values.

◆ operator=()

Parameters & libMesh::Parameters::operator= ( const Parameters source)
inlinevirtual

Assignment operator.

Removes all parameters in this and inserts copies of all parameters from source

Definition at line 329 of file parameters.h.

330 {
331  this->clear();
332  *this += source;
333 
334  return *this;
335 }

References clear().

◆ print()

void libMesh::Parameters::print ( std::ostream &  os = libMesh::out) const
inline

Prints the contents, by default to libMesh::out.

Definition at line 367 of file parameters.h.

368 {
369  Parameters::const_iterator it = _values.begin();
370 
371  os << "Name\t Type\t Value\n"
372  << "---------------------\n";
373  while (it != _values.end())
374  {
375  os << " " << it->first
376 #ifdef LIBMESH_HAVE_RTTI
377  << "\t " << it->second->type()
378 #endif // LIBMESH_HAVE_RTTI
379  << "\t "; it->second->print(os);
380  os << '\n';
381 
382  ++it;
383  }
384 }

References _values.

Referenced by libMesh::operator<<().

◆ remove()

void libMesh::Parameters::remove ( const std::string &  name)
inline

Removes the specified parameter from the list, if it exists.

Definition at line 471 of file parameters.h.

472 {
473  Parameters::iterator it = _values.find(name);
474 
475  if (it != _values.end())
476  {
477  delete it->second;
478  it->second = nullptr;
479 
480  _values.erase(it);
481  }
482 }

References _values, and libMesh::Quality::name().

Referenced by libMesh::FrequencySystem::clear_all().

◆ set()

template<typename T >
T & libMesh::Parameters::set ( const std::string &  name)
inline
Returns
A writable reference to the specified parameter. This method will create the parameter if it does not exist, so it can be used to define parameters which will later be accessed with the get() member.

Definition at line 460 of file parameters.h.

461 {
462  if (!this->have_parameter<T>(name))
463  _values[name] = new Parameter<T>;
464 
465  set_attributes(name, false);
466 
467  return cast_ptr<Parameter<T> *>(_values[name])->set();
468 }

References _values, libMesh::Quality::name(), and set_attributes().

Referenced by assemble_SchroedingerEquation(), libMesh::NewmarkSystem::clear(), libMesh::EquationSystems::EquationSystems(), init_cd(), HeatSystem::init_data(), Biharmonic::JR::initialize(), initialize(), main(), libMesh::NewmarkSystem::NewmarkSystem(), libMesh::NonlinearImplicitSystem::NonlinearImplicitSystem(), run_timestepping(), libMesh::FrequencySystem::set_current_frequency(), libMesh::FrequencySystem::set_frequencies(), libMesh::FrequencySystem::set_frequencies_by_range(), libMesh::FrequencySystem::set_frequencies_by_steps(), libMesh::NewmarkSystem::set_newmark_parameters(), and setup().

◆ set_attributes()

virtual void libMesh::Parameters::set_attributes ( const std::string &  ,
bool   
)
inlinevirtual

Overridable function to set any extended attributes for classes inheriting from this class.

Definition at line 129 of file parameters.h.

129 {}

Referenced by insert(), and set().

Member Data Documentation

◆ _values

std::map<std::string, Value *> libMesh::Parameters::_values
protected

Data structure to map names with values.

Definition at line 270 of file parameters.h.

Referenced by begin(), clear(), end(), get(), have_parameter(), insert(), n_parameters(), operator+=(), print(), remove(), and set().


The documentation for this class was generated from the following file:
libMesh::Parameters::clear
virtual void clear()
Clears internal data structures & frees any allocated memory.
Definition: parameters.h:313
libMesh::cast_ptr
Tnew cast_ptr(Told *oldvar)
Definition: libmesh_common.h:573
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::demangle
std::string demangle(const char *name)
Mostly system independent demangler.
Definition: print_trace.C:250
libMesh::Parameters::iterator
std::map< std::string, Value * >::iterator iterator
Parameter map iterator.
Definition: parameters.h:238
libMesh::Parameters::set
T & set(const std::string &)
Definition: parameters.h:460
libMesh::Parameters::set_attributes
virtual void set_attributes(const std::string &, bool)
Overridable function to set any extended attributes for classes inheriting from this class.
Definition: parameters.h:129
libMesh::Parameters::_values
std::map< std::string, Value * > _values
Data structure to map names with values.
Definition: parameters.h:270
libMesh::Parameters::get
const T & get(const std::string &) const
Definition: parameters.h:421
libMesh::Parameters::const_iterator
std::map< std::string, Value * >::const_iterator const_iterator
Constant parameter map iterator.
Definition: parameters.h:243
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42