Fluid structure interaction suite
ParsedTools::Constants Class Reference

A wrapper for physical constants to be shared among functions and classes. More...

#include <constants.h>

Inheritance diagram for ParsedTools::Constants:
[legend]

Public Member Functions

 Constants (const std::string &section_name="", const std::vector< std::string > &names={}, const std::vector< double > &default_values={}, const std::vector< std::string > &optional_names_for_parameter_file={}, const std::vector< std::string > &optional_documentation_strings={})
 Build a ParameterAcceptor based collection of constants. More...
 
 operator const std::map< std::string, double > & () const
 Return the constants defined in this class as a map. More...
 
 operator const Differentiation::SD::types::substitution_map & () const
 Return the constants defined in this class as a Differentiation::SD::types::substitution_map. More...
 
const double & operator[] (const std::string &key) const
 Return the constant associated with the given name. More...
 
- Public Member Functions inherited from ParameterAcceptor
 ParameterAcceptor (const std::string &section_name="")
 
unsigned int get_acceptor_id () const
 
virtual ~ParameterAcceptor () override
 
virtual void declare_parameters (ParameterHandler &prm)
 
virtual void parse_parameters (ParameterHandler &prm)
 
std::string get_section_name () const
 
std::vector< std::string > get_section_path () const
 
void add_parameter (const std::string &entry, ParameterType &parameter, const std::string &documentation="", ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern())
 
void enter_subsection (const std::string &subsection)
 
void leave_subsection ()
 
void enter_my_subsection (ParameterHandler &prm)
 
void leave_my_subsection (ParameterHandler &prm)
 
void serialize (Archive &ar, const unsigned int version)
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&) noexcept
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (Subscriptor &&) noexcept
 
void serialize (Archive &ar, const unsigned int version)
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 

Private Attributes

std::map< std::string, double > constants
 The actual constants. More...
 
Differentiation::SD::types::substitution_map constant_substitution_map
 Return the constants defined in this class as a Differentiation::SD::types::substitution_map. More...
 
std::map< std::string, std::string > constants_parameter_entries
 The documentation string used to parse the constants from the parameter file. More...
 
std::map< std::string, std::string > constants_documentation
 The documentation of each constant. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ParameterAcceptor
static void initialize (const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_output_filename=ParameterHandler::Short, ParameterHandler &prm=ParameterAcceptor::prm, const ParameterHandler::OutputStyle output_style_for_filename=ParameterHandler::DefaultStyle)
 
static void initialize (std::istream &input_stream, ParameterHandler &prm=ParameterAcceptor::prm)
 
static void clear ()
 
static void parse_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm)
 
static void declare_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm)
 
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 
- Static Public Member Functions inherited from Subscriptor
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 
- Public Attributes inherited from ParameterAcceptor
boost::signals2::signal< void()> declare_parameters_call_back
 
boost::signals2::signal< void()> parse_parameters_call_back
 
- Static Public Attributes inherited from ParameterAcceptor
static ParameterHandler prm
 
- Protected Attributes inherited from ParameterAcceptor
const std::string section_name
 
std::vector< std::string > subsections
 

Detailed Description

A wrapper for physical constants to be shared among functions and classes.

This class can be used to store physical constants that are used in a simulation, e.g., elastic parameters, densities, etc., and that could be reused when defining Function objects.

This class behaves like a map, where the keys are strings and the values are the corresponding values.

In addition to constants defined at construction time, this class also provides a list of all mathematical constants defined in the numbers namespace, i.e., PI, E, LOG2_E, etc.

Constants given at construction time takes precedence, so if you use "E" as a constant name, than that value will be used instead of the Nepero constant numbers::E.

Definition at line 43 of file constants.h.

Constructor & Destructor Documentation

◆ Constants()

ParsedTools::Constants::Constants ( const std::string &  section_name = "",
const std::vector< std::string > &  names = {},
const std::vector< double > &  default_values = {},
const std::vector< std::string > &  optional_names_for_parameter_file = {},
const std::vector< std::string > &  optional_documentation_strings = {} 
)

Build a ParameterAcceptor based collection of constants.

An example usage of this class is the following:

ParsedTools::Constants constants("/Physical Constants",
{"a", "b", "c"},
{1.0, 2.0, 3.0},
{"The constant a",
"The constant b",
"The constant c"});
// Now use c as a map whenever one is needed, i.e.,
const std::map<std::string, double> &c = constants;
c.at("a") == 1.0; // returns true
// or directly as
contants["a"] == 1.0; // returns true
static void initialize(const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_output_filename=ParameterHandler::Short, ParameterHandler &prm=ParameterAcceptor::prm, const ParameterHandler::OutputStyle output_style_for_filename=ParameterHandler::DefaultStyle)
A wrapper for physical constants to be shared among functions and classes.
Definition: constants.h:44
std::map< std::string, double > constants
The actual constants.
Definition: constants.h:132

The above snippet of code will delcare the ParameterAcceptor::prm ParameterHandler with the following entries:

subsection Physical Constants
set The constant a (a) = 1.0
set The constant b (b) = 2.0
set The constant c (c) = 3.0
end

The optional_names_for_parameter_file can be left empty, in which case the names of the constants will be used. In the example above, leaving optional_names_for_parameter_file empty would result in the following parameter entries:

subsection Physical Constants
set a = 1.0
set b = 2.0
set c = 3.0
end
Parameters
section_nameThe name of the section in the parameter file.
namesThe names of the constants.
default_valuesThe default values of the constants.
optional_names_for_parameter_fileOptional names to use instead of the constant names in the parameter file defintion.
optional_documentation_stringsOptional documentation strings to use in the parameter file defintion.

Definition at line 24 of file constants.cc.

References ParameterAcceptor::add_parameter(), AssertDimension, constants, constants_documentation, constants_parameter_entries, numbers::E, numbers::LN10, numbers::LN2, numbers::LOG10E, numbers::LOG2E, numbers::PI, numbers::PI_2, numbers::PI_4, numbers::SQRT1_2, and numbers::SQRT2.

Member Function Documentation

◆ operator const std::map< std::string, double > &()

ParsedTools::Constants::operator const std::map< std::string, double > & ( ) const

Return the constants defined in this class as a map.

◆ operator const Differentiation::SD::types::substitution_map &()

ParsedTools::Constants::operator const Differentiation::SD::types::substitution_map & ( ) const

Return the constants defined in this class as a Differentiation::SD::types::substitution_map.

Definition at line 95 of file constants.cc.

◆ operator[]()

const double & ParsedTools::Constants::operator[] ( const std::string &  key) const

Return the constant associated with the given name.

Parameters
keyThe name of the constant.
Returns
const double& The constant associated with the given name.

Definition at line 83 of file constants.cc.

References constants.

Member Data Documentation

◆ constants

std::map<std::string, double> ParsedTools::Constants::constants
private

The actual constants.

Definition at line 132 of file constants.h.

Referenced by Constants(), and operator[]().

◆ constant_substitution_map

Differentiation::SD::types::substitution_map ParsedTools::Constants::constant_substitution_map
mutableprivate

Return the constants defined in this class as a Differentiation::SD::types::substitution_map.

Definition at line 141 of file constants.h.

◆ constants_parameter_entries

std::map<std::string, std::string> ParsedTools::Constants::constants_parameter_entries
private

The documentation string used to parse the constants from the parameter file.

Definition at line 149 of file constants.h.

Referenced by Constants().

◆ constants_documentation

std::map<std::string, std::string> ParsedTools::Constants::constants_documentation
private

The documentation of each constant.

Definition at line 154 of file constants.h.

Referenced by Constants().


The documentation for this class was generated from the following files: